Re: [R] Collinearity in Linear Multiple Regression

2009-07-21 Thread Tim Paysen
Actually, the CI index and VIF are just a start.  It is best to look at what 
they call a matrix of "variance proportions" (found in SAS and a few other 
places...)--which hardly anyone understands (including the SAS folks).  It is a 
matrix of estimates of what the variences of the regression coefficients would 
be if you could figure them out in the first place.  It shows which factors 
dominate over others IN THE PARTICULAR SETUP you are analyzing.  The matrix is 
often calculated using eigenvalues, but is best done with Singular Value 
Decomposition techniques (you don't have to have a square matrix, and you 
maintain better precision).  Analysts will say that it can display an unstable 
system -- which is correct, but they generally say that, if its true, you have 
bad data and should throw it out--or collect more.  I suggest care, because it 
may be illustrating the nature of the system you are studying.

The only decent reference that I know of is a little book (hard to read) that I 
can't remember off the top of my head.  Have to look it up.

Timothy E. Paysen, Phd
Research Forester (ret.)





From: John Sorkin 
To: Alex Roy ; r-help@r-project.org
Sent: Tuesday, July 21, 2009 4:19:11 AM
Subject: Re: [R] Collinearity in Linear Multiple Regression

I suggest you start by doing some reading about Condition index (CI) and 
variation inflation factor (VIF). Once you have reviewed the theory, a search 
of search.r-project.org (under the help menu in a windows-based R installation) 
for VIF will help you obtain values for VIF, c.f. 
http://finzi.psych.upenn.edu/R/library/HH/html/vif.html 
John

John David Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)

>>> Alex Roy  7/21/2009 7:01 AM >>>
Dear all,
                  How can I test for collinearity in the predictor data set
for multiple linear regression.

Thanks

Alex

    [[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 
and provide commented, minimal, self-contained, reproducible code.

Confidentiality Statement:
This email message, including any attachments, is for th...{{dropped:11}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Subsample points for mclust

2009-07-21 Thread Mario Valle

Nothing is better than asking help to find the answer by myself...

Page 47 of the technical report (tr504.pdf) deals exactly with the 
problem of big datasets.


Also I found that mclust is too much for my problem, the optimum number 
of Gaussian suggested is way too high. For example for one dataset 
(downsampled to 1/10) it suggests 9 Gaussian, but the central 7 sum with 
good approximation to a single Gaussian, so the dataset is better 
decomposed into only 3 Gaussian.

I admit I'm not rigorous at all...

Bye!
  mario

Mario Valle wrote:

Hi all!

I have an ordered vector of values. The distribution of these values 
can be modeled by a sum of Gaussians.
So I'm using the package 'mclust' to get the Gaussians's parameters 
for this 1D distribution. It works very well, but, for input sizes 
above 100.000 values it starts taking really forever. Unfortunately my 
dataset has around 4.6M values...


My question: is it correct to subsample my dataset taking a value 
every N to make mclust happy? Or have I no alternative except using 
the complete dataset?


Excuse my profound ignorance and thank for your help!

mario





--
Ing. Mario Valle
Data Analysis and Visualization Group| http://www.cscs.ch/~mvalle
Swiss National Supercomputing Centre (CSCS)  | Tel:  +41 (91) 610.82.60
v. Cantonale Galleria 2, 6928 Manno, Switzerland | Fax:  +41 (91) 610.82.82

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to extract the upper xlim and ylim of my plot?

2009-07-21 Thread Greg Snow
?grconvertX

-Original Message-
From: "Mark Na" 
To: "r-help@r-project.org" 
Sent: 7/21/09 3:05 PM
Subject: [R] How to extract the upper xlim and ylim of my plot?


Dear R-helpers,

I wish to place some text in a plot, at approx 10% of my upper xlim and
approx 90% of my upper ylim, i.e.

> plot(log(all$SR,10)~log(all$AREA,10))
> text(.1*max(xlim),.9*max(ylim),"text to be placed")

(I know how to give absolute coordinates for text location, but I wish to
use relative coordinates).

My code (above) doesn't work because I don't know how to properly extract
the upper xlim and ylim values.

Does anyone know how I could extract the upper xlim and ylim values (without
using max(x-variable) or max (y-variable)...I wish to keep this as general
as possible and not point to the original data.

Thanks in advance,

Mark

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How do I delete a row from a data frame when varA == "TRUE"

2009-07-21 Thread Daniel Malter
XYZ=XYZ[XYZ$A==TRUE , ] should do. Note that this specific command
overwrites your XYZ dataframe. If you want to keep XYZ, you will want to
name the newly created frame differently.

HTH,
Daniel

-
cuncta stricte discussurus
-

-Ursprüngliche Nachricht-
Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im
Auftrag von kxk
Gesendet: Wednesday, July 22, 2009 12:24 AM
An: r-help@r-project.org
Betreff: [R] How do I delete a row from a data frame when varA == "TRUE"


I want to delete a row from a data frame XYZ where A == "TRUE".  Let's
assume there are five variables in this data frame XYZ.  My deletion is
based on the TRUE vs. FALSE value under variable A.  How do I do this?
Thanks!

My current code: 
for (i in 1:length(XYZ$A)) if (XYZ$A == "FALSE") XYZ<-XYZ else XYZ<-
XYZ[-i,]

Error message is:
Error in if (XYZ$A == "FALSE") XYZ<-XYZ else XYZ<- XYZ[-i,  : 
  missing value where TRUE/FALSE needed


Please help!!
--
View this message in context:
http://www.nabble.com/How-do-I-delete-a-row-from-a-data-frame-when-varA-%3D%
3D-%22TRUE%22-tp24599876p24599876.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] EM algorithm

2009-07-21 Thread Elena 5/12


l=∑_i∑_k log[ (Se(i))^(t_ik ) [1-Se(i) ]^(1-t_ik ) p+(Sp(i))^(1-t_ik)
[1-Sp(i) ]^(t_ik ) (1-p)]

This is my observed loglikelihood. It is a sum over i (there are I tests)
and over k (K patients). t_ik is the result for the kth patient on the ith
test.

Se(i)= sensitivity, Sp (i)= specificity and p=prevalence are my unknown
parameters.

Do you know how to code this loglikelihood and EM algorithm in R? I can't
get it to work.

Thanks!


-- 
View this message in context: 
http://www.nabble.com/EM-algorithm-tp24595358p24596434.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] How do I delete a row from a data frame when varA == "TRUE"

2009-07-21 Thread kxk

I want to delete a row from a data frame XYZ where A == "TRUE".  Let's assume
there are five variables in this data frame XYZ.  My deletion is based on
the TRUE vs. FALSE value under variable A.  How do I do this?  Thanks!

My current code: 
for (i in 1:length(XYZ$A)) if (XYZ$A == "FALSE") XYZ<-XYZ else XYZ<-
XYZ[-i,]

Error message is:
Error in if (XYZ$A == "FALSE") XYZ<-XYZ else XYZ<- XYZ[-i,  : 
  missing value where TRUE/FALSE needed


Please help!!
-- 
View this message in context: 
http://www.nabble.com/How-do-I-delete-a-row-from-a-data-frame-when-varA-%3D%3D-%22TRUE%22-tp24599876p24599876.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] R extract vertices for polygon

2009-07-21 Thread Angel Marley

Dear R users, 
I'm trying to extract from a given matrix (GROUP) the coordinates of the 
vertices of the different groups (i.e. 3, 7, 1 . . .) to plot the polygons to 
delineate the area in which each group "wins" and colour it diferentially. I 
can make a simple point plot, but I would like to add polygons with full 
colored area. The example is with a 5x5 matrix, but I'm working with 500 x 500 
matrix, so hand work is difficult, 
Any suggestion will be welcomed. 
  
Nrep=5
GROUP<-matrix(c(3,3,3,3,7,3,3,3,3,7,1,3,3,3,7,1,3,3,3,7,1,1,4,4,0),Nrep,Nrep)   
  
column<- seq(1, 5, length=Nrep)
row<- seq(0,10,length=Nrep)

colnames(GROUP)<- round(column,3)
rownames(GROUP)<- row

GROUP

grupovec<-as.vector(GROUP)
flushvec<-rep(column,rep(Nrep,Nrep))
MORvec<-rep(row,Nrep)

plot(flushvec,MORvec, col=grupovec, pch=19)

polygon() # 

Thanks 
Angel

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] EM algorithm

2009-07-21 Thread Elena 5/12

l=∑_i∑_k log[ (Se(i))^(t_ik ) [1-Se(i) ]^(1-t_ik ) p+(Sp(i))^(1-t_ik)
[1-Sp(i) ]^(t_ik ) (1-p)] 

This is my observed loglikelihood. It is a sum over i (there are I tests)
and over k (K patients). t_ik is the result for the kth patient on the ith
test. 

Se(i)= sensitivity, Sp (i)= specificity and p=prevalence are my unknown
parameters. 

Do you know how to code this loglikelihood and EM algorithm in R? I can't
get it to work. 

Thanks! 
-- 
View this message in context: 
http://www.nabble.com/EM-algorithm-tp24596478p24596478.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Select set of variables with strongest correlation

2009-07-21 Thread nyk

Thanks, I did! This reply I also got helped a lot:

r<-matrix(rnorm(30),ncol=3)
r4 <-1+2*rnorm(10,r[,3], 0.5)
r5 <-1-3*rnorm(10,r[,3], 0.5)
data<-cbind(r,r4,r5)

corr<-cor(data,use='na.or.complete')
corrl<-(corr[col(corr)>row(corr)])^2
colms<-col(data)[col(col(data))>row(col(data))]
rows<-row(data)[col(row(data))>row(row(data))]
tosort<-cbind(corrl,rows,colms)
sorted <- tosort[order(tosort[,1],decreasing = TRUE, na.last = TRUE), ]


Uwe Ligges-3 wrote:
> 
> See ?cor
> 
> Uwe Ligges
> 
> 
> nyk wrote:
>> What would be a good method to find the subset of columns of a data
>> matrix
>> (with about 200 rows and columns) that has the strongest correlation to
>> one
>> other column? I tried testing sub-matrices with random sets of 10 columns
>> selected using lm(x ~submtrx) and comparing the r^2 values. But isn't
>> there
>> a better method for this task?
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Select-set-of-variables-with-strongest-correlation-tp24507332p24598197.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Adjusting x/y text labels for a bwplot using cex.lab

2009-07-21 Thread mcobb_berkeley

Figured it out --- FYI:

bwplot(hr~Herd, data=telemetry, notch=T, ylab=list("Home Range Area (ha)",
cex=1.5), xlab=list("Herd", cex=1.5), par.settings = list(plot.symbol =
list(col = "black"),box.umbrella = list(col ="black"),
box.rectangle=list(col="black")),fill="light blue")




mcobb_berkeley wrote:
> 
> Searched for this and found some help, but I still can't figure it out.  
> I have trying to enlarge the x and y labels on my box plot.  I understand
> that you can do this using "cex.lab", but it does not seem to be working
> for me.  I must be adding it in the wrong spot.  Any help would be greatly
> appreciated.  Here is my code:
> 
> bwplot(hr~Herd, data=telemetry, notch=T, ylab="Home Range Area (ha)",
> xlab="Herd", 
> par.settings = list(plot.symbol = list(col = "black"),box.umbrella =
> list(col ="black"), box.rectangle=list(col="black")),fill="light blue")
> 
> ~McCrea
> 

-- 
View this message in context: 
http://www.nabble.com/Adjusting-x-y-text-labels-for-a-bwplot-using-cex.lab-tp24595920p24597612.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] dump() an object of type raw ?

2009-07-21 Thread David Winsemius


On Jul 21, 2009, at 10:21 PM, Benjamin Tyner wrote:

Thank you David for taking the time to respond to my question.  
Perhaps I should clarify: the man page says "a 'dump' file can be  
'source'd"; have I taken the documentation too literally in this case?


I suppose that objects of type raw may not have been given full  
provision in the construction of source(). The help page suggests to  
me that attributes are not dumped. Perhaps you could be more expansive  
about what you are hoping to accomplish?


Does this get any closer?

> x <- as.numeric( writeBin(pi, raw()) )
> x
[1]  24  45  68  84 251  33   9  64
> dump("x","x.R")
> source("/Users/davidwinsemius/x.R")
> x
[1]  24  45  68  84 251  33   9  64
> as.raw(x)
[1] 18 2d 44 54 fb 21 09 40

Or this: The help page also advises that save() is more appropriate  
for R data.


> x <- writeBin(pi, raw())
> save("x",file="x.R")
> load("x.R")
> x
[1] 18 2d 44 54 fb 21 09 40



David Winsemius wrote:


On Jul 21, 2009, at 7:19 PM, Benjamin Tyner wrote:


Is there a way to do this? I tried

x <- writeBin(pi, raw())
dump("x","x.R")
source("x.R")

but is seems x.R is not source()-able, as it contains an  
unexpected symbol.




Yes, "2d".I get:
> source("/Users/davidwinsemius/x.R")
Error in source("/Users/davidwinsemius/x.R") :
 /Users/davidwinsemius/x.R:2:8: unexpected symbol
1: x <-
2: c(18, 2d
 ^

So there was an good faith effort to source the file but the  
interpreter was not put on notice that it would be getting  
hexadecimal. The file contains:


x <-
c(18, 2d, 44, 54, fb, 21, 09, 40)

and when you try to execute that from the command line you get:

> x <-
+ c(18, 2d, 44, 54, fb, 21, 09, 40)
Error: syntax error

(R variable names cannot start with 2 and R wouldn't assume these  
are hexadecimal numbers.)



David Winsemius, MD
Heritage Laboratories
West Hartford, CT





David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] is a sequence of dates consecutive, without gaps?

2009-07-21 Thread Christopher W. Ryan
Thanks, Phil and Marc; exactly what I needed! I didn't know about the
diff function.

--Chris
Christopher W. Ryan, MD
SUNY Upstate Medical University Clinical Campus at Binghamton
40 Arch Street, Johnson City, NY  13790
cryanatbinghamtondotedu

"If you want to build a ship, don't drum up the men to gather wood,
divide the work and give orders. Instead, teach them to yearn for the
vast and endless sea."  [Antoine de St. Exupery]

Marc Schwartz wrote:
> 
> On Jul 21, 2009, at 4:58 PM, Christopher W. Ryan wrote:
> 
>> I have a long sequence of dates, about 6 years worth, as one column in a
>> data frame. How can I test whether the sequence is consecutive, that is,
>> without gaps?
>>
>> Thanks.
>>
>> --Chris
> 
> 
> Chris,
> 
> Presuming that your data frame is called DF, the date column is called
> 'date' AND 'date' has been coerced to a Date class, you could use:
> 
>   all(diff(DF$date) == 1)
> 
> which will tell you if all of the differences between successive dates
> in the column are one day.
> 
> See ?diff for more information.
> 
> If the dates have not yet been coerced to a Date class, see ?as.Date.
> 
> HTH,
> 
> Marc Schwartz
> 
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] dump() an object of type raw ?

2009-07-21 Thread Benjamin Tyner
Thank you David for taking the time to respond to my question. Perhaps I 
should clarify: the man page says "a 'dump' file can be 'source'd"; have 
I taken the documentation too literally in this case?


David Winsemius wrote:


On Jul 21, 2009, at 7:19 PM, Benjamin Tyner wrote:


Is there a way to do this? I tried

 x <- writeBin(pi, raw())
 dump("x","x.R")
 source("x.R")

but is seems x.R is not source()-able, as it contains an unexpected 
symbol.




Yes, "2d".I get:
> source("/Users/davidwinsemius/x.R")
Error in source("/Users/davidwinsemius/x.R") :
  /Users/davidwinsemius/x.R:2:8: unexpected symbol
1: x <-
2: c(18, 2d
  ^

So there was an good faith effort to source the file but the 
interpreter was not put on notice that it would be getting 
hexadecimal. The file contains:


x <-
c(18, 2d, 44, 54, fb, 21, 09, 40)

and when you try to execute that from the command line you get:

> x <-
+ c(18, 2d, 44, 54, fb, 21, 09, 40)
Error: syntax error

(R variable names cannot start with 2 and R wouldn't assume these are 
hexadecimal numbers.)



David Winsemius, MD
Heritage Laboratories
West Hartford, CT



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] dump() an object of type raw ?

2009-07-21 Thread David Winsemius


On Jul 21, 2009, at 7:19 PM, Benjamin Tyner wrote:


Is there a way to do this? I tried

 x <- writeBin(pi, raw())
 dump("x","x.R")
 source("x.R")

but is seems x.R is not source()-able, as it contains an unexpected  
symbol.




Yes, "2d".I get:
> source("/Users/davidwinsemius/x.R")
Error in source("/Users/davidwinsemius/x.R") :
  /Users/davidwinsemius/x.R:2:8: unexpected symbol
1: x <-
2: c(18, 2d
  ^

So there was an good faith effort to source the file but the  
interpreter was not put on notice that it would be getting  
hexadecimal. The file contains:


x <-
c(18, 2d, 44, 54, fb, 21, 09, 40)

and when you try to execute that from the command line you get:

> x <-
+ c(18, 2d, 44, 54, fb, 21, 09, 40)
Error: syntax error

(R variable names cannot start with 2 and R wouldn't assume these are  
hexadecimal numbers.)



David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] strange dlply behavior

2009-07-21 Thread hadley wickham
Hi Damien,

This is because of a small bug.  You can work around it by explicitly
using the force function - dlply(d, "V1", force).  The default will be
fixed in the next version.

Regards,

Hadley

On Tue, Jul 21, 2009 at 11:18 AM, Damien Moore wrote:
> I'm running R 2.9.1 on winXP, using the library plyr.
>
> Can anyone explain to me what is going wrong in this code? (in particular
> see lines marked with **) Trying to modify objects in a list
> created using dlply seems to corrupt the objects in the list.
>
>> library(plyr)
>> d=as.data.frame(cbind(c(1,1,1,2,2,2),c(1,2,3,4,5,6)))
>> d
>  V1 V2
> 1  1  1
> 2  1  2
> 3  1  3
> 4  2  4
> 5  2  5
> 6  2  6
>> c=dlply(d,.(V1))
>> c
> [[1]]
>  V1 V2
> 1  1  1
> 2  1  2
> 3  1  3
>
> [[2]]
>  V1 V2
> 4  2  4
> 5  2  5
> 6  2  6
>
> ## display an element from the second data frame
>> c[[2]][2,2]
> [1] 5
>
> ## change element in the second data from
>> c[[2]][2,2]=10
>> c
> [[1]]
>    V1 V2
> 2    1  2    **
> 2.1  1  2   **  What happened to V2?
> 2.2  1  2   **
>
> [[2]]
>   V1 V2
> 4   2  4
> NA NA NA **
> 6   2  6
>
> ##Try again with first data frame
>> c=dlply(d,.(V1))
>> c[[1]][2,2]=10 **
>> c
> [[1]]
> NULL * YIKES!
>
>
> ##Try again but copy c into a new list k
>> c=dlply(d,.(V1))
>> k=list(c[[1]],c[[2]])
>> k[[1]]
>  V1 V2
> 1  1  1
> 2  1  2
> 3  1  3
>> k[[2]][2,2]=10
>> k
> [[1]]
>  V1 V2
> 1  1  1
> 2  1  2
> 3  1  3
>
> [[2]]
>  V1 V2
> 4  2  4
> 5  2 10 ***
> 6  2  6
>> k[[1]][2,2]=10
>> k
> [[1]]
>  V1 V2
> 1  1  1
> 2  1 10 ***
> 3  1  3
>
> [[2]]
>  V1 V2
> 4  2  4
> 5  2 10
> 6  2  6
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
http://had.co.nz/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to replace NAs in a vector of factors?

2009-07-21 Thread Rolf Turner


On 22/07/2009, at 1:21 PM, jim holtman wrote:


Notice that three items are returned where you thought one was:

[1] FALSE  TRUE  TRUE  TRUE FALSE

db1$olditems[db1$olditems=='']  #wait, only one item is returned?

[1]
Levels:  nuts soup

db1[db1$olditems=='',]  #somehow this works!

  olditems prices
23.25
34.42
42.25
paste('[',db1$olditems[db1$olditems==''],']') # put some  
characters around return values

[1] "[  ]" "[  ]" "[  ]"





The '[1]' was just an indication that this is the first value returned
and the other two were blanks so you did not see them.  Also "" is
just that; a blank and not NA.


	Strictly speaking --- or maybe even not so strictly --- a ***null  
character***,

not a blank.  "" != " "

cheers,

Rolf Turner



##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to replace NAs in a vector of factors?

2009-07-21 Thread Bill.Venables
Couple of points:

1. if you are going to be replacing entries in factors with updated levels, 
it's probably easier if you start with your strings remaining as strings as 
they go into the data frames.  So here is how I would start your example


db1 <- data.frame(
olditems = c('soup','','','','nuts'),
prices = c(4.45, 3.25, 4.42, 2.25, 3.98), 
stringsAsFactors = FALSE)
db2 <- data.frame(
newitems = c('stew','crackers','tofu','goatsmilk','peanuts'), 
stringsAsFactors = FALSE)


2. Strings with zero characters are still strings (like zero is still a 
number).  They are not missing.  If you want them to be made missing you can do 
so afterwards with:


 zero length strings become NA 
is.na(db1$olditems[db1$olditems == '']) <- TRUE


3. Now to replace the missing values with the corresponding ones from the 
second data frame:


k <- is.na(db1$olditems)
db1[k, "olditems"] <- db2[k, "newitems"]


4. Check

> db1
   olditems prices
1  soup   4.45
2  crackers   3.25
3  tofu   4.42
4 goatsmilk   2.25
5  nuts   3.98
> 

5. If you really do want factors rather than character strings, you can now 
change back:

db1 <- within(db1, olditems <- factor(olditems)) ## use <- here!

6. check the difference

> str(db1)
'data.frame':   5 obs. of  2 variables:
 $ olditems: Factor w/ 5 levels "crackers","goatsmilk",..: 4 1 5 2 3
 $ prices  : num  4.45 3.25 4.42 2.25 3.98
> 
 


Bill Venables
http://www.cmis.csiro.au/bill.venables/ 


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Gene Leynes
Sent: Wednesday, 22 July 2009 10:39 AM
To: r-help@r-project.org
Subject: [R] How to replace NAs in a vector of factors?

# Just when I thought I had the basic stuff mastered
# This has been quite perplexing, thanks for any help


## Here's the example:

db1=data.frame(
olditems=c('soup','','','','nuts'),
prices=c(4.45, 3.25, 4.42, 2.25, 3.98))
db2=data.frame(
newitems=c('stew','crackers','tofu','goatsmilk','peanuts'))

str(db1)#factors and prices
str(db2)#new names, but I want *only* the updates

is.na(db1$olditems)  #a little surprising that '' is not equal to NA
db1$olditems=='' #oh good, at least I can get to the blanks this way
db1$olditems[db1$olditems=='']  #wait, only one item is returned?
db1[db1$olditems=='',]  #somehow this works!

#how would I get the new item names into the old items column of db1??
# I was expecting that this would work:
#db1$olditems[db1$olditems=='']=
#db2$newitems[db1$olditems=='']

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to replace NAs in a vector of factors?

2009-07-21 Thread jim holtman
Notice that three items are returned where you thought one was:

[1] FALSE  TRUE  TRUE  TRUE FALSE
> db1$olditems[db1$olditems=='']  #wait, only one item is returned?
[1]
Levels:  nuts soup
> db1[db1$olditems=='',]  #somehow this works!
  olditems prices
23.25
34.42
42.25
> paste('[',db1$olditems[db1$olditems==''],']') # put some characters around 
> return values
[1] "[  ]" "[  ]" "[  ]"
>


The '[1]' was just an indication that this is the first value returned
and the other two were blanks so you did not see them.  Also "" is
just that; a blank and not NA.

On Tue, Jul 21, 2009 at 8:39 PM, Gene Leynes wrote:
> # Just when I thought I had the basic stuff mastered
> # This has been quite perplexing, thanks for any help
>
>
> ## Here's the example:
>
> db1=data.frame(
>    olditems=c('soup','','','','nuts'),
>    prices=c(4.45, 3.25, 4.42, 2.25, 3.98))
> db2=data.frame(
>    newitems=c('stew','crackers','tofu','goatsmilk','peanuts'))
>
> str(db1)    #factors and prices
> str(db2)    #new names, but I want *only* the updates
>
> is.na(db1$olditems)  #a little surprising that '' is not equal to NA
> db1$olditems==''     #oh good, at least I can get to the blanks this way
> db1$olditems[db1$olditems=='']  #wait, only one item is returned?
> db1[db1$olditems=='',]  #somehow this works!
>
> #how would I get the new item names into the old items column of db1??
> # I was expecting that this would work:
> #    db1$olditems[db1$olditems=='']=
> #        db2$newitems[db1$olditems=='']
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to replace NAs in a vector of factors?

2009-07-21 Thread hadley wickham
On Tue, Jul 21, 2009 at 7:39 PM, Gene Leynes wrote:
> # Just when I thought I had the basic stuff mastered
> # This has been quite perplexing, thanks for any help
>
>
> ## Here's the example:
>
> db1=data.frame(
>    olditems=c('soup','','','','nuts'),
>    prices=c(4.45, 3.25, 4.42, 2.25, 3.98))
> db2=data.frame(
>    newitems=c('stew','crackers','tofu','goatsmilk','peanuts'))
>
> str(db1)    #factors and prices
> str(db2)    #new names, but I want *only* the updates
>
> is.na(db1$olditems)  #a little surprising that '' is not equal to NA

Why?

> db1$olditems==''     #oh good, at least I can get to the blanks this way
> db1$olditems[db1$olditems=='']  #wait, only one item is returned?

length(db1$olditems[db1$olditems==''])

> db1[db1$olditems=='',]  #somehow this works!
>
> #how would I get the new item names into the old items column of db1??
> # I was expecting that this would work:
> #    db1$olditems[db1$olditems=='']=
> #        db2$newitems[db1$olditems=='']

Try working with characters instead of factors.

db1$olditems <- as.character(db1$olditems)
db2$newitems <- as.character(db2$newitems)
db1$olditems[db1$olditems==''] <- db2$newitems[db1$olditems=='']

Hadley

-- 
http://had.co.nz/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] dump() an object of type raw ?

2009-07-21 Thread David Winsemius


On Jul 21, 2009, at 7:19 PM, Benjamin Tyner wrote:


Is there a way to do this? I tried


Do what?

> writeBin(pi, raw())
[1] 18 2d 44 54 fb 21 09 40

Why would you want to "source" _that_?
source() is for parse-able and executable R code.



 x <- writeBin(pi, raw())
 dump("x","x.R")
 source("x.R")

but is seems x.R is not source()-able, as it contains an unexpected  
symbol.


Thanks
Ben




David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] list of lm() results

2009-07-21 Thread Gene Leynes
I found that it was easiest to just pull out the parts I want with an
"apply" loop.

Here I am regressing a bunch of equity returns on some index returns and
just keeping the coefficients:

EqCoefQ1 = apply(retEqQ1,2,
function(x) summary(lm(x~retIndexQ1))$coefficients)

On Tue, Jul 21, 2009 at 4:49 PM, Giovanni Petris  wrote:

>
> My guess is that you did not define the list correcly before making
> any assignments to it. Try something like
>
> > myResults <- vector("list", 16)
>
> and then your code
>
> > myResults[1] <- lm(...)
> > myResults[2] <- lm(...)
> > myResults[3] <- lm(...)
>  ...
> > myResults[15] <- lm(...)
> > myResults[16] <- lm(...)
>
> HTH,
> Giovanni
>
> > Date: Tue, 21 Jul 2009 11:27:52 -0500
> > From: Idgarad 
> > Sender: r-help-boun...@r-project.org
> > Precedence: list
> > DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com;
> s=gamma;
> > DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma;
> >
> > How can I get the results of lm() into a list so I can loop through the
> results?
> >
> > e.g.
> >
> > myResults[1] <- lm(...)
> > myResults[2] <- lm(...)
> > myResults[3] <- lm(...)
> > ...
> > myResults[15] <- lm(...)
> > myResults[16] <- lm(...)
> >
> > so far every attempt I've tried doesn't work throwing a "number of
> > items to replace is not a multiple of replacement length" error or
> > simply not working.
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
> >
>
> --
>
> Giovanni Petris  
> Associate Professor
> Department of Mathematical Sciences
> University of Arkansas - Fayetteville, AR 72701
> Ph: (479) 575-6324, 575-8630 (fax)
> http://definetti.uark.edu/~gpetris/
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] How to replace NAs in a vector of factors?

2009-07-21 Thread Gene Leynes
# Just when I thought I had the basic stuff mastered
# This has been quite perplexing, thanks for any help


## Here's the example:

db1=data.frame(
olditems=c('soup','','','','nuts'),
prices=c(4.45, 3.25, 4.42, 2.25, 3.98))
db2=data.frame(
newitems=c('stew','crackers','tofu','goatsmilk','peanuts'))

str(db1)#factors and prices
str(db2)#new names, but I want *only* the updates

is.na(db1$olditems)  #a little surprising that '' is not equal to NA
db1$olditems=='' #oh good, at least I can get to the blanks this way
db1$olditems[db1$olditems=='']  #wait, only one item is returned?
db1[db1$olditems=='',]  #somehow this works!

#how would I get the new item names into the old items column of db1??
# I was expecting that this would work:
#db1$olditems[db1$olditems=='']=
#db2$newitems[db1$olditems=='']

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Adjusting x/y text labels for a bwplot using cex.lab

2009-07-21 Thread S Ellison
You probably missed the bit in the lattice documentation which says that
few if any of the standard par() parameters work on lattice. lattice
uses its own system.

Look at the xyplot help page and seek out the scales argument. That
tells you that scales is a list, optionally with x and y components,
that controls the axis appearance. The bit you probably want is the cex
component of that.

Using one of the simpler examples from ?xyplot, this looks like:
xyplot(decrease ~ treatment, OrchardSprays, groups = rowpos,
   type = "a",
   auto.key = list(space = "right", points = FALSE, lines = TRUE),
   scales=list(x=list(cex=1.5))) #specifies bigger text on the
x-axis

Steve E

>>> mcobb_berkeley  07/21/09 10:10 PM >>>

Searched for this and found some help, but I still can't figure it out. 

I have trying to enlarge the x and y labels on my box plot.  I
understand
that you can do this using "cex.lab", but it does not seem to be working
for
me.  I must be adding it in the wrong spot.  Any help would be greatly
appreciated.  Here is my code:

bwplot(hr~Herd, data=telemetry, notch=T, ylab="Home Range Area (ha)",
xlab="Herd", 
par.settings = list(plot.symbol = list(col = "black"),box.umbrella =
list(col ="black"), box.rectangle=list(col="black")),fill="light blue")

~McCrea
-- 
View this message in context:
http://www.nabble.com/Adjusting-x-y-text-labels-for-a-bwplot-using-cex.lab-tp24595920p24595920.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


***
This email and any attachments are confidential. Any use...{{dropped:8}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] kaplan-meier error

2009-07-21 Thread Marc Schwartz

On Jul 21, 2009, at 7:23 PM, Joseph Magagnoli wrote:


Hi all,
I am getting an error in my code and I don't know what the problem is.
I am using R 2.9 on ubuntu.   my code is as follows:

## Libraries ##
library(survival)
library(foreign)

## reading data ##

data<-read.dta("http://psfaculty.ucdavis.edu/bsjjones/cabinet.dta";)
head(data)
attach(data)


fit1<-survfit(Surv(durat,censor))
and I get the following error

fit1<-survfit(Surv(durat,censor))

Error in survfit(Surv(durat, censor)) :
 Survfit requires a formula or a coxph fit as the first argument
any help is greatly appreciated
Joe



Try:

  fit1 <- survfit(Surv(durat, censor) ~ 1, data = data)

See ?survfit and note in the description of 'formula':

  For a single survival curve the right hand side should be ~ 1.

I would also avoid using attach() as it can create subsequent  
problems, which is why there is the 'data' argument to most R  
functions that take a formula argument.


HTH,

Marc Schwartz

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] kaplan-meier error

2009-07-21 Thread Joseph Magagnoli
Hi all, 
I am getting an error in my code and I don't know what the problem is.
I am using R 2.9 on ubuntu.   my code is as follows:

## Libraries ##
library(survival)
library(foreign)

## reading data ##

data<-read.dta("http://psfaculty.ucdavis.edu/bsjjones/cabinet.dta";)
head(data)
attach(data)


fit1<-survfit(Surv(durat,censor))
and I get the following error 
> fit1<-survfit(Surv(durat,censor))
Error in survfit(Surv(durat, censor)) :
  Survfit requires a formula or a coxph fit as the first argument
any help is greatly appreciated 
Joe

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Checking on closed file connections

2009-07-21 Thread Duncan Murdoch

On 21/07/2009 8:13 PM, Jim Nemesh wrote:

On Jul 21, 2009, at 6:40 PM, Duncan Murdoch wrote:


On 21/07/2009 5:03 PM, Jim Nemesh wrote:

Hi!  I'm wondering if there's a smart way around this:
fileName= (some valid file on your system)

fileCon=file(fileName, open="rt")
l<-readLines (fileCon, n= 1)

isOpen(fileCon)

[1] TRUE

close(fileCon)
isOpen(fileCon)

Error in isOpen(fileCon) : invalid connection
How do you test for a file being closed if isOpen gives you an  
error  message?

You could use try().

But you shouldn't be doing that.  Whoever opens the connection  
should close it.  The isOpen() test is designed to be used on newly  
created connections, being passed to some other function and  
guaranteed to be valid.  Was it created with file(fileName,  
open="rt") or file(fileName)?  That's what isOpen() is there to  
determine.  (The first one was opened, and should be closed by  
whoever opened it; the second one was not, and the function that  
uses it shouldn't leave it open.)


Duncan Murdoch



The story is of course slightly more complicated.  I'm writing a  
streaming caching file input class.  When you instantiate the class,  
you open a connection (as shown in the sample code.)  I wanted to  
close the file input when either a) I run out of lines in the file b)  
when the class is garbage collected.  There's something fishy going on  
with the connection, as it always claims to be invalid when I try to  
close it, yet it reads data out perfectly fine.


Essentially, I'm always getting warnings about not closing the file,  
but I can't close the file!


Some paired down "real world" code (using R.oo Library)


I don't have anything against R.oo, but I really don't know it at all. 
So you're on your own with this one.


Duncan Murdoch



setConstructorS3("StreamingFileReader", function(fileName) {
if (missing (fileName)) fileName =NA
extend(Object(), "StreamingFileReader",
.fileName=fileName,
.fileCon=NA,
.initialized=F)
})

setMethodS3("init", "StreamingFileReader", function(this, ...){
if (this$.initialized==F) {
this$.fileCon=file(this$.fileName, open="rt")
#read header
if (this$.hasHeader) {
l<-readLines (this$.fileCon, n= 1)
l<-strsplit (l, '\t')[[1]]
this$.header=l
}   
this$.initialized=T
}
})

setMethodS3("getHeader", "StreamingFileReader", function(this,  
numLines=1, ...) {

this$init()
return (this$.header);
})

#lots of attempts to remove, cleanup, etc the connection I'm holding  
on to.

setMethodS3("finalize", "StreamingFileReader", function(this, ...) {
#if (this$.hasMoreData==F) return()
#if (is.na(this$.fileCon)) return()
#rm (this$.fileCon)
#print (isOpen(this$.fileCon))
#close(this$.fileCon)
#close(this$.fileCon)
})


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Checking on closed file connections

2009-07-21 Thread Jim Nemesh

On Jul 21, 2009, at 6:40 PM, Duncan Murdoch wrote:

> On 21/07/2009 5:03 PM, Jim Nemesh wrote:
>> Hi!  I'm wondering if there's a smart way around this:
>> fileName= (some valid file on your system)
>> >fileCon=file(fileName, open="rt")
>> >l<-readLines (fileCon, n= 1)
>> >
>> > isOpen(fileCon)
>> [1] TRUE
>> >close(fileCon)
>> > isOpen(fileCon)
>> Error in isOpen(fileCon) : invalid connection
>> How do you test for a file being closed if isOpen gives you an  
>> error  message?
>
> You could use try().
>
> But you shouldn't be doing that.  Whoever opens the connection  
> should close it.  The isOpen() test is designed to be used on newly  
> created connections, being passed to some other function and  
> guaranteed to be valid.  Was it created with file(fileName,  
> open="rt") or file(fileName)?  That's what isOpen() is there to  
> determine.  (The first one was opened, and should be closed by  
> whoever opened it; the second one was not, and the function that  
> uses it shouldn't leave it open.)
>
> Duncan Murdoch
>

The story is of course slightly more complicated.  I'm writing a  
streaming caching file input class.  When you instantiate the class,  
you open a connection (as shown in the sample code.)  I wanted to  
close the file input when either a) I run out of lines in the file b)  
when the class is garbage collected.  There's something fishy going on  
with the connection, as it always claims to be invalid when I try to  
close it, yet it reads data out perfectly fine.

Essentially, I'm always getting warnings about not closing the file,  
but I can't close the file!

Some paired down "real world" code (using R.oo Library)

setConstructorS3("StreamingFileReader", function(fileName) {
if (missing (fileName)) fileName =NA
extend(Object(), "StreamingFileReader",
.fileName=fileName,
.fileCon=NA,
.initialized=F)
})

setMethodS3("init", "StreamingFileReader", function(this, ...){
if (this$.initialized==F) {
this$.fileCon=file(this$.fileName, open="rt")
#read header
if (this$.hasHeader) {
l<-readLines (this$.fileCon, n= 1)
l<-strsplit (l, '\t')[[1]]
this$.header=l
}   
this$.initialized=T
}
})

setMethodS3("getHeader", "StreamingFileReader", function(this,  
numLines=1, ...) {
this$init()
return (this$.header);
})

#lots of attempts to remove, cleanup, etc the connection I'm holding  
on to.
setMethodS3("finalize", "StreamingFileReader", function(this, ...) {
#if (this$.hasMoreData==F) return()
#if (is.na(this$.fileCon)) return()
#rm (this$.fileCon)
#print (isOpen(this$.fileCon))
#close(this$.fileCon)
#close(this$.fileCon)
})
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] dump() an object of type raw ?

2009-07-21 Thread Benjamin Tyner

Is there a way to do this? I tried

  x <- writeBin(pi, raw())
  dump("x","x.R")
  source("x.R")

but is seems x.R is not source()-able, as it contains an unexpected symbol.

Thanks
Ben

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] RODBC results from stored procedure

2009-07-21 Thread tradenet

Thanks Dieter.

The stored proc drops and recreates a result table that contains a copy of
the same result set that is returned by the query.

If I pause after line 1, line 2 returns a valid result set and line 4
displays a table of data.
If I do not pause the script after line 1 or 2, line 3 fails, saying
datatable does not exist (line 1 query has not completed the recreation of
datatable) and line 4 displays no data.

Also, the query in line one returns a single result set, a select statement
from datatable, but R doesn't see this returned result set after invocation
of only line 1. 


1.) dbdata<-sqlQuery(conn,"sp_GetData)  #returns a result set in query
analyzer, not in R
2.) head(dbdata) #it's empty
3.) dbdata<-sqlQuery(conn,"select * from datatable order by Date asc") 
4.) head(dbdata) #the data is in dbdata


My workaround is to run line 1's query manually before running any R
scripts.  Not ideal, but I'm at a loss for what else to try for this prickly
case.

Warm regards,

Andrew




Dieter Menne wrote:
> 
> 
> 
> tradenet wrote:
>> 
>> Thanks Dieter.
>> 
>> The date argument isn't a problem.  When I invoke the stored proc
>> execution with the date arguments the stored proc runs fine, but RODBC
>> doesn't wait for the stored proc to finish and return results.
>> 
>> 
> 
> Don't understand that one. How do you know that is did not wait to finish? 
> 
> Did the call I showed you work with the Northwind database?
> 
> Dieter
> 
> 

-- 
View this message in context: 
http://www.nabble.com/RODBC-results-from-stored-procedure-tp24503096p24597208.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Checking on closed file connections

2009-07-21 Thread Duncan Murdoch

On 21/07/2009 5:03 PM, Jim Nemesh wrote:

Hi!  I'm wondering if there's a smart way around this:

fileName= (some valid file on your system)

 >   fileCon=file(fileName, open="rt")
 >   l<-readLines (fileCon, n= 1)
 >
 > isOpen(fileCon)
[1] TRUE
 >   close(fileCon)
 > isOpen(fileCon)
Error in isOpen(fileCon) : invalid connection

How do you test for a file being closed if isOpen gives you an error  
message?


You could use try().

But you shouldn't be doing that.  Whoever opens the connection should 
close it.  The isOpen() test is designed to be used on newly created 
connections, being passed to some other function and guaranteed to be 
valid.  Was it created with file(fileName, open="rt") or file(fileName)? 
 That's what isOpen() is there to determine.  (The first one was 
opened, and should be closed by whoever opened it; the second one was 
not, and the function that uses it shouldn't leave it open.)


Duncan Murdoch

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Rcmdr GUI goes into loop via alt+backspace under Windows OS

2009-07-21 Thread tradenet

I'm using Rcmdr version 1.4-10 with R version 2.9.0 under Vista x64.

A standard editing convention under Windows is that alt+backspace is a
keyboard shortcut for "undo".  I often find myself hitting the [alt] and
[backspace] keys while editing scripts in Rcmdr. However, this causes the
Rcmdr GUI to go into a crazy mode where the menu keeps flashing and the GUI
is unresponsive.  Sometimes after several minutes, the GUI menus stop
sporadically flashing and the GUI becomes responsive again, but usually I
have to kill R.

Has anyone else seen this problem and might there be a fix for it?

If it weren't for the fact that the particular key combination is a standard
in Windows I would ignore the problem, but I often get trapped by it because
the GUI handles this standard Windows key combination is such a bizzare way.

I'd appreciate any suggestions you might have.

Regards,

Andrew
-- 
View this message in context: 
http://www.nabble.com/Rcmdr-GUI-goes-into-loop-via-alt%2Bbackspace-under-Windows-OS-tp24597087p24597087.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] EM algorithm

2009-07-21 Thread Elena 5/12

l=∑_i∑_k log [(Se(i))^(t_ik ) [1-Se(i) ]^(1-t_ik ) p+(Sp(i))^(1-t_ik )
[1-Sp(i) ]^(t_ik ) (1-p)]

This is my loglikelihood. It is a sum over i (I tests) and over k (K
patients). t_ik is the test results for the ithe test for the kth patient. 

Se(i)=sensitivity of test i, Sp(i)=specificity of test i and p=prevalence
are my three unknown parameters. Now I need to apply the EM algorithm to
this l to become estimates for these parameters. But I am not able to code
it in R, it does not work.

Do you know how to code this likelihood and the EM algorithm?
-- 
View this message in context: 
http://www.nabble.com/EM-algorithm-tp24596990p24596990.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] sampling randomly from general correlated multivariate PDFs

2009-07-21 Thread gnuman

(apologies if this looks like a re-post, I just sent a similar message to the
r-help mail list.  This version is via Nabble.)
My intended application is error propagation using the ISO GUM Supplement 1
approach (propagation of distributions using Monte Carlo strategies).  To
automate uncertainty analysis I typically have the following data:
(1) a measurement function y(x1,x2,...xn)
(2) 'n' input variables (x1,x2,...xn) their means and covariances and
marginal PDF forms (I'm only contemplating using common PDFs like gaussian,
uniform, poisson, triangular, lognormal,...).
(3) degrees of freedom for each input quantity
then
we want to simulate draws from each of the xi (say 1, so we get n*1000
random numbers) and correlate them as per the covariance data, without
destroying the form of the marginal PDF for each xi.

Q. I'd like to know if there are packages that can be used to efficiently
simulate such random
draws from general multivariate (joint) PDF functions when ONLY the
independent marginal PDFs
are known (RV means and covariance or correlation matrix)?

Q. I see there is a Markov Chain Monte Carlo package, but the mcmc
documentation is
not clear enough for me to be able to use it to simulate draws from joint
PDFs.  I'd like
to automate this type of task in R.  Is there another Monte Carlo strategy
that has
an R interface that can do this work?

I've read papers by Mishra (2004) and Al-Subaihi (2004) that give clues on
how to use MCMC, but 
I'm not adept enough (yet) to translate their strategies into a general
purpose R module. 
Surely this has already been done by someone?  Can anyone help?

Other Stats Questions/comments:
* I'm aware the underlying joint PDF cannot be uniquely determined, but I
assume for
certain simulation purposes sampling correlated RV's from the marginal PDFs
is
sufficient (eg., my purpose is uncertainty or error propagation, using say
the
ISO GUM Supplement 1 Monte Carlo approach).  Is this assumption correct, or
for
error propagation are there strong caveats to observe.
(ASIDE: The ISO GUM Supp.-1 does not provide advice on how to simulate RV's
drawn from
multivariate PDFS for other than the multivariate normal dist. for which I
can easily
use the mvtnorm or mnormt packages.)

Thanks in advance.
bms.
-- 
View this message in context: 
http://www.nabble.com/sampling-randomly-from-general-correlated-multivariate-PDFs-tp24596883p24596883.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Elementary Symmetric Polynomials

2009-07-21 Thread Austin H. Jones
We are interested in obtaining an efficient function that for a given 
vector of length t will output a vector of length t+1 that contains the 
associated values of the elementary symmetric polynomials in t 
variables. Below is what we have at the moment, but it is a little slow 
for our needs. Any suggestions?


Thanks ahead of time for any help you can offer,

Austin H. Jones
Department of Mathematics
Wake Forest University



f<-function(v)
{
prodsub<-function(v,q){prod(v[q])}
t<-length(v)
C<-vector("list",t)
for (i in 1:t)
{C[[i]]<-combn(1:t,i)}
e<-rep(0,t)
for (i in 1:(t))
{
e[i]<-sum(apply(C[[i]],2,prodsub,v=v))
}
e<-c(1,e)
e
}

Examples:


> f(c(1,2,3))
[1]  1  6 11  6


> f(c(4,6,3,1,9))
[1]1   23  193  729 1206  648

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] sampling from general multivariate pdf

2009-07-21 Thread Blair Smith
Hi,
Forgive me if I seem naive, I'm tackling multivariate stats for the first time!

Q. I'd like to know if there are packages that can be used to simulate random 
draws from general multivariate (joint) PDF functions when ONLY the independent 
marginal PDFs 
are known (RV means and covariance or correlation matrix)?

Q. I see there is a Markov Chain Monte Carlo package, but the mcmc 
documentation is 
not clear enough for me to be able to use it to simulate draws from joint PDFs. 
 I'd like 
to automate this type of task.  Is there aother Monte Carlo strategy that has 
an R interface?
Can anyone help?

Other Stats Questions/comments:
* I'm aware the underlying joint PDF cannot be uniquely determined, but I 
assume for 
certain simulation purposes sampling correlated RV's from the marginal PDFs is 
sufficient (eg., my purpose is uncertainty or error propagation, using say the 
ISO GUM Supplement 1 Monte Carlo approach).  Is this assumption correct, or for 
error propagation are there strong caveats to observe.
(ASIDE: The ISO GUM Supp.-1 does not provide advice on how to simulate RV's 
drawn from 
multivariate PDFS for other than the multivariate normal dist. for which I can 
easily 
use the mvtnorm or mnormt packages.)

Thanks in advance.
bms.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] list of lm() results

2009-07-21 Thread Giovanni Petris

My guess is that you did not define the list correcly before making
any assignments to it. Try something like

> myResults <- vector("list", 16)

and then your code

> myResults[1] <- lm(...)
> myResults[2] <- lm(...)
> myResults[3] <- lm(...)
 ...
> myResults[15] <- lm(...)
> myResults[16] <- lm(...)

HTH,
Giovanni

> Date: Tue, 21 Jul 2009 11:27:52 -0500
> From: Idgarad 
> Sender: r-help-boun...@r-project.org
> Precedence: list
> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;
> DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma;
> 
> How can I get the results of lm() into a list so I can loop through the 
> results?
> 
> e.g.
> 
> myResults[1] <- lm(...)
> myResults[2] <- lm(...)
> myResults[3] <- lm(...)
> ...
> myResults[15] <- lm(...)
> myResults[16] <- lm(...)
> 
> so far every attempt I've tried doesn't work throwing a "number of
> items to replace is not a multiple of replacement length" error or
> simply not working.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 

Giovanni Petris  
Associate Professor
Department of Mathematical Sciences
University of Arkansas - Fayetteville, AR 72701
Ph: (479) 575-6324, 575-8630 (fax)
http://definetti.uark.edu/~gpetris/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] class export in package creation / setClass / namespace?

2009-07-21 Thread L L
Thanks to both Martins, your advice solved the confusion between S3 and S4
classes for the show method.

br.
Leo

On Tue, Jul 21, 2009 at 9:58 AM, Martin Maechler  wrote:

> > "MartinMo" == Martin Morgan 
> > on Mon, 20 Jul 2009 18:57:33 -0700 writes:
>
>MartinMo> L L  writes:
>>> Ok, I could solve also the latter problem by defining show.myclass
> function in
>>> the zzz.R file and adding the line 'S3method(show,myclass)' into
> NAMESPACE
>>> file. Now the package passes all checks.
>
> MartinMo> I would have, in NAMESPACE,
>
>MartinMo> importFrom(methods, show)
>MartinMo> exportMethods(show)
>
>MartinMo> and in some file in R/
>
>MartinMo> setMethod(show, "myclass", function(object) {
>MartinMo> cat("here I am\n")
>MartinMo> })
>
>MartinMo> Do not try to make an S3 method on an S4 generic,
>MartinMo> or to create a new S4 generic for show. Since
>MartinMo> you've defined a method on show, you need to add
>MartinMo> documentation in a file in man/ (your choice; I'd
>MartinMo> add the documentation to the myclass documentation
>MartinMo> page). You only get one
>MartinMo> \alias{show,myclass-method}.
>
>MartinMo> Martin
>
> Yes, indeed!
> I'm just ``signing''  Martin Morgan's very good advice.
>
> In case it was explicit enough:
> do *NOT* define  show.myclass()  [which is an S3 method for an
>  S4 generic and S4 class ..]
>
> Martin Mächler
>
>
>>> The information on how to exactly extend existing methods and include
> new
>>> methods/classes into a package is available but rather scattered in
> the web. A
>>> step-by-step tutorial written by an experienced user who is aware of
> best
>>> practices etc. would be rather useful for a beginner.
>>> best regards
>>> Leo
>>>
>>>
>>> On Mon, Jul 20, 2009 at 7:09 PM, L L <[[lmla...@gmail.com]]> wrote:
>>>
>>> Thanks, the issue was solved by adding class definitions to the
>>> zzz.R file in the R code directory. However, this led to a new
>>> problem.
>>> The zzz.R now contains class definition:
>>> > setClass("myclass", contains = "list")
>>> and  method definition for the new class, extending the generic
>>> show':
>>> > setGeneric("show",function(x,...){standardGeneric("show")}) >
>>> setMethod("show", "myclass",function(x, ...) {cat("myclass object
>>> \n")})
>>> I get two warnings. The first one:
>>> * checking Rd files ... WARNING Rd files with duplicated alias
>>> show,myclass-method':   myclass-class.Rd show-methods.Rd
>>> I get this one because the alias row for the method
>>> (\alias{show,myclass-method}) is in both myclass-class.Rd file and
>>> show-methods.Rd file (created by promptMethods function). This is
>>> likely related to the second warning:
>>> * checking for missing documentation entries ... WARNING
> Undocumented
>>> code objects:   show
>>> I thought that the show method would've been documented correctly as
>>> I put 'show-methods.Rd' file in the 'man' directory. This does not
>>> seem to be the case, however.
>>> Any help on how I should document the extended show method in this
>>> case, or are there some mistakes in my original definition for
>>> extended 'show'? I could not find suitable examples from the
>>> web/mailing lists.
>>> br Leo
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Adjusting x/y text labels for a bwplot using cex.lab

2009-07-21 Thread mcobb_berkeley

Searched for this and found some help, but I still can't figure it out.  
I have trying to enlarge the x and y labels on my box plot.  I understand
that you can do this using "cex.lab", but it does not seem to be working for
me.  I must be adding it in the wrong spot.  Any help would be greatly
appreciated.  Here is my code:

bwplot(hr~Herd, data=telemetry, notch=T, ylab="Home Range Area (ha)",
xlab="Herd", 
par.settings = list(plot.symbol = list(col = "black"),box.umbrella =
list(col ="black"), box.rectangle=list(col="black")),fill="light blue")

~McCrea
-- 
View this message in context: 
http://www.nabble.com/Adjusting-x-y-text-labels-for-a-bwplot-using-cex.lab-tp24595920p24595920.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] is a sequence of dates consecutive, without gaps?

2009-07-21 Thread Marc Schwartz


On Jul 21, 2009, at 4:58 PM, Christopher W. Ryan wrote:

I have a long sequence of dates, about 6 years worth, as one column  
in a
data frame. How can I test whether the sequence is consecutive, that  
is,

without gaps?

Thanks.

--Chris



Chris,

Presuming that your data frame is called DF, the date column is called  
'date' AND 'date' has been coerced to a Date class, you could use:


  all(diff(DF$date) == 1)

which will tell you if all of the differences between successive dates  
in the column are one day.


See ?diff for more information.

If the dates have not yet been coerced to a Date class, see ?as.Date.

HTH,

Marc Schwartz

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to extract the upper xlim and ylim of my plot?

2009-07-21 Thread Marc Schwartz

On Jul 21, 2009, at 4:03 PM, Mark Na wrote:


Dear R-helpers,

I wish to place some text in a plot, at approx 10% of my upper xlim  
and

approx 90% of my upper ylim, i.e.


plot(log(all$SR,10)~log(all$AREA,10))
text(.1*max(xlim),.9*max(ylim),"text to be placed")


(I know how to give absolute coordinates for text location, but I  
wish to

use relative coordinates).

My code (above) doesn't work because I don't know how to properly  
extract

the upper xlim and ylim values.

Does anyone know how I could extract the upper xlim and ylim values  
(without
using max(x-variable) or max (y-variable)...I wish to keep this as  
general

as possible and not point to the original data.

Thanks in advance,

Mark


Mark,

  par("usr")

after the plot has been created will give you the x,y corner extremes  
of the plot region in user coordinates.


See ?par and scroll down to 'usr'.

HTH,

Marc Schwartz

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] time attribute from a file

2009-07-21 Thread Erin Hodgess
Thanks to all!

file.info is it.


On Tue, Jul 21, 2009 at 4:06 PM, Erik Iverson wrote:
> Peter, that is assigning the time of creation of the object name.
>
> I think Erin might be looking for the file.info function, see ?file.info .
>
> Erik
>
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf Of Peter Alspach
> Sent: Tuesday, July 21, 2009 4:03 PM
> To: Erin Hodgess; R help
> Subject: Re: [R] time attribute from a file
>
> Tena koe Erin
>
> You could write a wee wrapper and give the file an attribute.  For
> example,
>
> copy <- function (file = "clipboard", sep = "\t", na.strings = c("NA",
>    "*"), as.is = T, ...)
> {
>    myX <- read.table(file, sep = sep, na.strings = na.strings,
>        as.is = as.is, ...)
>    attr(myX, "copy time") <- Sys.time()
>    myX
> }
>
> I did this some time ago, but I must admit that I find it of limited
> value.
>
> HTH 
>
> Peter Alspach
>
>> -Original Message-
>> From: r-help-boun...@r-project.org
>> [mailto:r-help-boun...@r-project.org] On Behalf Of Erin Hodgess
>> Sent: Wednesday, 22 July 2009 8:55 a.m.
>> To: R help
>> Subject: [R] time attribute from a file
>>
>> Dear R People:
>>
>> I am reading in a file via read.table.   Is there a way to bring in
>> the time that the file was created, please?
>>
>> Thanks,
>> Erin
>>
>>
>> --
>> Erin Hodgess
>> Associate Professor
>> Department of Computer and Mathematical Sciences University
>> of Houston - Downtown
>> mailto: erinm.hodg...@gmail.com
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> The contents of this e-mail are confidential and may be subject to legal 
> privilege.
>  If you are not the intended recipient you must not use, disseminate, 
> distribute or
>  reproduce all or any part of this e-mail or attachments.  If you have 
> received this
>  e-mail in error, please notify the sender and delete all material pertaining 
> to this
>  e-mail.  Any opinion or views expressed in this e-mail are those of the 
> individual
>  sender and may not represent those of The New Zealand Institute for Plant and
>  Food Research Limited.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: erinm.hodg...@gmail.com

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to extract the upper xlim and ylim of my plot?

2009-07-21 Thread milton ruser
May be:

text(.1*max(all$AREA),.9*max(all$SR),"text to be placed")

?

bests

milton

On Tue, Jul 21, 2009 at 5:03 PM, Mark Na  wrote:

> Dear R-helpers,
>
> I wish to place some text in a plot, at approx 10% of my upper xlim and
> approx 90% of my upper ylim, i.e.
>
> > plot(log(all$SR,10)~log(all$AREA,10))
> > text(.1*max(xlim),.9*max(ylim),"text to be placed")
>
> (I know how to give absolute coordinates for text location, but I wish to
> use relative coordinates).
>
> My code (above) doesn't work because I don't know how to properly extract
> the upper xlim and ylim values.
>
> Does anyone know how I could extract the upper xlim and ylim values
> (without
> using max(x-variable) or max (y-variable)...I wish to keep this as general
> as possible and not point to the original data.
>
> Thanks in advance,
>
> Mark
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to extract the upper xlim and ylim of my plot?

2009-07-21 Thread Peter Alspach
Tena koe Mark

?par

in particular usr parameter, accessible by par()$usr

HTH 

Peter Alspach

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Mark Na
> Sent: Wednesday, 22 July 2009 9:04 a.m.
> To: r-help@r-project.org
> Subject: [R] How to extract the upper xlim and ylim of my plot?
> 
> Dear R-helpers,
> 
> I wish to place some text in a plot, at approx 10% of my 
> upper xlim and approx 90% of my upper ylim, i.e.
> 
> > plot(log(all$SR,10)~log(all$AREA,10))
> > text(.1*max(xlim),.9*max(ylim),"text to be placed")
> 
> (I know how to give absolute coordinates for text location, 
> but I wish to use relative coordinates).
> 
> My code (above) doesn't work because I don't know how to 
> properly extract the upper xlim and ylim values.
> 
> Does anyone know how I could extract the upper xlim and ylim 
> values (without using max(x-variable) or max (y-variable)...I 
> wish to keep this as general as possible and not point to the 
> original data.
> 
> Thanks in advance,
> 
> Mark
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

The contents of this e-mail are confidential and may be subject to legal 
privilege.
 If you are not the intended recipient you must not use, disseminate, 
distribute or
 reproduce all or any part of this e-mail or attachments.  If you have received 
this
 e-mail in error, please notify the sender and delete all material pertaining 
to this
 e-mail.  Any opinion or views expressed in this e-mail are those of the 
individual
 sender and may not represent those of The New Zealand Institute for Plant and
 Food Research Limited.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] time attribute from a file

2009-07-21 Thread Steve Lianoglou

Hi,

On Jul 21, 2009, at 4:54 PM, Erin Hodgess wrote:


Dear R People:

I am reading in a file via read.table.   Is there a way to bring in
the time that the file was created, please?



See: ?file.info and the mtime, ctime, atime attributes it returns.

-steve

--
Steve Lianoglou
Graduate Student: Physiology, Biophysics and Systems Biology
Weill Medical College of Cornell University

Contact Info: http://cbio.mskcc.org/~lianos/contact

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] time attribute from a file

2009-07-21 Thread Erik Iverson
Peter, that is assigning the time of creation of the object name. 

I think Erin might be looking for the file.info function, see ?file.info .

Erik 

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Peter Alspach
Sent: Tuesday, July 21, 2009 4:03 PM
To: Erin Hodgess; R help
Subject: Re: [R] time attribute from a file

Tena koe Erin

You could write a wee wrapper and give the file an attribute.  For
example,

copy <- function (file = "clipboard", sep = "\t", na.strings = c("NA", 
"*"), as.is = T, ...) 
{
myX <- read.table(file, sep = sep, na.strings = na.strings, 
as.is = as.is, ...)
attr(myX, "copy time") <- Sys.time()
myX
}

I did this some time ago, but I must admit that I find it of limited
value.

HTH 

Peter Alspach 

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Erin Hodgess
> Sent: Wednesday, 22 July 2009 8:55 a.m.
> To: R help
> Subject: [R] time attribute from a file
> 
> Dear R People:
> 
> I am reading in a file via read.table.   Is there a way to bring in
> the time that the file was created, please?
> 
> Thanks,
> Erin
> 
> 
> --
> Erin Hodgess
> Associate Professor
> Department of Computer and Mathematical Sciences University 
> of Houston - Downtown
> mailto: erinm.hodg...@gmail.com
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

The contents of this e-mail are confidential and may be ...{{dropped:21}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] thousands separator

2009-07-21 Thread Christophe Dutang
thanks,

I test it on the following example

27 076 552 440.95,230 400.04,1
27 176 285 276.98,170 240.22,1
27 276 040 780.57,640 053.22,1
27 376 072 983.53,800 300.1,1
27 476 552 531.87,411 770.68,1
27 576 552 919.09,130 010.21,1
27 676 285 254.43,460 020.70,1
27 776 072 840.44,220 071.16,1
27 876 032 704.00,540 121.14,1

setwd("~/Desktop")
x <- read.table("untitled", as.is=TRUE, sep=",")
col2cvt <- c('V1', 'V2','V3')

for(i in col2cvt)
{   x[[i]] <- as.numeric(gsub(" ","",x[[i]]))
}
print(x,digits=22)

it works fine!

Christophe

Le 21 juil. 09 à 21:47, jim holtman a écrit :

> What I do is read the file in and then convert the various columns  
> to numeric
>
> x <- read.table(..., as.is=TRUE)
> col2cvt <- c('V1', 'V3','V6')  # columns for conversion
> for (i in col2cvt){
>x[[i]] <- as.numeric(gsub(",", "", x[[i]]))
> }
>
> Replace ',' with ' ' for blanks.
>
> On Tue, Jul 21, 2009 at 3:34 PM, christophe  
> dutang wrote:
>> Dear useRs,
>>
>> I was wondering how to deal with data where thousands separator is  
>> a space
>> or a comma? with google, I thought I found the answer but the  
>> thread (
>> http://tolstoy.newcastle.edu.au/R/help/06/04/25524.html) just  
>> focuses on
>> decimal separator.
>>
>> Is there any function to numbers written like this in a csv file?
>>
>> Thanks in advance
>>
>> Christophe
>>
>> --
>> Christophe DUTANG
>> Ph. D. student at ISFA
>>
>>[[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
>
> -- 
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem that you are trying to solve?

--
Christophe Dutang
Ph.D. student at ISFA, Lyon, France
website: http://dutangc.free.fr







[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Checking on closed file connections

2009-07-21 Thread Jim Nemesh

Hi!  I'm wondering if there's a smart way around this:

fileName= (some valid file on your system)

>fileCon=file(fileName, open="rt")
>l<-readLines (fileCon, n= 1)
>
> isOpen(fileCon)
[1] TRUE
>close(fileCon)
> isOpen(fileCon)
Error in isOpen(fileCon) : invalid connection

How do you test for a file being closed if isOpen gives you an error  
message?


Thanks!

-Jim

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] S_alloc or Calloc for return value

2009-07-21 Thread Dan Kelley

Self-posting the solution, to help those who come across this thread with a
similar interest --

My solution, arrived at with the generous help of those who have replied to
my question, was to use .Call, as exemplified below.  My task was to find
indices in a "raw" buffer (input) that match a particular two-byte sequence
(b1 and b2).  (It's a task that is common in my research area.  The files
are large, so the use of C was important both to achive speed and to fit
within memory constraings.)  


indices <- .Call("match2bytes", as.raw(input), as.raw(b1), as.raw(b2))



#include 
#include 
#include 
/* test R code:
   buf <- as.raw(c(0xa5, 0x11, 0xaa, 0xa5, 0x11, 0x00))
   dyn.load("bitwise.so")
   m <- .Call("match2bytes", buf, as.raw(0xa5), as.raw(0x11))
   print(m)
 */
SEXP match2bytes(SEXP buf, SEXP m1, SEXP m2)
{
  int i, j, n, n_match;
  double *resp;
  unsigned char *bufp, *m1p, *m2p;
  SEXP res;
  PROTECT(buf = AS_RAW(buf));
  PROTECT(m1 = AS_RAW(m1));
  PROTECT(m2 = AS_RAW(m2));
  bufp = RAW_POINTER(buf);
  m1p = RAW_POINTER(m1);
  m2p = RAW_POINTER(m2);
  n = LENGTH(buf);
  n_match = 0;
  for (i = 0; i < n - 1; i++) {
if (bufp[i] == *m1p && bufp[i + 1] == *m2p) {
  n_match++;
  ++i;  /* skip */
}
  }
  PROTECT(res = NEW_NUMERIC(n_match));
  resp = NUMERIC_POINTER(res);
  j = 0;
  for (i = 0; i < n - 1; i++) {
if (j <= n_match && bufp[i] == *m1p && bufp[i + 1] == *m2p) {
  resp[j++] = i + 1;/* the 1 is to offset from C to R */
}
  }
  UNPROTECT(4);
  return(res);
}


-- 
View this message in context: 
http://www.nabble.com/S_alloc-or-Calloc-for-return-value-tp24579062p24595838.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] time attribute from a file

2009-07-21 Thread Tobias Verbeke

Erin Hodgess wrote:

Dear R People:

I am reading in a file via read.table.   Is there a way to bring in
the time that the file was created, please?


Use file.info on the same file ?

HTH,
Tobias

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] How to extract the upper xlim and ylim of my plot?

2009-07-21 Thread Mark Na
Dear R-helpers,

I wish to place some text in a plot, at approx 10% of my upper xlim and
approx 90% of my upper ylim, i.e.

> plot(log(all$SR,10)~log(all$AREA,10))
> text(.1*max(xlim),.9*max(ylim),"text to be placed")

(I know how to give absolute coordinates for text location, but I wish to
use relative coordinates).

My code (above) doesn't work because I don't know how to properly extract
the upper xlim and ylim values.

Does anyone know how I could extract the upper xlim and ylim values (without
using max(x-variable) or max (y-variable)...I wish to keep this as general
as possible and not point to the original data.

Thanks in advance,

Mark

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] EM algorithm

2009-07-21 Thread Andrej Kastrin

Hi,

two useful references for beginning:

www.stat.umn.edu/geyer/5931/mle/mle.pdf
www.unc.edu/~monogan/computing/r/MLE_in_R.pdf

Andrej

Elena 5/12 wrote:

Hi,

I have the following problem: I am working on assessing the accuracy of
diagnostic tests. I have a log likelihood and 3 unknown parameters. Now I
want to apply the EM algorithm to find the maximum likelihood estimates of
these parameters. But I don't know anaything about how to code that in R.

Can somebody help me??

Greats,
Elena


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] time attribute from a file

2009-07-21 Thread Peter Alspach
Tena koe Erin

You could write a wee wrapper and give the file an attribute.  For
example,

copy <- function (file = "clipboard", sep = "\t", na.strings = c("NA", 
"*"), as.is = T, ...) 
{
myX <- read.table(file, sep = sep, na.strings = na.strings, 
as.is = as.is, ...)
attr(myX, "copy time") <- Sys.time()
myX
}

I did this some time ago, but I must admit that I find it of limited
value.

HTH 

Peter Alspach 

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Erin Hodgess
> Sent: Wednesday, 22 July 2009 8:55 a.m.
> To: R help
> Subject: [R] time attribute from a file
> 
> Dear R People:
> 
> I am reading in a file via read.table.   Is there a way to bring in
> the time that the file was created, please?
> 
> Thanks,
> Erin
> 
> 
> --
> Erin Hodgess
> Associate Professor
> Department of Computer and Mathematical Sciences University 
> of Houston - Downtown
> mailto: erinm.hodg...@gmail.com
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

The contents of this e-mail are confidential and may be subject to legal 
privilege.
 If you are not the intended recipient you must not use, disseminate, 
distribute or
 reproduce all or any part of this e-mail or attachments.  If you have received 
this
 e-mail in error, please notify the sender and delete all material pertaining 
to this
 e-mail.  Any opinion or views expressed in this e-mail are those of the 
individual
 sender and may not represent those of The New Zealand Institute for Plant and
 Food Research Limited.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] is a sequence of dates consecutive, without gaps?

2009-07-21 Thread Christopher W. Ryan
I have a long sequence of dates, about 6 years worth, as one column in a
data frame. How can I test whether the sequence is consecutive, that is,
without gaps?

Thanks.

--Chris
-- 
Christopher W. Ryan, MD
SUNY Upstate Medical University Clinical Campus at Binghamton
40 Arch Street, Johnson City, NY  13790
cryanatbinghamtondotedu

"If you want to build a ship, don't drum up the men to gather wood,
divide the work and give orders. Instead, teach them to yearn for the
vast and endless sea."  [Antoine de St. Exupery]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Searching for specific values in a matrix

2009-07-21 Thread Mehdi Khan
thank you VERY much, I have to run now, but I will look at this in the next
few days (going on a field trip).  I really appreciate it!

Mehdi Khan

On Tue, Jul 21, 2009 at 12:49 PM, Steve Lianoglou <
mailinglist.honey...@gmail.com> wrote:

>
> On Jul 21, 2009, at 3:27 PM, Mehdi Khan wrote:
>
>  I understand your explanation about the test for even numbers.  However I
>> am still a bit confused as to how to go about finding a particular value.
>>  Here is an example data set
>>
>> col #  attr1attr2   attr 3LONLAT
>> 17209 DNANA -122.9409 38.27645
>> 17210BCNANA -122.9581 38.36304
>> 17211 BNANA -123.6851 41.67121
>> 17212BCNANA -123.0724 38.93073
>> 17213 CNANA -123.7240 41.84403
>> 17214 464NA -122.9430 38.30988
>> 17215 CNANA -123.4442 40.65369
>> 17216BCNANA -122.9389 38.31551
>> 17217 CNANA -123.0747 38.97998
>> 17218 CNANA -123.6580 41.59610
>> 17219 CNANA -123.4513 40.70992
>> 17220 CNANA -123.0901 39.06473
>> 17221BCNANA -123.0653 38.94845
>> 17222BCNANA -122.9464 38.36808
>> 17223 464NA -123.0143 38.70205
>> 17224  NA 5 -122.8609 37.94137
>> 17225  NA 5 -122.8628 37.95057
>> 17226  NA 7 -122.8646 37.95978
>>
>
> For future reference, perhaps paste this in a way that's easy for us to
> paste into a running R session so we can use it, like so:
>
> df <- data.frame(
> coln=c(17209, 17210, 17211, 17212, 17213, 17214, 17215, 17216, 17217,
> 17218, 17219, 17220, 17221, 17222, 17223, 17224, 17225, 17226),
>
> attr1=c("D","BC","B","BC","C",NA,"C","BC","C","C","C","C","BC","BC",NA,NA,NA,NA),
> attr2=c( NA,NA,NA,NA,NA,464,NA,NA,NA,NA,NA,NA,NA,NA,464,NA,NA,NA),
> attr3=c(NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,5,5,7),
> LON=c(
> -122.9409,-122.9581,-123.6851,-123.0724,-123.7240,-122.9430,-123.4442,-122.9389,-123.0747,-123.6580,-123.4513,-123.0901,-123.0653,-122.9464,-123.0143,-122.8609,-122.8628,-122.8646),
>
> LAT=c(38.27645,38.36304,41.67121,38.93073,41.84403,38.30988,40.65369,38.31551,38.97998,41.59610,40.70992,39.06473,38.94845,38.36808,38.70205,37.94137,37.95057,37.95978))
>
>  If I wanted to find the row with Lat = 37.95978
>>
>
> Using an "indexing vector":
>
> R> lats <- df$LAT == 37.95978
> # or with the %~% from before:
> # lats <- df$LAT %~% 37.95978
> R> df[lats,]
>coln attr1 attr2 attr3   LON  LAT
> 18 17226  NA 7 -122.8646 37.95978
>
> Using the "subset" function:
>
> R> subset(df, LAT == 37.95978)
>coln attr1 attr2 attr3   LON  LAT
> 18 17226  NA 7 -122.8646 37.95978
>
>  , how would i do that?  How would  I find the rows with BC?
>>
>
> R> subset(df, attr1 == 'BC')
>coln attr1 attr2 attr3   LON  LAT
> 2  17210BCNANA -122.9581 38.36304
> 4  17212BCNANA -123.0724 38.93073
> 8  17216BCNANA -122.9389 38.31551
> 13 17221BCNANA -123.0653 38.94845
> 14 17222BCNANA -122.9464 38.36808
>
>
> If you try with an "indexing vector" the NA's will trip you up:
>
> R> df[df$attr1 == 'BC',]
>  coln attr1 attr2 attr3   LON  LAT
> 217210BCNANA -122.9581 38.36304
> 417212BCNANA -123.0724 38.93073
> NA  NA  NANANA   NA
> 817216BCNANA -122.9389 38.31551
> 13   17221BCNANA -123.0653 38.94845
> 14   17222BCNANA -122.9464 38.36808
> NA.1NA  NANANA   NA
> NA.2NA  NANANA   NA
> NA.3NA  NANANA   NA
> NA.4NA  NANANA   NA
>
> So you could do something like:
>
> > df[df$attr1 == 'BC' & !is.na(df$attr1),]
>coln attr1 attr2 attr3   LON  LAT
> 2  17210BCNANA -122.9581 38.36304
> 4  17212BCNANA -123.0724 38.93073
> 8  17216BCNANA -122.9389 38.31551
> 13 17221BCNANA -123.0653 38.94845
> 14 17222BCNANA -122.9464 38.36808
>
>
> HTH,
> -steve
>
> --
> Steve Lianoglou
> Graduate Student: Physiology, Biophysics and Systems Biology
> Weill Medical College of Cornell University
>
> Contact Info: 
> http://cbio.mskcc.org/~lianos/contact
>
>
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Searching for specific values in a matrix

2009-07-21 Thread Mehdi Khan
I understand your explanation about the test for even numbers.  However I am
still a bit confused as to how to go about finding a particular value.  Here
is an example data set

col #  attr1attr2   attr 3LONLAT
17209 DNANA -122.9409 38.27645
17210BCNANA -122.9581 38.36304
17211 BNANA -123.6851 41.67121
17212BCNANA -123.0724 38.93073
17213 CNANA -123.7240 41.84403
17214 464NA -122.9430 38.30988
17215 CNANA -123.4442 40.65369
17216BCNANA -122.9389 38.31551
17217 CNANA -123.0747 38.97998
17218 CNANA -123.6580 41.59610
17219 CNANA -123.4513 40.70992
17220 CNANA -123.0901 39.06473
17221BCNANA -123.0653 38.94845
17222BCNANA -122.9464 38.36808
17223 464NA -123.0143 38.70205
17224  NA 5 -122.8609 37.94137
17225  NA 5 -122.8628 37.95057
17226  NA 7 -122.8646 37.95978

If I wanted to find the row with Lat = 37.95978, how would i do that?  How
would  I find the rows with BC?

Thank you for all your help!

Mehdi Khan

On Tue, Jul 21, 2009 at 12:10 PM, Steve Lianoglou <
mailinglist.honey...@gmail.com> wrote:

> I am a bit confused as to what the following command does:
>> evens <- df$nums %% 2 == 0
>>
>
> It returns a logical vector (I'm calling this an "indexing vector") that is
> TRUE where df$nums %% 2 == 0 (%% is modulo division, and 4 mod 2 == 0 -- so
> it's a test for "being even")
>
>  In my matrix example, let's say I am looking for the variable(s) BC and I
>> want R to return all the rows with that value...
>>
>
> You "just" have to setup a suitable test and build an "indexing" vector to
> select the appropriate rows -- or use the subset function (see ?subset).
>
> If it's still confusing to you, please create a trivial example data.frame
> and send it back to the list along with things you'd like to "find", so we
> can give you concrete examples on different ways you can find what you need.
>
>  or If I want a value such as 33.543.  How would I get it to do that?
>> Just a single value in the latter case.  I have already converted it to a
>> data frame.
>>
>
> Be careful when searching for doubles/floats as sometimes you'll miss what
> you're looking for if you are using exact matches (ie something ==
> something.else) ... I have an almost.equals function in my "bag of
> utilities" that I'd probably use for stuff like this:
>
> almost.equal <- function(x, y, eps=0.01) {
>  abs(x - y) < eps
> }
>
> '%~%' <- function(x, y) almost.equal(x, y))
>
> R> x <- rnorm(1000, sd=.0001)
> R> sum(x %~% 0)
> ## Equivalently: sum(almost.equal(x, 0))
> [1] 8
>
> R> sum(x == 0)
> [1] 0
>
> Summing over a logical vector treats the TRUE values as 1 and FALSE values
> as 0.
>
> HTH,
>
> -steve
>
> --
> Steve Lianoglou
> Graduate Student: Physiology, Biophysics and Systems Biology
> Weill Medical College of Cornell University
>
> Contact Info: 
> http://cbio.mskcc.org/~lianos/contact
>
>
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] time attribute from a file

2009-07-21 Thread Erin Hodgess
Dear R People:

I am reading in a file via read.table.   Is there a way to bring in
the time that the file was created, please?

Thanks,
Erin


-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: erinm.hodg...@gmail.com

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Re gression using age and Duration of disease as a continous factors

2009-07-21 Thread Mehdi Khan
It was decent, I ended up not going to class and only going to discussions
and reading the book, got an A-.

On Tue, Jul 21, 2009 at 12:18 PM, Steve Lianoglou <
mailinglist.honey...@gmail.com> wrote:

>
> On Jul 21, 2009, at 1:56 PM, Mehdi Khan wrote:
>
>
>> http://www.amazon.com/gp/product/007310874X/ref=pd_lpo_k2_dp_sr_1?pf_rd_p=304485901&pf_rd_s=lpo-top-stripe-1&pf_rd_t=201&pf_rd_i=0256117365&pf_rd_m=ATVPDKIKX0DER&pf_rd_r=155Y7AP1SHTSJESHM15M
>>
>> This is our textbook for regression analysis.  Go through the first 8 or 9
>> chapters and you're good.
>>
>
> By the by, do you like this book?
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Searching for specific values in a matrix

2009-07-21 Thread Mehdi Khan
I am a bit confused as to what the following command does:
evens <- df$nums %% 2 == 0

In my matrix example, let's say I am looking for the variable(s) BC and I
want R to return all the rows with that value... or If I want a value such
as 33.543.  How would I get it to do that?   Just a single value in the
latter case.  I have already converted it to a data frame.

Thanks a lot!

On Tue, Jul 21, 2009 at 11:34 AM, Steve Lianoglou <
mailinglist.honey...@gmail.com> wrote:

>
> On Jul 21, 2009, at 1:47 PM, Mehdi Khan wrote:
>
>  Hello all,
>>
>> I have a seemingly simple question which I have searched for an answer for
>> for a few hours without luck.  I have a matrix of both values and
>> characters
>> with thousands of rows.  I would like to run a search of this matrix for
>> certain values and would like the search to retrieve the entire row.  How
>> would I accomplish this?
>>
>
> Oh, values! Woops
>
> Like so?
>
> df <- data.frame(nums=1:10, words=c("Abelonian",
>"abeltree",
>"Abencerrages",
>"abenteric",
>"abepithymia",
>"Aberdeen",
>"aberdevine",
>"Aberdonian",
>"Aberia",
>"aberrance"))
>
> evens <- df$nums %% 2 == 0
> df[evens,]
>
> You can build such an indexing vector (like evens) in a number of different
> ways to suite your problem.
>
>
> -steve
>
> --
> Steve Lianoglou
> Graduate Student: Physiology, Biophysics and Systems Biology
> Weill Medical College of Cornell University
>
> Contact Info: 
> http://cbio.mskcc.org/~lianos/contact
>
>
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] EM algorithm

2009-07-21 Thread Elena 5/12

Hi,

I have the following problem: I am working on assessing the accuracy of
diagnostic tests. I have a log likelihood and 3 unknown parameters. Now I
want to apply the EM algorithm to find the maximum likelihood estimates of
these parameters. But I don't know anaything about how to code that in R.

Can somebody help me??

Greats,
Elena
-- 
View this message in context: 
http://www.nabble.com/EM-algorithm-tp24595358p24595358.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] error when installing rjags

2009-07-21 Thread Tobias Verbeke

Hi Mark,

What command did you use exactly to install the package ?

The following blog post by Yu-Sung Su

http://yusung.blogspot.com/2009/01/install-jags-and-rjags-in-fedora.html

indicates that some configure.args might need to be set to
succesfully install the package (at least on Fedora 10)

install.packages("rjags", 
configure.args="--with-jags-include=/usr/local/include/JAGS 
--with-jags-lib=/usr/local/lib/JAGS 
--with-jags-modules=/usr/local/lib/JAGS/modules")


The fact that in the error message complains some files are
not found might have to do with one of the appropriate paths
not being picked up.

HTH,
Tobias

markle...@verizon.net wrote:

   Hi All: I get the following error when trying to install the rjags package.
   I've installed the
   jags software and I'm using Fedora 10.0 and my sessionInfo is at the bottom
   of this email.
   I'm also sorry if this email ends up having control A's all over it. I still
   haven't figured how to fix that. Thanks.
   [1] "LOADING MASS LIBRARY"
   checking for prefix by checking for jags... /usr/bin/jags
   configure: creating ./config.status
   config.status: creating src/Makevars
   configure: creating ./config.status
   config.status: creating src/Makevars
   config.status: creating R/unix/zzz.R
   g++ -m32 -I/usr/include/R -I/usr/include/JAGS -I/usr/local/include  Â
   -fpicÂ-O2  -g  -pipe  -Wall  -Wp,-D_FORTIFY_SOURCE=2  -fexceptions
   -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic
   -fasynchronous-unwind-tables -c jags.cc -o jags.o
   jags.cc:8:21: error Console.h No such file or directory
   jags.cc:9:24: error: util/naing.h: No such file or directory
   jags.cc:20: error: 'SArray' was not declared in this scope
   jags.cc:21: error expected ',' or ';' before { token
   R version 2.9.0 (2009-04-17)
   i386-redhat-linux-gnu
   locale:
   LC_CTYPE=en_US.utf8;LC_NUMERIC=C;LC_TIME=en_US.utf8;LC_COLLATE=en_US.utf8;LC
   _MONETARY=C;LC_MESSAGES=en_US.utf8;LC_PAPER=en_US.utf8;LC_NAME=C;LC_ADDRESS=
   C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.utf8;LC_IDENTIFICATION=C
   attached base packages:
   [1] datasets  utils     stats     graphics  grDevices methods Â
   base   Â
   other attached packages:
   Â [1] gsubfn_0.3-8Â Â Â Â Â Â  proto_0.3-8Â Â Â Â Â Â Â  latticeExtra_0.5-4
   RColorBrewer_1.0-2filehash_2.0-1Â Â Â Â reshape_0.8.2Â Â Â Â Â
   plyr_0.1.8Â Â Â Â Â Â Â Â  rOpenBUGS_0.0-1Â Â Â  caret_4.19Â Â Â Â Â Â Â
   [10]dyn_0.2-8Â Â Â Â Â Â Â Â Âcoda_0.13-4Â Â Â Â Â Â Â
   lattice_0.17-22Â Â Â  zoo_1.5-5Â Â Â Â Â Â Â Â Â  chron_2.3-30Â Â Â Â Â Â
   MASS_7.2-46Â Â Â Â Â Â
   loaded via a namespace (and not attached):
   [1] grid_2.9.0
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Customization options with .Renviron, R_LIBS, .Rprofile etc

2009-07-21 Thread Steve Lianoglou

Hi,

On Jul 21, 2009, at 3:56 PM, ravi wrote:

Hi,
I am interested in customizing the installation of R. I have
gone through the “R Installation and Administration” manual. But some
of the stuff is not clear to me and I would like to get clarifications
on the following points (for a Windows installation with
R_HOME=C:\\R\\R-2.9.1 ) :
1.  I understand that I need to create a
file, .Renviron with the following path : R_HOME\\etc\\.Renviron where
a number of environmental variables can be set. I would first like to
know if the file to be created is Renviron or .Renviron.


If the files in the R install on my mac would provide a hint, I'm  
guessing it should be Renviron (no period).



Both versions
are mentioned in the manual. By the way, many functions in R start  
with

a period.


Really? Which functions have you found that you want to use start with  
a period?


Anyway, I'm guessing these are functions are ones that probably  
shouldn't be used by "an end user."



Is there any special significance to a name (file, function
etc) if it starts with a period?


Files that start with a period are typically reserved for "hidden  
files", at least on unix/linux machines ... not sure about windows  
machines.



2.  I want to have two different
libraries – one for the packages that follow with the R installation
and a second one for any additional packages that I add afterwards. By
doing this, I hope to avoid repeating the installation of these  
packages

once again after an update of R.


I wouldn't recommend doing this in this in this scenario. "Minor"  
upgrades in R (ie. 2.9.0 to 2.9.1) don't really require you to  
reinstall your packages, but an upgrade from 2.8 to 2.9 should also  
involve upgrading all packages you have installed.


In either event, you can install a package in a particular directory  
by setting the target directory path in the "lib" argument to the  
"install.packages" function.



I understand that I can set the paths
to these libraries with the environmental variables R_LIBS or
R_LIBS_USER in the .Renviron file. But I am not entirely sure about  
the

difference between these two environmental variables. It is mentioned
in the manual that multiple paths (for different libraries) can be
specified. Does this mean that I can set the paths with any of these
environmental variables? Or, should I set R_LIBS=R_HOME\\library and
R_LIBS_USER to my private library? Does this also mean that any  
package that

I add with the install.packages() function will then end up in the
private library?
3.  If I want to start R with a certain set of
packages loaded on startup, I understand that I need to create a file
.Rprofile with the path R_HOME\\etc\\.Rprofile. Again, should it be
.Rprofile or Rprofile (or, is it Rprofile.site which I see is already
present in my R installation)?


It should be .Rprofile -- probably you want to put this file in your  
home directory.



Is the following syntax OK for
specifying the environmental variable
R_DEFAULT_PACKAGES = {“base”, “datasets”,”utils”,”ggplot2”,“lattice”}
How can I add, for example, ggplot2 and lattice to the list of  
default packages that R normally starts with?


A simple way is to just add the appropriate "library" calls at the  
start of your ~/.Rprofile file



4.
If I add a .Renviron file to my working directory, will it override
that in R_HOME? Or, is it the other way around? Can I add a .Rprofile
file as well to the working directory where I can specify the
R_DEFAULT_PACKAGES a little differently?


Have a look at ?Startup and I don't think R loads an .Rprofile file in  
your current working directory (at least, it's not doing it for me).


-steve

--
Steve Lianoglou
Graduate Student: Physiology, Biophysics and Systems Biology
Weill Medical College of Cornell University

Contact Info: http://cbio.mskcc.org/~lianos/contact

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] help for SSOAP

2009-07-21 Thread nermin sarlak

Hi,
I am trying to learn how to from within R access web services.   I am also 
interested in having R be a client and from within R access data on other web 
services.  Specifically the web services I would like to access from within R 
are “http://water.sdsc.edu/waterOneFlow/NWIS/DailyValues.asmx?WSDL” Therefor, I 
wrote the following code into R program:
> library(SSOAP) 
> processWSDL("http://water.sdsc.edu/wateroneflow/NWIS/DailyValues.asmx?WSDL";, 
> verbose=TRUE)
However, this program gave me error messages, like:
processing (sub) schema http://www.cuahsi.org/his/1.0/ws/ 
1 ) GetValues 
Error in parse(text = paste(txt, collapse = "\n")) : 
 unexpected input in "function(x, ..., obj = new( ‘" 
In addition: Warning message: 
In processWSDL("http://water.sdsc.edu/wateroneflow/NWIS/DailyValues.asmx?WSDL";, 
 : 
 Ignoring additional  ... elements.
So, I could not call the WSDL format into R. I wonder  how I access the data 
from the web services into R. I am very pleasured if you give me any 
information. Actually I try to implement nwis.R program in the SSOAP folder. 
However I got same error message. please anybody help me.. 
 
Nermin
_
Teker teker mi, yoksa hepsi birden mi? Arkadaþlarýnýzla ilgili güncel bilgileri 
tek bir yerden edinin.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Re gression using age and Duration of disease as a continous factors

2009-07-21 Thread Johannes Hüsing

Mehdi Khan schrieb:

http://www.amazon.com/gp/product/007310874X/ref=pd_lpo_k2_dp_sr_1?pf_rd_p=304485901&pf_rd_s=lpo-top-stripe-1&pf_rd_t=201&pf_rd_i=0256117365&pf_rd_m=ATVPDKIKX0DER&pf_rd_r=155Y7AP1SHTSJESHM15M

This is our textbook for regression analysis.  Go through the first 8 or 9
chapters and you're good.

  

I think he'd be ill-advised to do so.

Modelling the course of a disease is a very tricky problem whic 
definitely asks for a statistician with a couple of years experience 
under his belt, and more than just a few hours of his time. Perusing a 
book on regression may be a good thing to do in order to be able to 
communicate to the statistician, or solve some (considerably) simpler 
problem oneself, but it's like perusing a book of anatomy before your 
first surgical intervention.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Split plot analysis problems

2009-07-21 Thread Kevin W
I don't think you are clear enough about the layout within each block.  If
the four treatments are randomized, I would choose the first model.

KW


On Tue, Jul 21, 2009 at 9:38 AM, Jean-Paul Maalouf <
jean-paul.maal...@u-bordeaux1.fr> wrote:

> Hello,
>
> I would be very grateful if someone could give me a hand with my split plot
> design problems.
>
> So here is my design :
> I am studying the crossed-effects of water (wet/dry) and mowing
> (mowed/not-mowed = nm) on plant height (PH) within 2 types of plant
> communities (Xerobromion and Mesobromion) :
> - Within each type of communities, I have localised 4 blocks
> - In each block, I have defined 4 plots in order to have the 4 possible
> treatments of both the water and mowing factors : nm/dry ; mowed/dry ;
> mowed/wet ; nm/wet.
>
> Here is my data table :
>
>   Community Block Mowing WaterPH
> 1   Mesob1  Mowed   Wet  7.40
> 2   Mesob1 nm   Wet 13.10
> 3   Mesob1  Mowed   Dry  5.55
> 4   Mesob1 nm   Dry 10.35
> 5   Mesob2 nm   Dry 10.70
> 6   Mesob2  Mowed   Dry  6.38
> 7   Mesob2 nm   Wet  9.75
> 8   Mesob2  Mowed   Wet  6.35
> 9   Mesob3 nm   Wet  9.60
> 10  Mesob3  Mowed   Dry  5.10
> 11  Mesob3 nm   Dry 10.05
> 12  Mesob3  Mowed   Wet  6.25
> 13  Mesob4 nm   Wet  9.00
> 14  Mesob4  Mowed   Wet  6.50
> 15  Mesob4 nm   Dry  7.75
> 16  Mesob4  Mowed   Dry  5.90
> 17  Xerob5 nm   Wet  7.69
> 18  Xerob5  Mowed   Wet  8.11
> 19  Xerob5 nm   Dry  3.98
> 20  Xerob5  Mowed   Dry  3.69
> 21  Xerob6 nm   Wet  5.24
> 22  Xerob6  Mowed   Wet  4.22
> 23  Xerob6 nm   Dry  6.55
> 24  Xerob6  Mowed   Dry  4.40
> 25  Xerob7  Mowed   Dry  3.79
> 26  Xerob7 nm   Dry  3.91
> 27  Xerob7 nm   Wet  9.00
> 28  Xerob7  Mowed   Wet  8.50
> 29  Xerob8  Mowed   Dry  3.33
> 30  Xerob8 nm   Wet  6.25
> 31  Xerob8  Mowed   Wet  8.00
> 32  Xerob8 nm   Dry  6.33
>
> I actually have 2 questions :
> I wrote my model in two different ways, and there were differences in
> P-Values according to the model written :
>
> First model : summary(aov(PH~Community*Mowing*Water + Error(Block)))
> Error: Block
>  Df Sum Sq Mean Sq F value   Pr(>F)
> Community  1 42.182  42.182  24.407 0.002603 **
> Residuals  6 10.370   1.728
> ---
> Signif. codes:  0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1
>
> Error: Within
>   Df Sum Sq Mean Sq F valuePr(>F)
> Mowing  1 40.007  40.007 21.1747 0.0002215 ***
> Water   1 23.120  23.120 12.2370 0.0025673 **
> Community:Mowing1 21.060  21.060 11.1467 0.0036554 **
> Community:Water 1  6.901   6.901  3.6524 0.0720478 .
> Mowing:Water1  1.611   1.611  0.8527 0.3680090
> Community:Mowing:Water  1  0.858   0.858  0.4542 0.5089331
> Residuals  18 34.008   1.889
> ---
>
> - Second model (assuming that Mowing*Water are nested inside the Block
> factor) :
> summary(aov(PH~Community*Mowing*Water + Error(Block/(Mowing*Water
>
> Error: Block
>  Df Sum Sq Mean Sq F value   Pr(>F)
> Community  1 42.182  42.182  24.407 0.002603 **
> Residuals  6 10.370   1.728
> ---
> Signif. codes:  0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1
>
> Error: Block:Mowing
> Df Sum Sq Mean Sq F valuePr(>F)
> Mowing1 40.007  40.007  37.791 0.0008489 ***
> Community:Mowing  1 21.060  21.060  19.893 0.0042820 **
> Residuals 6  6.352   1.059
> ---
> Signif. codes:  0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1
>
> Error: Block:Water
>Df  Sum Sq Mean Sq F value  Pr(>F)
> Water1 23.1200 23.1200  6.0725 0.04884 *
> Community:Water  1  6.9006  6.9006  1.8125 0.22685
> Residuals6 22.8439  3.8073
> ---
> Signif. codes:  0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1
>
> Error: Block:Mowing:Water
>   Df Sum Sq Mean Sq F value Pr(>F)
> Mowing:Water1 1.6110  1.6110  2.0085 0.2062
> Community:Mowing:Water  1 0.8581  0.8581  1.0697 0.3409
> Residuals   6 4.8126  0.8021
>
> Both models give me interesting (but different!) results. Which one would
> be the most appropriate?
>
> Second question : How can I verify preliminary assumptions (normality of
> residuals and variance homogeneity) in this kind of models?
> When I ask R to extract residuals, the answer is "NULL":
>
>  residuals(aov(PH~Community*Mowing*Water + Error(Block/(Mowing*Water
>>
> NULL
>
>> residuals(aov(PH~Community*Mowing*Water + Error(Block)))
>>
> NULL
>
> A huge thanks to the one who will rescue (or at least try to rescue) my
> PhD!
>
> Sincerely,
>
>
> --
> Jean-Paul Maalouf
> UMR 1202 BIOGECO
> Inra - Université Bordeaux 1
> Bâtiment B8, Avenue des Facultés
> 33405 Talence, France
> Tel 

[R] Customization options with .Renviron, R_LIBS, .Rprofile etc

2009-07-21 Thread ravi

Hi,
I am interested in customizing the installation of R. I have
gone through the “R Installation and Administration” manual. But some
of the stuff is not clear to me and I would like to get clarifications
on the following points (for a Windows installation with
R_HOME=C:\\R\\R-2.9.1 ) :
1.  I understand that I need to create a
file, .Renviron with the following path : R_HOME\\etc\\.Renviron where
a number of environmental variables can be set. I would first like to
know if the file to be created is Renviron or .Renviron. Both versions
are mentioned in the manual. By the way, many functions in R start with
a period. Is there any special significance to a name (file, function
etc) if it starts with a period?
2.  I want to have two different
libraries – one for the packages that follow with the R installation
and a second one for any additional packages that I add afterwards. By
doing this, I hope to avoid repeating the installation of these packages
once again after an update of R. I understand that I can set the paths
to these libraries with the environmental variables R_LIBS or
R_LIBS_USER in the .Renviron file. But I am not entirely sure about the
difference between these two environmental variables. It is mentioned
in the manual that multiple paths (for different libraries) can be
specified. Does this mean that I can set the paths with any of these
environmental variables? Or, should I set R_LIBS=R_HOME\\library and
R_LIBS_USER to my private library? Does this also mean that any package that
I add with the install.packages() function will then end up in the
private library?
3.  If I want to start R with a certain set of
packages loaded on startup, I understand that I need to create a file
.Rprofile with the path R_HOME\\etc\\.Rprofile. Again, should it be
.Rprofile or Rprofile (or, is it Rprofile.site which I see is already
present in my R installation)? Is the following syntax OK for
specifying the environmental variable 
R_DEFAULT_PACKAGES = {“base”, “datasets”,”utils”,”ggplot2”,“lattice”}
How can I add, for example, ggplot2 and lattice to the list of default packages 
that R normally starts with?
4. 
If I add a .Renviron file to my working directory, will it override
that in R_HOME? Or, is it the other way around? Can I add a .Rprofile
file as well to the working directory where I can specify the
R_DEFAULT_PACKAGES a little differently?
Thanking you,
Ravi

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Searching for specific values in a matrix

2009-07-21 Thread Steve Lianoglou


On Jul 21, 2009, at 3:27 PM, Mehdi Khan wrote:

I understand your explanation about the test for even numbers.   
However I am still a bit confused as to how to go about finding a  
particular value.  Here is an example data set


col #  attr1attr2   attr 3LONLAT
17209 DNANA -122.9409 38.27645
17210BCNANA -122.9581 38.36304
17211 BNANA -123.6851 41.67121
17212BCNANA -123.0724 38.93073
17213 CNANA -123.7240 41.84403
17214 464NA -122.9430 38.30988
17215 CNANA -123.4442 40.65369
17216BCNANA -122.9389 38.31551
17217 CNANA -123.0747 38.97998
17218 CNANA -123.6580 41.59610
17219 CNANA -123.4513 40.70992
17220 CNANA -123.0901 39.06473
17221BCNANA -123.0653 38.94845
17222BCNANA -122.9464 38.36808
17223 464NA -123.0143 38.70205
17224  NA 5 -122.8609 37.94137
17225  NA 5 -122.8628 37.95057
17226  NA 7 -122.8646 37.95978


For future reference, perhaps paste this in a way that's easy for us  
to paste into a running R session so we can use it, like so:


df <- data.frame(
coln=c(17209, 17210, 17211, 17212, 17213, 17214, 17215, 17216, 17217,  
17218, 17219, 17220, 17221, 17222, 17223, 17224, 17225, 17226),
attr1 
= 
c 
("D 
","BC","B","BC","C",NA,"C","BC","C","C","C","C","BC","BC",NA,NA,NA,NA),

attr2=c( NA,NA,NA,NA,NA,464,NA,NA,NA,NA,NA,NA,NA,NA,464,NA,NA,NA),
attr3=c(NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,5,5,7),
LON 
= 
c 
( -122.9409 
,-122.9581 
,-123.6851 
,-123.0724 
,-123.7240 
,-122.9430 
,-123.4442 
,-122.9389 
,-123.0747 
,-123.6580 
,-123.4513 
,-123.0901,-123.0653,-122.9464,-123.0143,-122.8609,-122.8628,-122.8646),
LAT 
= 
c 
(38.27645,38.36304,41.67121,38.93073,41.84403,38.30988,40.65369,38.31551,38.97998,41.59610,40.70992,39.06473,38.94845,38.36808,38.70205,37.94137,37.95057,37.95978 
))



If I wanted to find the row with Lat = 37.95978


Using an "indexing vector":

R> lats <- df$LAT == 37.95978
# or with the %~% from before:
# lats <- df$LAT %~% 37.95978
R> df[lats,]
coln attr1 attr2 attr3   LON  LAT
18 17226  NA 7 -122.8646 37.95978

Using the "subset" function:

R> subset(df, LAT == 37.95978)
coln attr1 attr2 attr3   LON  LAT
18 17226  NA 7 -122.8646 37.95978


, how would i do that?  How would  I find the rows with BC?


R> subset(df, attr1 == 'BC')
coln attr1 attr2 attr3   LON  LAT
2  17210BCNANA -122.9581 38.36304
4  17212BCNANA -123.0724 38.93073
8  17216BCNANA -122.9389 38.31551
13 17221BCNANA -123.0653 38.94845
14 17222BCNANA -122.9464 38.36808


If you try with an "indexing vector" the NA's will trip you up:

R> df[df$attr1 == 'BC',]
  coln attr1 attr2 attr3   LON  LAT
217210BCNANA -122.9581 38.36304
417212BCNANA -123.0724 38.93073
NA  NA  NANANA   NA
817216BCNANA -122.9389 38.31551
13   17221BCNANA -123.0653 38.94845
14   17222BCNANA -122.9464 38.36808
NA.1NA  NANANA   NA
NA.2NA  NANANA   NA
NA.3NA  NANANA   NA
NA.4NA  NANANA   NA

So you could do something like:

> df[df$attr1 == 'BC' & !is.na(df$attr1),]
coln attr1 attr2 attr3   LON  LAT
2  17210BCNANA -122.9581 38.36304
4  17212BCNANA -123.0724 38.93073
8  17216BCNANA -122.9389 38.31551
13 17221BCNANA -123.0653 38.94845
14 17222BCNANA -122.9464 38.36808

HTH,
-steve

--
Steve Lianoglou
Graduate Student: Physiology, Biophysics and Systems Biology
Weill Medical College of Cornell University

Contact Info: http://cbio.mskcc.org/~lianos/contact

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] thousands separator

2009-07-21 Thread jim holtman
What I do is read the file in and then convert the various columns to numeric

x <- read.table(..., as.is=TRUE)
col2cvt <- c('V1', 'V3','V6')  # columns for conversion
for (i in col2cvt){
x[[i]] <- as.numeric(gsub(",", "", x[[i]]))
}

Replace ',' with ' ' for blanks.

On Tue, Jul 21, 2009 at 3:34 PM, christophe dutang wrote:
> Dear useRs,
>
> I was wondering how to deal with data where thousands separator is a space
> or a comma? with google, I thought I found the answer but the thread (
> http://tolstoy.newcastle.edu.au/R/help/06/04/25524.html) just focuses on
> decimal separator.
>
> Is there any function to numbers written like this in a csv file?
>
> Thanks in advance
>
> Christophe
>
> --
> Christophe DUTANG
> Ph. D. student at ISFA
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Odd coefficent behavior

2009-07-21 Thread Peter Ehlers

Idgarad,

I guess that all of your factor variables are indicators with levels
"0" and "1". Try changing the levels to "NO", "YES" for one of the
variables and see what you get. I think that the output will clarify
the (actually not) "random" 1s.

 -Peter

Idgarad wrote:

Why are my coefficients getting appended with a 1? It borks a match I
do later against the original list that doesn't have the random 1
added to the end.


linearModel[[1]]


Call:
lm(formula = modelSource ~ +UNITBUILD + UNITDB + ITBUILD + ITDB +
UATBUILD + UATDB + HOGANCODE + RCF + ReleaseST1 + ReleaseST2 +
ReleaseBLA + Small.Bank.Acquisitions + HLY.NewYear + HLY.MLK +
HLY.PRES + HLY.MEMORIAL + HLY.J4 + HLY.LABOR + HLY.COLUMBUS +
HLY.VETS + HLY.THANKS + HLY.XMAS + HLY.ELECT + HLY.PATRIOT + EOM,
data = mcReg)

Coefficients:
 (Intercept)UNITBUILD1   UNITDB1
405.8326   -8.5675   13.5029
ITBUILD1 ITDB1 UATBUILD1
 33.0950   -6.19380.2625
  UATDB1HOGANCODE1  RCF1
 -3.7793   -3.48255.3243
 ReleaseST11   ReleaseST21   ReleaseBLA1
 13.6911   -9.4573   -3.3526
Small.Bank.Acquisitions1  HLY.NewYear1  HLY.MLK1
 36.6445  -92.5360   22.1168
   HLY.PRES1 HLY.MEMORIAL1   HLY.J41
  7.1886  -13.0013  -14.3520
  HLY.LABOR1 HLY.COLUMBUS1 HLY.VETS1
 -0.9740  -16.9177   16.2969
 HLY.THANKS1 HLY.XMAS1HLY.ELECT1
-15.9056  -65.9887  -10.9916
HLY.PATRIOT1  EOM1
-20.2531   15.4775

Now all the variables with a 1 appended are factors so is that normal
behavior? (if so then I can adjust the match() command to pad a 1 to
the master list.)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] thousands separator

2009-07-21 Thread christophe dutang
Dear useRs,

I was wondering how to deal with data where thousands separator is a space
or a comma? with google, I thought I found the answer but the thread (
http://tolstoy.newcastle.edu.au/R/help/06/04/25524.html) just focuses on
decimal separator.

Is there any function to numbers written like this in a csv file?

Thanks in advance

Christophe

-- 
Christophe DUTANG
Ph. D. student at ISFA

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Re gression using age and Duration of disease as a continous factors

2009-07-21 Thread Marc Schwartz

On Jul 21, 2009, at 11:29 AM, 1Rnwb wrote:
Thanks Steve,Thanks for the explanation,  I agree the question is  
too vague,
I do not what a regression is I have switched to R a couple of  
months ago,
after working in Excel for a long time.  I also know the lm, glm  
functions
in R. but due to my data I am completely lost.  it looks like the  
experts
individuals just come to poke fun at our expesense who has no  
background of

statistics.

I have a 8 proteins and I have two groups with 840 samples in  
control and
1140 samples in diseases further stratified by sex, draw age,  
duration of
disease. all these groups and sub groups is making the thing very  
confusing
as how to do the regression in R. the pupose is to show the changes  
in the
levels of these proteins as the disease progress or changes in their  
levels

with respect to progression in age, effect of gender, SNPs for these
proteins, it is a pretty big dataset.

The suggestion that consult the statistician is kind of funny as  the
statistician in my center is my co-mentor and from past 5 years he is
sitting on the data without any output.

I am not here to ask someone to do my data analysis, but to get an
understanding of the process as well as a proper direction to look  
for the
analysis.  after all I do have to explain all these things to my  
boss as

well.

Thanks




First, welcome to R.

Not withstanding other replies, a key issue here is that the specific  
data and analytic domains for which you are querying are not ones that  
can be really learned remotely. These are not "simple" regression  
models and this is certainly not an area that the point and click  
approach of Excel would even begin to address, much less the plethora  
of other criticisms relevant to Excel's use for statistical analysis.


To the question that you pose in the final paragraph above, the proper  
direction for you at this point is to seek out a professional  
statistician with expertise in this particular domain. I would think  
that after 5 years, even your boss would be more comfortable in  
knowing that this was done with the requisite expertise applied.


It sounds like you are a clinical researcher/physician. If your  
current statistician is not in a position to offer assistance after 5  
years, for whatever reason, then as I note above, you need to seek  
another with experience in this domain who can work with you in close  
collaboration on this project. Neither statistician nor clinician  
should work in isolation here. It is the value in collaboration where  
each brings their own respective expertise to the table that results  
in a reasonable result.


The purpose of R's e-mail lists is not to provide general statistical  
consultancy, but to address specific issues as they pertain to R. Your  
initial queries fall into the former. In other words, your questions  
so far focus more on learning what are in fact, quite complex  
statistical methods and insights. That being said, there will be some  
interactions on the lists pertaining to general statistical issues  
when presented with *focused* questions, even though they may not be R  
specific.


The nature of your data suggest that you might benefit from the use of  
tools that have been made available via the Bioconductor project:


  http://www.bioconductor.org

which is built upon R and intended for this domain. There are entire  
books written on this subject in particular and on regression in  
general, some of which have been referenced by others in this thread.  
Bioconductor exists because it address specific needs for analytic  
tools within a statistical subspecialty, that R in general may not.


Just as there are specialties within medicine, they exist within  
statistics. You would not have an orthopaedic surgeon perform a mitral  
valve replacement any more than you would have a cardiac surgeon do a  
hip replacement, even though they are both surgeons, went to medical  
school and share general surgery training. They both went on to  
additional years of study within their specialties, diverging in their  
skills and knowledge base at that point.


The same in this domain.

There are fundamental questions that you will need to address  
regarding the means by which your data have been collected which can  
and will impact how you go about analyzing it. It sounds like this  
dataset may be the result of a retrospective collection process or  
'data of opportunity' rather than a prospective study design.


Do you have serial protein measurements from the same subjects over  
time, or will your time based hypotheses be inferred based upon single  
protein samples from each subject where the subjects happened to be  
available at differing ages and with differing disease duration/ 
progression at the time of data collection?


Why are there not equal sample sizes in your two groups? Does this  
infer sample selection bias that will have to be taken into account?  
What other source

Re: [R] Re gression using age and Duration of disease as a continous factors

2009-07-21 Thread Steve Lianoglou


On Jul 21, 2009, at 1:56 PM, Mehdi Khan wrote:


http://www.amazon.com/gp/product/007310874X/ref=pd_lpo_k2_dp_sr_1?pf_rd_p=304485901&pf_rd_s=lpo-top-stripe-1&pf_rd_t=201&pf_rd_i=0256117365&pf_rd_m=ATVPDKIKX0DER&pf_rd_r=155Y7AP1SHTSJESHM15M

This is our textbook for regression analysis.  Go through the first  
8 or 9

chapters and you're good.


By the by, do you like this book?

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Odd coefficent behavior

2009-07-21 Thread David Winsemius


On Jul 21, 2009, at 2:42 PM, Idgarad wrote:


Why are my coefficients getting appended with a 1? It borks a match I
do later against the original list that doesn't have the random 1
added to the end.


linearModel[[1]]


The linearModel function that is easiest to find appears (on the basis  
of its help page anyway) to be designed as a dialog control function  
rather than to be used in the manner you are illustrating. Of course I  
could be wrong about which package you are using, and the the  
appropriate use of linearModel, but why not see if you don't get more  
expected results with:


lm(formula = modelSource ~ +UNITBUILD + UNITDB + ITBUILD + ITDB +
   UATBUILD + UATDB + HOGANCODE + RCF + ReleaseST1 + ReleaseST2 +
   ReleaseBLA + Small.Bank.Acquisitions + HLY.NewYear + HLY.MLK +
   HLY.PRES + HLY.MEMORIAL + HLY.J4 + HLY.LABOR + HLY.COLUMBUS +
   HLY.VETS + HLY.THANKS + HLY.XMAS + HLY.ELECT + HLY.PATRIOT +   
EOM,

   data = mcReg)




Call:
lm(formula = modelSource ~ +UNITBUILD + UNITDB + ITBUILD + ITDB +
UATBUILD + UATDB + HOGANCODE + RCF + ReleaseST1 + ReleaseST2 +
ReleaseBLA + Small.Bank.Acquisitions + HLY.NewYear + HLY.MLK +
HLY.PRES + HLY.MEMORIAL + HLY.J4 + HLY.LABOR + HLY.COLUMBUS +
HLY.VETS + HLY.THANKS + HLY.XMAS + HLY.ELECT + HLY.PATRIOT +EOM,
data = mcReg)

Coefficients:
(Intercept)UNITBUILD1
UNITDB1
   405.8326   -8.5675
13.5029
   ITBUILD1 ITDB1  
UATBUILD1
33.0950   -6.1938 
0.2625
 UATDB1 
HOGANCODE1  RCF1
-3.7793   -3.4825 
5.3243
ReleaseST11   ReleaseST21
ReleaseBLA1
13.6911   -9.4573
-3.3526
Small.Bank.Acquisitions1  HLY.NewYear1   
HLY.MLK1
36.6445  -92.5360
22.1168
  HLY.PRES1 HLY.MEMORIAL1
HLY.J41
 7.1886  -13.0013   
-14.3520
 HLY.LABOR1 HLY.COLUMBUS1  
HLY.VETS1
-0.9740  -16.9177
16.2969
HLY.THANKS1 HLY.XMAS1 
HLY.ELECT1
   -15.9056  -65.9887   
-10.9916

   HLY.PATRIOT1  EOM1
   -20.2531   15.4775

Now all the variables with a 1 appended are factors so is that normal
behavior? (if so then I can adjust the match() command to pad a 1 to
the master list.)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Searching for specific values in a matrix

2009-07-21 Thread Steve Lianoglou

I am a bit confused as to what the following command does:
evens <- df$nums %% 2 == 0


It returns a logical vector (I'm calling this an "indexing vector")  
that is TRUE where df$nums %% 2 == 0 (%% is modulo division, and 4 mod  
2 == 0 -- so it's a test for "being even")


In my matrix example, let's say I am looking for the variable(s) BC  
and I want R to return all the rows with that value...


You "just" have to setup a suitable test and build an "indexing"  
vector to select the appropriate rows -- or use the subset function  
(see ?subset).


If it's still confusing to you, please create a trivial example  
data.frame and send it back to the list along with things you'd like  
to "find", so we can give you concrete examples on different ways you  
can find what you need.


or If I want a value such as 33.543.  How would I get it to do  
that?   Just a single value in the latter case.  I have already  
converted it to a data frame.


Be careful when searching for doubles/floats as sometimes you'll miss  
what you're looking for if you are using exact matches (ie something  
== something.else) ... I have an almost.equals function in my "bag of  
utilities" that I'd probably use for stuff like this:


almost.equal <- function(x, y, eps=0.01) {
  abs(x - y) < eps
}

'%~%' <- function(x, y) almost.equal(x, y))

R> x <- rnorm(1000, sd=.0001)
R> sum(x %~% 0)
## Equivalently: sum(almost.equal(x, 0))
[1] 8

R> sum(x == 0)
[1] 0

Summing over a logical vector treats the TRUE values as 1 and FALSE  
values as 0.


HTH,
-steve

--
Steve Lianoglou
Graduate Student: Physiology, Biophysics and Systems Biology
Weill Medical College of Cornell University

Contact Info: http://cbio.mskcc.org/~lianos/contact

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Odd coefficent behavior

2009-07-21 Thread Idgarad
Why are my coefficients getting appended with a 1? It borks a match I
do later against the original list that doesn't have the random 1
added to the end.

> linearModel[[1]]

Call:
lm(formula = modelSource ~ +UNITBUILD + UNITDB + ITBUILD + ITDB +
UATBUILD + UATDB + HOGANCODE + RCF + ReleaseST1 + ReleaseST2 +
ReleaseBLA + Small.Bank.Acquisitions + HLY.NewYear + HLY.MLK +
HLY.PRES + HLY.MEMORIAL + HLY.J4 + HLY.LABOR + HLY.COLUMBUS +
HLY.VETS + HLY.THANKS + HLY.XMAS + HLY.ELECT + HLY.PATRIOT + EOM,
data = mcReg)

Coefficients:
 (Intercept)UNITBUILD1   UNITDB1
405.8326   -8.5675   13.5029
ITBUILD1 ITDB1 UATBUILD1
 33.0950   -6.19380.2625
  UATDB1HOGANCODE1  RCF1
 -3.7793   -3.48255.3243
 ReleaseST11   ReleaseST21   ReleaseBLA1
 13.6911   -9.4573   -3.3526
Small.Bank.Acquisitions1  HLY.NewYear1  HLY.MLK1
 36.6445  -92.5360   22.1168
   HLY.PRES1 HLY.MEMORIAL1   HLY.J41
  7.1886  -13.0013  -14.3520
  HLY.LABOR1 HLY.COLUMBUS1 HLY.VETS1
 -0.9740  -16.9177   16.2969
 HLY.THANKS1 HLY.XMAS1HLY.ELECT1
-15.9056  -65.9887  -10.9916
HLY.PATRIOT1  EOM1
-20.2531   15.4775

Now all the variables with a 1 appended are factors so is that normal
behavior? (if so then I can adjust the match() command to pad a 1 to
the master list.)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Searching for specific values in a matrix

2009-07-21 Thread Steve Lianoglou

Hi,

On Jul 21, 2009, at 1:47 PM, Mehdi Khan wrote:


Hello all,

I have a seemingly simple question which I have searched for an  
answer for
for a few hours without luck.  I have a matrix of both values and  
characters
with thousands of rows.  I would like to run a search of this matrix  
for
certain values and would like the search to retrieve the entire  
row.  How

would I accomplish this?


Are the characters and values (numeric, I guess(?)) in their own  
respective columns? If so, make sure you use a data frame.


That having been said:

R> df <- data.frame(nums=1:10, words=c("Abelonian",
"abeltree",
"Abencerrages",
"abenteric",
"abepithymia",
"Aberdeen",
"aberdevine",
"Aberdonian",
"Aberia",
"aberrance"))
R> idxs <- grep('ia', df$words)
R> df[idxs,]
  nums   words
11   Abelonian
55 abepithymia
88  Aberdonian
99  Aberia

Is something like that what you're after?

-steve

--
Steve Lianoglou
Graduate Student: Physiology, Biophysics and Systems Biology
Weill Medical College of Cornell University

Contact Info: http://cbio.mskcc.org/~lianos/contact

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Searching for specific values in a matrix

2009-07-21 Thread Steve Lianoglou


On Jul 21, 2009, at 1:47 PM, Mehdi Khan wrote:


Hello all,

I have a seemingly simple question which I have searched for an  
answer for
for a few hours without luck.  I have a matrix of both values and  
characters
with thousands of rows.  I would like to run a search of this matrix  
for
certain values and would like the search to retrieve the entire  
row.  How

would I accomplish this?


Oh, values! Woops

Like so?

df <- data.frame(nums=1:10, words=c("Abelonian",
"abeltree",
"Abencerrages",
"abenteric",
"abepithymia",
"Aberdeen",
"aberdevine",
"Aberdonian",
"Aberia",
"aberrance"))

evens <- df$nums %% 2 == 0
df[evens,]

You can build such an indexing vector (like evens) in a number of  
different ways to suite your problem.


-steve

--
Steve Lianoglou
Graduate Student: Physiology, Biophysics and Systems Biology
Weill Medical College of Cornell University

Contact Info: http://cbio.mskcc.org/~lianos/contact

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Re gression using age and Duration of disease as a continous factors

2009-07-21 Thread Steve Lianoglou

it looks like the experts
individuals just come to poke fun at our expesense who has no  
background of

statistics.


This isn't really a fair statement ... I'd simply suggest to be  
mindful of what you ask. It was as if you couldn't be bothered to take  
the time to fully describe your problem (how was anybody supposed to  
deduce what you explained below from your original email??), but  
wanted other people to take their time and to understand what you want  
and do your work for you.


When you look at it that way, it's not a big surprise that you  
received some of the answers you received. Lastly, I'm not sure how  
true this is through and through, or how relevant it is to *this  
particular scenario* but when people post to a somehow-professional  
list such as this one, I'd think it's generally frowned upon to use  
some bizarre alias instead of a real name (my 2 cents, there).


In any event, perhaps we can all move on.

As a disclaimer, anything I say from here on out would require taking  
with a grain of salt:


I have a 8 proteins and I have two groups with 840 samples in  
control and
1140 samples in diseases further stratified by sex, draw age,  
duration of
disease. all these groups and sub groups is making the thing very  
confusing
as how to do the regression in R. the pupose is to show the changes  
in the
levels of these proteins as the disease progress or changes in their  
levels

with respect to progression in age, effect of gender, SNPs for these
proteins, it is a pretty big dataset.


I'd start by trying to creating some clever graphics to see if you can  
eyeball any trends to see if you can get some juice out of further  
downstream analysis.


Anyway, I don't think there is a simple answer you can get from an  
email, and I'm a bit surprised that your statistician mentor doesn't  
have at least some idea of where to start. It sounds like you want to  
build some predictive model that uses the values in your predictor  
variables to predict some real valued expression of your protein(s) --  
and the problem is that there is no guarantee that you can do this  
with the data you have anyway (repeat after me: "research is fun").


That being said, one (overly) simple approach (there is no grouping/ 
subgrouping here) you can do is to use glmnet to and try to do lasso  
or elasticnet regression using all the factors you mention as  
predictor variables for the 8 different output vectors, which would be  
the individual expression of your proteins (so -- that's 8 different  
models you're trying to learn).


The hope is that the lasso will nuke some of the predictors (by  
setting their coefficients to 0) and help you find "the most  
important" factors that influence the protein expression ... in all  
likelihood, this probably won't work ... and if this is the type of  
answer you are looking to get, I'm not sure you will get anything  
satisfactory (repeat after me: "research is fun").



I am not here to ask someone to do my data analysis, but to get an
understanding of the process as well as a proper direction to look  
for the
analysis.  after all I do have to explain all these things to my  
boss as

well.


I'm not an expert, but there is no canned process to do this ... and  
like I said, there is no guarantee you can do this .. I mean, does it  
make sense to set up your problem in this way and expect a reasonable  
outcome (biologically speaking-wise)? Do you have to somehow take into  
account how these 8 proteins are interacting w/ each other? Many  
questions to answer ...


Anyway ... I'm not sure there's any real value in this email, but I've  
got my own fish to fry so time to move on ...


-steve

--
Steve Lianoglou
Graduate Student: Physiology, Biophysics and Systems Biology
Weill Medical College of Cornell University

Contact Info: http://cbio.mskcc.org/~lianos/contact

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Re gression using age and Duration of disease as a continous factors

2009-07-21 Thread Mehdi Khan
http://www.amazon.com/gp/product/007310874X/ref=pd_lpo_k2_dp_sr_1?pf_rd_p=304485901&pf_rd_s=lpo-top-stripe-1&pf_rd_t=201&pf_rd_i=0256117365&pf_rd_m=ATVPDKIKX0DER&pf_rd_r=155Y7AP1SHTSJESHM15M

This is our textbook for regression analysis.  Go through the first 8 or 9
chapters and you're good.

Mehdi Khan

On Tue, Jul 21, 2009 at 9:29 AM, 1Rnwb  wrote:

>
> Thanks Steve,Thanks for the explanation,  I agree the question is too
> vague,
> I do not what a regression is I have switched to R a couple of months ago,
> after working in Excel for a long time.  I also know the lm, glm functions
> in R. but due to my data I am completely lost.  it looks like the experts
> individuals just come to poke fun at our expesense who has no background of
> statistics.
>
> I have a 8 proteins and I have two groups with 840 samples in control and
> 1140 samples in diseases further stratified by sex, draw age, duration of
> disease. all these groups and sub groups is making the thing very confusing
> as how to do the regression in R. the pupose is to show the changes in the
> levels of these proteins as the disease progress or changes in their levels
> with respect to progression in age, effect of gender, SNPs for these
> proteins, it is a pretty big dataset.
>
> The suggestion that consult the statistician is kind of funny as  the
> statistician in my center is my co-mentor and from past 5 years he is
> sitting on the data without any output.
>
> I am not here to ask someone to do my data analysis, but to get an
> understanding of the process as well as a proper direction to look for the
> analysis.  after all I do have to explain all these things to my boss as
> well.
>
> Thanks
>
>
>
> Steve Lianoglou-6 wrote:
> >
> >
> > On Jul 20, 2009, at 5:30 PM, 1Rnwb wrote:
> >
> >> I have read that multiple times without understanding anything.
> >
> > If that's the case, then perhaps you should follow Greg's first piece
> > of advice:
> >
> >> Greg Snow-2 wrote:
> >>>
> >>> If you need an explanation of what regression means, then you need
> >>> to take
> >>> a course or 2 at your local university, or at least hire a
> >>> statistical
> >>> consultant.
> >
> > We're not trying to be rude, but your question is quite ill formed,
> > and no one can really help you:
> >
> >> Please explain me as what it means and how this analysis can be done
> >> using R and which library(ies) are needed.
> >
> > It's not clear what you do/don't understand, and your problem
> > statement is too vague for anyone to tell you more.
> >
> > It seems like you're saying you don't understand what "regression" is,
> > in which case a simple email will not help you.
> >
> > "Simply put" regression is a method to predict a (typically)
> > "continuous" output by some combination of inputs, eg. predicting
> > someone's height by knowing their weight and shoe size (these are
> > continuous variables, too). It looks like in your case, your "inputs"
> > are the "continuous factors" of your email subject, which are age and
> > duration of disease?
> >
> > You haven't even mentioned what it is you are trying to predict.
> > Survival?
> >
> > The thing is, as soon as one puts something in "simple terms," it's
> > often wrong -- which is why Greg suggested taking a class or hiring
> > someone to help you.
> >
> > Anyway, I'm assuming you must know what regression is, otherwise you
> > wouldn't be looking to know how to do it. One way to perform linear
> > regression in R is using the "lm" function. Type ?lm at the R prompt
> > for help.
> >
> >
> >> I thought this forum is for help. now i know what the statistician
> >> in my dept
> >> does all day long
> >
> > It is for help -- you'll see it's quite active around here.
> >
> > It's *not* for soliciting other people to do your analysis for you,
> > which is how your email comes across. All of us have our own work to
> > do, but are here to help if you're stuck on something *in
> > particular* ... perhaps you can do a bit more legwork and rephrase
> > your question in a more meaningful way.
> >
> > -steve
> >
> > --
> > Steve Lianoglou
> > Graduate Student: Physiology, Biophysics and Systems Biology
> > Weill Medical College of Cornell University
> >
> > Contact Info: 
> > http://cbio.mskcc.org/~lianos/contact
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Regression-using-age-and-Duration-of-disease-as-a-continous-factors-tp24574133p24591056.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting gu

Re: [R] how to transform m/d/yyyy to yyyymmdd?

2009-07-21 Thread Gabor Grothendieck
Assuming that there are no duplicate dates,
try this using zoo and chron:

> Lines <- "12/9/2007 0
+ 12/16/2007 1
+ 1/1/2008 2
+ 1/3/2008 3
+ 1/12/2008 4"
>
> library(zoo)
> library(chron)
> z <- read.zoo(textConnection(Lines), FUN = chron)
> z # is automatically sorted by times
12/09/07 12/16/07 01/01/08 01/03/08 01/12/08
   01234
> plot(z)

See R News 4/1 for more about dates and see the
3 vignettes (pdf documents) in the zoo package for
manipulating time series with zoo.

On Tue, Jul 21, 2009 at 1:16 PM, liujb wrote:
>
> Hello,
>
> I have a set of data that has a Date column looks like this:
> 12/9/2007
> 12/16/2007
> 1/1/2008
> 1/3/2008
> 1/12/2008
> etc.
>
> I'd like the date to look something like the follow (so that I could sort by
> date easily).
> 20071209
> 20071216
> 20080101
> 20080103
> 20080112
>
> How to do it? Thank you very much
> Julia
> --
> View this message in context: 
> http://www.nabble.com/how-to-transform-m-d--to-mmdd--tp24591898p24591898.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how to transform m/d/yyyy to yyyymmdd?

2009-07-21 Thread John Kane

Why not convert them to dates? 

Assuming you are using that perverse Month/Day/Year format

x <- c("12/9/2007" ,"12/16/2007","1/1/2008","1/3/2008","1/12/2008")

xx <- as.Date(x, "%m/%d/%Y")
xx

--- On Tue, 7/21/09, liujb  wrote:

> From: liujb 
> Subject: [R]  how to transform m/d/ to mmdd?
> To: r-help@r-project.org
> Received: Tuesday, July 21, 2009, 1:16 PM
> 
> Hello,
> 
> I have a set of data that has a Date column looks like
> this:
> 12/9/2007
> 12/16/2007
> 1/1/2008
> 1/3/2008
> 1/12/2008
> etc.
> 
> I'd like the date to look something like the follow (so
> that I could sort by
> date easily).
> 20071209
> 20071216
> 20080101
> 20080103
> 20080112
> 
> How to do it? Thank you very much
> Julia
> -- 
> View this message in context: 
> http://www.nabble.com/how-to-transform-m-d--to-mmdd--tp24591898p24591898.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org
> mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Re gression using age and Duration of disease as a continous factors

2009-07-21 Thread Ben Bolker



1Rnwb wrote:
> 
> 
>  [snip]
> 
> The suggestion that consult the statistician is kind of funny as  the
> statistician in my center is my co-mentor and from past 5 years he is
> sitting on the data without any output. 
> 
> I am not here to ask someone to do my data analysis, but to get an
> understanding of the process as well as a proper direction to look for the
> analysis.  after all I do have to explain all these things to my boss as
> well. 
> 
> 

Does your co-mentor have any graduate students, postdocs, etc. who could
help you?  Anyone else in your group with more statistical knowledge? Are
there courses in regression offered at your institution? This really looks
like a large and potentially complicated question, and it could take hours
of someone's (unpaid) time to help you through it.  At least people
associated with your institution will (1) know the field [and hence be able
to spot potential pitfalls], (2) be physically present [communication is
easier/faster].  Postdocs or graduate students might be willing to help you
out for the price of beer or coffee, or out of interest -- or for
co-authorship on a manuscript, if it comes to that.  

  There are books on regression geared toward R by Julian Faraway and Frank
Harrell, among others.  If repeated samples are drawn from the same
individual you may also need to consult Pinheiro and Bates 2000.

  At the risk of offending you further:

> library(fortunes)
> fortune("brain")

I wish to perform brain surgery this afternoon at 4pm and don't know where
to
start. My background is the history of great statistician sports legends but
I
am willing to learn. I know there are courses and numerous books on brain
surgery but I don't have the time for those. Please direct me to the
appropriate HowTos, and be on standby for solving any problem I may
encounter
while in the operating room. Some of you might ask for specifics of the
case,
but that would require my following the posting guide and spending even more
time than I am already taking to write this note.
   -- I. Ben Fooled (aka Frank Harrell)
  R-help (April 1, 2005)

-- 
View this message in context: 
http://www.nabble.com/Regression-using-age-and-Duration-of-disease-as-a-continous-factors-tp24574133p24592482.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Searching for specific values in a matrix

2009-07-21 Thread Mehdi Khan
Hello all,

I have a seemingly simple question which I have searched for an answer for
for a few hours without luck.  I have a matrix of both values and characters
with thousands of rows.  I would like to run a search of this matrix for
certain values and would like the search to retrieve the entire row.  How
would I accomplish this?

Thanks!

Mehdi Khan

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how to transform m/d/yyyy to yyyymmdd?

2009-07-21 Thread Chuck Cleland
On 7/21/2009 1:16 PM, liujb wrote:
> Hello,
> 
> I have a set of data that has a Date column looks like this:
> 12/9/2007
> 12/16/2007
> 1/1/2008
> 1/3/2008
> 1/12/2008
> etc.
> 
> I'd like the date to look something like the follow (so that I could sort by
> date easily).
> 20071209
> 20071216
> 20080101
> 20080103
> 20080112
> 
> How to do it? Thank you very much
> Julia

dates <- c("2/27/1992", "2/27/1992", "1/14/1992",
   "2/28/1992", "2/1/1992")

as.character(as.Date(dates, "%m/%d/%Y"), "%Y%m%d")
[1] "19920227" "19920227" "19920114" "19920228" "19920201"

?as.Date

-- 
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how to transform m/d/yyyy to yyyymmdd?

2009-07-21 Thread Whit Armstrong
warmstr...@research:~$ R
> strptime("12/9/2007","%m/%d/%Y")
[1] "2007-12-09"
> format(strptime("12/9/2007","%m/%d/%Y"),"%Y%m%d")
[1] "20071209"
>



On Tue, Jul 21, 2009 at 1:16 PM, liujb wrote:
>
> Hello,
>
> I have a set of data that has a Date column looks like this:
> 12/9/2007
> 12/16/2007
> 1/1/2008
> 1/3/2008
> 1/12/2008
> etc.
>
> I'd like the date to look something like the follow (so that I could sort by
> date easily).
> 20071209
> 20071216
> 20080101
> 20080103
> 20080112
>
> How to do it? Thank you very much
> Julia
> --
> View this message in context: 
> http://www.nabble.com/how-to-transform-m-d--to-mmdd--tp24591898p24591898.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Re gression using age and Duration of disease as a continous factors

2009-07-21 Thread 1Rnwb

Thanks Steve,Thanks for the explanation,  I agree the question is too vague,
I do not what a regression is I have switched to R a couple of months ago,
after working in Excel for a long time.  I also know the lm, glm functions
in R. but due to my data I am completely lost.  it looks like the experts
individuals just come to poke fun at our expesense who has no background of
statistics. 

I have a 8 proteins and I have two groups with 840 samples in control and
1140 samples in diseases further stratified by sex, draw age, duration of
disease. all these groups and sub groups is making the thing very confusing
as how to do the regression in R. the pupose is to show the changes in the
levels of these proteins as the disease progress or changes in their levels
with respect to progression in age, effect of gender, SNPs for these
proteins, it is a pretty big dataset. 

The suggestion that consult the statistician is kind of funny as  the
statistician in my center is my co-mentor and from past 5 years he is
sitting on the data without any output. 

I am not here to ask someone to do my data analysis, but to get an
understanding of the process as well as a proper direction to look for the
analysis.  after all I do have to explain all these things to my boss as
well. 

Thanks



Steve Lianoglou-6 wrote:
> 
> 
> On Jul 20, 2009, at 5:30 PM, 1Rnwb wrote:
> 
>> I have read that multiple times without understanding anything.
> 
> If that's the case, then perhaps you should follow Greg's first piece  
> of advice:
> 
>> Greg Snow-2 wrote:
>>>
>>> If you need an explanation of what regression means, then you need  
>>> to take
>>> a course or 2 at your local university, or at least hire a  
>>> statistical
>>> consultant.
> 
> We're not trying to be rude, but your question is quite ill formed,  
> and no one can really help you:
> 
>> Please explain me as what it means and how this analysis can be done
>> using R and which library(ies) are needed.
> 
> It's not clear what you do/don't understand, and your problem  
> statement is too vague for anyone to tell you more.
> 
> It seems like you're saying you don't understand what "regression" is,  
> in which case a simple email will not help you.
> 
> "Simply put" regression is a method to predict a (typically)  
> "continuous" output by some combination of inputs, eg. predicting  
> someone's height by knowing their weight and shoe size (these are  
> continuous variables, too). It looks like in your case, your "inputs"  
> are the "continuous factors" of your email subject, which are age and  
> duration of disease?
> 
> You haven't even mentioned what it is you are trying to predict.  
> Survival?
> 
> The thing is, as soon as one puts something in "simple terms," it's  
> often wrong -- which is why Greg suggested taking a class or hiring  
> someone to help you.
> 
> Anyway, I'm assuming you must know what regression is, otherwise you  
> wouldn't be looking to know how to do it. One way to perform linear  
> regression in R is using the "lm" function. Type ?lm at the R prompt  
> for help.
> 
> 
>> I thought this forum is for help. now i know what the statistician  
>> in my dept
>> does all day long
> 
> It is for help -- you'll see it's quite active around here.
> 
> It's *not* for soliciting other people to do your analysis for you,  
> which is how your email comes across. All of us have our own work to  
> do, but are here to help if you're stuck on something *in  
> particular* ... perhaps you can do a bit more legwork and rephrase  
> your question in a more meaningful way.
> 
> -steve
> 
> --
> Steve Lianoglou
> Graduate Student: Physiology, Biophysics and Systems Biology
> Weill Medical College of Cornell University
> 
> Contact Info: http://cbio.mskcc.org/~lianos/contact
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Regression-using-age-and-Duration-of-disease-as-a-continous-factors-tp24574133p24591056.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] how to transform m/d/yyyy to yyyymmdd?

2009-07-21 Thread liujb

Hello,

I have a set of data that has a Date column looks like this:
12/9/2007
12/16/2007
1/1/2008
1/3/2008
1/12/2008
etc.

I'd like the date to look something like the follow (so that I could sort by
date easily).
20071209
20071216
20080101
20080103
20080112

How to do it? Thank you very much
Julia
-- 
View this message in context: 
http://www.nabble.com/how-to-transform-m-d--to-mmdd--tp24591898p24591898.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Histograms on a log scale

2009-07-21 Thread Lorenzo Isella

John Kane wrote:
How about using the ggplot2 package? Does this give you something along the lines of what you want?  
===

library(ggplot2)
r <- data.frame(rlnorm(1000))
names(r) <- "rr"

ggplot(r, aes(rr)) + geom_histogram()+ scale_x_log10() + scale_y_log10()

=

--- On Mon, 7/20/09, Lorenzo Isella  wrote:

  

From: Lorenzo Isella 
Subject: [R] Histograms on a log scale
To: r-help@r-project.org
Received: Monday, July 20, 2009, 5:17 AM
Dear All,
I would like to be able to plot histograms/densities on a
semi-log or log-log scale.
I found several suggestions online

http://tolstoy.newcastle.edu.au/R/help/05/09/12044.html
https://stat.ethz.ch/pipermail/r-help/2002-June/022295.html
http://www.harding.edu/fmccown/R/#histograms

Now, consider the code snippet taken from 
http://www.harding.edu/fmccown/R/#histograms

# Get a random log-normal distribution
r <- rlnorm(1000)

# Get the distribution without plotting it using tighter
breaks
h <- hist(r, plot=F, breaks=c(seq(0,max(r)+1, .1)))

# Plot the distribution using log scale on both axes, and
use
# blue points
plot(h$counts, log="xy", pch=20, col="blue",
   main="Log-normal distribution",
   xlab="Value", ylab="Frequency")

This is very close to what I need, but how can I have
filled rectangles in the plot, so that it looks more like a
traditional histogram?
Kind Regards

Lorenzo

__
R-help@r-project.org
mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained,
reproducible code.





  __
The new Internet Explorer® 8 - Faster, safer, easier.  Optimized for Yahoo!  
Get it Now for Free! at http://downloads.yahoo.com/ca/internetexplorer/
  

Hello,
And thanks for answering.
Well, I think I found what I wanted (maybe in a cumbersome way). ggplot2 
can probably do the same and a lot more, but perhaps it is like using a 
cannon to kill a bird.

See the code snippet at the end of the email.
Kind Regards

Lorenzo


rm(list=ls())

set.seed(1234)

my_seq <- rlnorm(1000)

log_binning <- function(x_min,x_max,n_breaks=10){
delta_log <- log(x_max/x_min)/(n_breaks-1)
my_seq<-seq(0,n_breaks-1)
log_breaks <- x_min*exp(my_seq*delta_log)
}

freq <- table(my_seq)

n_bins <- 20

my_breaks2 <- log_binning(min(my_seq), max(my_seq), n_bins) #this 
creates a log-spaced bin structure
h2 <- hist(my_seq, plot=F, my_breaks2) #this creates a histogram but 
does not plot it.


pdf("histogram_lognormal.pdf")
par( mar = c(4.5,5, 2, 1) + 0.1)
i <- seq(1,(length(h2$breaks)-1)) #this counts the rectangles I am about 
to generate


plot(h2$mids, h2$counts, col="blue",ylab="Frequency", log="x",
,cex.axis=1.4,cex.lab=1.6, xlab="Value of Random Number", main="")
rect(h2$breaks[i], 0, h2$breaks[i+1],h2$count )#this generates a set of 
rectangles which are useful to visualize the underlying

#bin structure
dev.off()

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Re gression using age and Duration of disease as a continous factors

2009-07-21 Thread Greg Snow
If you truly did not understand anything in "An Introduction to R" section 11, 
then you are unlikely to understand anything that we would write in a post 
without getting some more background understanding (that is why I suggested 
that you take a class or hire a consultant).

There are many people on this list that give quite a bit of help every day, but 
the word 'help' in R-help means to give hints, or assist with when you do your 
part, or discuss and give insight.  It does not mean that we will do your work 
for you.

You are making it difficult for us to help you.  I for one am horrible at mind 
reading (just ask my wife).

Given the information in your original question, the answer may be:

> fit <- lm(Duration ~ age, data=disease)
> summary(fit)

But the above could also be completely useless, or give an error, or based on 
if some assumptions don't hold, the above could be worse than useless by giving 
results that are completely wrong but look good and lead you in the wrong 
direction.
If you try the above code and come back with only a statement about it not 
working or not understanding the output without any detail, then my sole 
response will be "I told you so!".

But if you can give us some detail on the background of your question, what 
question you are trying to answer, what you data looks like, and what your 
education/understanding is, then we may be able to help.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of 1Rnwb
> Sent: Monday, July 20, 2009 3:31 PM
> To: r-help@r-project.org
> Subject: Re: [R] Re gression using age and Duration of disease as a
> continous factors
> 
> 
> I have read that multiple times without understanding anything.
> 
> Greg Snow-2 wrote:
> >
> > If you need an explanation of what regression means, then you need to
> take
> > a course or 2 at your local university, or at least hire a
> statistical
> > consultant.
> >
> > If you understand regression and just need the explanation of how to
> do it
> > using R, then read section 11 (as well as everything else) of "An
> > Introduction to R".
> >
> > --
> > Gregory (Greg) L. Snow Ph.D.
> > Statistical Data Center
> > Intermountain Healthcare
> > greg.s...@imail.org
> > 801.408.8111
> >
> >
> >> -Original Message-
> >> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> >> project.org] On Behalf Of 1Rnwb
> >> Sent: Monday, July 20, 2009 11:30 AM
> >> To: r-help@r-project.org
> >> Subject: [R] Re gression using age and Duration of disease as a
> >> continous factors
> >>
> >>
> >> Please explain me as what it means and how this analysis can be done
> >> using R
> >> and which library(ies) are needed.
> >> Thanks
> >>
> >> --
> >> View this message in context: http://www.nabble.com/Regression-
> using-
> >> age-and-Duration-of-disease-as-a-continous-factors-
> >> tp24574133p24574133.html
> >> Sent from the R help mailing list archive at Nabble.com.
> >>
> >> __
> >> R-help@r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide http://www.R-project.org/posting-
> >> guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
> >
> 
> --
> View this message in context: http://www.nabble.com/Regression-using-
> age-and-Duration-of-disease-as-a-continous-factors-
> tp24574133p24577937.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Select value according two vectors...

2009-07-21 Thread Dieter Menne



Steve Lianoglou-6 wrote:
> 
> 
> On Jul 21, 2009, at 11:28 AM, Dieter Menne wrote:
> 
> Or, more simply:
> 
> R> a <- c(0., 0.0909, 0.0909, 0.1818, 0.2727, 0.3636, 0.4545,  
> 0.6363, 0., 0., 0., 0.000)
> R> b <- c(3, 5, 7, 18, 43, 85, 91, 98, 100, 130, 230, 487)
> R> b[a > .5]
> [1] 98
> 
> 

No, that's why I changed the values in a: when there are more than one >
0.5. 

Dieter

-- 
View this message in context: 
http://www.nabble.com/Select-value-according-two-vectors...-tp24589588p24591618.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] animated grid graphics

2009-07-21 Thread hadley wickham
> Drawing grid graphics always takes long, I would write the images to png's
> and make the animation. If you use Linux I can suggest some nice tools to do
> this. This movie is also much more compatible with all kinds of machines. It
> might be that you can get your grid animation working on your own computer,
> but if another user has a less powerfull machine he might not have a smooth
> animation.

If you're brave, another approach is to use one of the new graphics
systems, iplots extreme or qtpaint, tailored for high speed drawing.
Unfortunately neither system is ready for prime time (i.e. no
documentation) but they both offer tantalising glimpses of
fantastically quick animation inside R.

Hadley

-- 
http://had.co.nz/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] list of lm() results

2009-07-21 Thread Greg Snow
First make sure that myResults is a list (you probably did this, but just to be 
sure):

> myResults <- list()

Then use doubled brackets [[]]:

> myResults[[1]] <- lm(...)
Etc.

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Idgarad
> Sent: Tuesday, July 21, 2009 10:28 AM
> To: r-help@r-project.org
> Subject: [R] list of lm() results
> 
> How can I get the results of lm() into a list so I can loop through the
> results?
> 
> e.g.
> 
> myResults[1] <- lm(...)
> myResults[2] <- lm(...)
> myResults[3] <- lm(...)
> ...
> myResults[15] <- lm(...)
> myResults[16] <- lm(...)
> 
> so far every attempt I've tried doesn't work throwing a "number of
> items to replace is not a multiple of replacement length" error or
> simply not working.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] subscript into matrix discards row/column names

2009-07-21 Thread Henrique Dallazuanna
Try this:

x[1,, drop = FALSE]


On Tue, Jul 21, 2009 at 1:46 PM, Vadim Ogranovich <
vogranov...@jumptrading.com> wrote:

> Dear R-help,
>
> When the result of a matrix subscription degenerates to a scalar the names
> implied by the dimnames are discarded.
>
> > x <- matrix(0, 1, 1, dimnames=list('a', 'x'))
>
> ## below I expected result to have names='x', it's not
> > x[1,]
> [1] 0
>
> ## below I expected result to have names='a', it's not
> > x[,1]
> [1] 0
>
> This is probably a side effect of 'drop' applied to a 1*1 matrix, is there
> an elegant way around?
>
> One possibility could be to allow the 'drop' arg in '[' to take numerical
> values (in addition to bool), which would be interpreted as dimensions to
> drop.
>
> Thanks,
> Vadim
>
> Note: This email is for the confidential use of the named addressee(s) only
> and may contain proprietary, confidential or privileged information. If you
> are not the intended recipient, you are hereby notified that any review,
> dissemination or copying of this email is strictly prohibited, and to please
> notify the sender immediately and destroy this email and any attachments.
>  Email transmission cannot be guaranteed to be secure or error-free.  Jump
> Trading, therefore, does not make any guarantees as to the completeness or
> accuracy of this email or any attachments.  This email is for informational
> purposes only and does not constitute a recommendation, offer, request or
> solicitation of any kind to buy, sell, subscribe, redeem or perform any type
> of transaction of a financial product.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] list of lm() results

2009-07-21 Thread David Winsemius


On Jul 21, 2009, at 12:27 PM, Idgarad wrote:

How can I get the results of lm() into a list so I can loop through  
the results?


e.g.

myResults[1] <- lm(...)
myResults[2] <- lm(...)
myResults[3] <- lm(...)
...
myResults[15] <- lm(...)
myResults[16] <- lm(...)

so far every attempt I've tried doesn't work throwing a "number of
items to replace is not a multiple of replacement length" error or
simply not working.


?"[["

You are trying to use a vector/array  assignment operator, "[<- ",   
when you should be using a list assignment operator, "[[<-".



David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] subscript into matrix discards row/column names

2009-07-21 Thread Vadim Ogranovich
Dear R-help,

When the result of a matrix subscription degenerates to a scalar the names 
implied by the dimnames are discarded.

> x <- matrix(0, 1, 1, dimnames=list('a', 'x'))

## below I expected result to have names='x', it's not
> x[1,]
[1] 0

## below I expected result to have names='a', it's not
> x[,1]
[1] 0

This is probably a side effect of 'drop' applied to a 1*1 matrix, is there an 
elegant way around?

One possibility could be to allow the 'drop' arg in '[' to take numerical 
values (in addition to bool), which would be interpreted as dimensions to drop.

Thanks,
Vadim

Note: This email is for the confidential use of the named addressee(s) only and 
may contain proprietary, confidential or privileged information. If you are not 
the intended recipient, you are hereby notified that any review, dissemination 
or copying of this email is strictly prohibited, and to please notify the 
sender immediately and destroy this email and any attachments.  Email 
transmission cannot be guaranteed to be secure or error-free.  Jump Trading, 
therefore, does not make any guarantees as to the completeness or accuracy of 
this email or any attachments.  This email is for informational purposes only 
and does not constitute a recommendation, offer, request or solicitation of any 
kind to buy, sell, subscribe, redeem or perform any type of transaction of a 
financial product.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] list of lm() results

2009-07-21 Thread S Ellison
You could look at ?lmList in package lme ...



>>> Idgarad  21/07/2009 17:27:52 >>>
How can I get the results of lm() into a list so I can loop through the
results?

e.g.

myResults[1] <- lm(...)
myResults[2] <- lm(...)
myResults[3] <- lm(...)
...
myResults[15] <- lm(...)
myResults[16] <- lm(...)

so far every attempt I've tried doesn't work throwing a "number of
items to replace is not a multiple of replacement length" error or
simply not working.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html 
and provide commented, minimal, self-contained, reproducible code.

***
This email and any attachments are confidential. Any use...{{dropped:8}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how to change the "quantile" method in bwplot

2009-07-21 Thread Matthias Kohl

for teaching purposes I wrote a corresponding function; cf.
qbxp.stats (as well as qboxplot ...) in package MKmisc.

hth,
Matthias

Deepayan Sarkar schrieb:

On Tue, Jul 21, 2009 at 7:47 AM, Jun Shen wrote:
  

Uwe,

Thank you for your reply.  I am still not very clear about the meanings of
the arguments in the stats function.   To make it clearer, quantile() uses
type=7 as default method. I believe this is the method bwplot() uses to
calculate the quantiles. I want to use type=6 method for bwplot(). How do I
achieve that? Thanks again.



Maybe this will be clearer: bwplot() uses the boxplot.stats() function
to compute the "quantiles" used, which in turn uses fivenum(), which
has its own quantile calculation (and does not explicitly use
quantile()). There is no easy way to allow for type=6 etc. here.

bwplot() allows you to replace boxplot.stats() and provide your own
alternative. So what you need to do is:

(1) write a function, say, 'my.boxpot.stats', that takes the same
arguments as boxplot.stats() and returns a similar result, but using
your preferred calculation for the quantiles. There are many ways to
do this.

(2) plug in this function into the bwplot() call; e.g. bwplot(...,
stats = my.boxplot.stats)

-Deepayan


  

Jun

2009/7/21 Uwe Ligges 



Jun Shen wrote:

  

Hi, everyone,

Since quantile calculation has nine different methods in R, I wonder how I
specify a method when calling the bwplot() in lattice. I couldn't find any
information in the documentation. Thanks.




bwplot() uses the panel function panel.bwplot() which allows to specify a
function that calculates the statistics in its argument stats that defaults
to boxplot.stats(). Hence you can change that function.

Example with some fixed values:

bwplot( ~ 1:10,
   stats = function(x, ...)
   return(list(stats=1:5, n=10, conf=1, 10, out=integer(0)))
)


Uwe Ligges

  

   [[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
  


--
Dr. Matthias Kohl
www.stamats.de

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Background colour of axis

2009-07-21 Thread Greg Snow
Look at the xpd argument to the par function.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Miguel Lacerda
> Sent: Tuesday, July 21, 2009 8:21 AM
> To: r-help@r-project.org
> Subject: [R] Background colour of axis
> 
> Hi,
> 
> I would like to be able to shade the background of part of an axis. To
> illustrate, consider the following code:
> 
> par(xaxt="n")
> x=1:10
> y=rnorm(10,0,1)
> plot(x,y,type="l",xlab=NA)
> mtext(text=LETTERS[1:10], side=1, at=1:10)
> 
> How can I make the background behind, say, "G H I" on the x-axis red? I
> have
> tried using "polygon," but cannot seem to get it to plot outside the
> graph
> borders.
> 
> Any suggestions?
> 
> Miguel
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Calling R functions from multiple threads

2009-07-21 Thread David Haykazyan
Hi,

 

I am embedding R into a C++ application. Is it possible to call R functions
from different threads? If yes, should I call Rf_initEmbeddedR once or for
each thread separately? I know that R is not thread safe and making sure
that no simultaneous calls from different threads happen. Now I am working
under Windows though I want it to be workable under Linux too.

 

Regards,

David Haykazyan

OneMarketData LLC.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] list of lm() results

2009-07-21 Thread Idgarad
How can I get the results of lm() into a list so I can loop through the results?

e.g.

myResults[1] <- lm(...)
myResults[2] <- lm(...)
myResults[3] <- lm(...)
...
myResults[15] <- lm(...)
myResults[16] <- lm(...)

so far every attempt I've tried doesn't work throwing a "number of
items to replace is not a multiple of replacement length" error or
simply not working.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] animated grid graphics

2009-07-21 Thread Greg Snow
Imagemagick and gimp work on windows, linux, and mac as well and have tools for 
creating animated gifs (and possibly other animation files).

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Allan Engelhardt
> Sent: Tuesday, July 21, 2009 7:13 AM
> To: Paul Hiemstra
> Cc: r-help@r-project.org
> Subject: Re: [R] animated grid graphics
> 
> On 21/07/09 14:00, Paul Hiemstra wrote:
> > Hi,
> >
> > Drawing grid graphics always takes long, I would write the images to
> > png's and make the animation. If you use Linux I can suggest some
> nice
> > tools to do this.
> 
> Please do suggest!  I was thinking about a similar problem.
> 
> Allan.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


  1   2   >