[R] Programmatically give file name to a matrix

2013-01-30 Thread Kumar Mainali
I have a situation when I need to save matrix with file names that are
programmatically created.

for (i in levels(mergeTrn$Continent)) {
matrix here

# I want to save this matrix with a file name that carries i from for
loop. The following does not work.
paste(plotroc_GBM_Trn_, i, sep=) - matrix

}

Thanks,
Kumar

-- 
Section of Integrative Biology
University of Texas at Austin
Austin, Texas 78712, USA

[[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] Add axes to a 3D scene (afer makeTriangles)

2013-01-30 Thread cgenolin
Hi all,

I am drawing some 3D surfaces using the Triangle tools (package misc3) and
drawScene.rgl. Do you know if it is possible to add axes and graduation on
the scene?

Christophe



--
View this message in context: 
http://r.789695.n4.nabble.com/Add-axes-to-a-3D-scene-afer-makeTriangles-tp4657025.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] Programmatically give file name to a matrix

2013-01-30 Thread Pascal Oettli

Hello,

?assign

assign(paste(plotroc_GBM_Trn_, i, sep=), matrix(rnorm(100),10,10))

HTH,
Pascal


Le 30/01/2013 17:04, Kumar Mainali a écrit :

I have a situation when I need to save matrix with file names that are
programmatically created.

for (i in levels(mergeTrn$Continent)) {
 matrix here

# I want to save this matrix with a file name that carries i from for
loop. The following does not work.
paste(plotroc_GBM_Trn_, i, sep=) - matrix

}

Thanks,
Kumar



__
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] Creating dummy variables in r

2013-01-30 Thread peter dalgaard

On Jan 30, 2013, at 04:58 , Bert Gunter wrote:

 You almost never need dummy variables in R. R creates them
 automatically from factors given model and possibly contrasts
 specification.
 
 ?contrasts  ## for some technical details.
 
 If you have not read An Introduction to R do so now. Pay particular
 attention to the chapter on modeling and categorical variables. You
 can also google around to find appropriate tutorials. Here is one:
 
 http://www.ats.ucla.edu/stat/r/modules/dummy_vars.htm
 
 I repeat: DO not create dummy variablesby hand in R unless you have
 understood the above and have good reason to do so.

In this case it's a cutpoint-type situation, and the user might be excused for 
not wanting to deal with the mysteries of cut() (yet). 

More importantly, the main issue here seems to be a lack of understanding of 
where new variables are located. I.e., if the data set is called dd, you need

dd$prev1 - (etc)

and if you use attach(), do it _after_ modifying the data (or detach() and 
reattach).

Otherwise, new variables end up in the global environment. (This is logical 
enough once you realize that the result of a computation does not necessarily 
fit into the dataset.)

By the way: You don't need ifelse(): as.numeric(ret1 = .5) or even just (ret1 
= .5) works. 

 
 -- Bert
 
 On Tue, Jan 29, 2013 at 7:21 PM, Joseph Norman Thomson
 thoms...@email.arizona.edu wrote:
 Hello,
 
 Semi-new r user here and still learning the ropes. I am creating dummy
 variables for a dataset on stock prices in r. One dummy variable is
 called prev1 and is:
 
 prev1 - ifelse(ret1 = .5, 1, 0)
 
 where ret1 is the previous day's return.
 
 The variable prev1 is created fine and works in my regression model
 and for running conditional statistics. However, when I call the
 names() function on the dataset the freshly created variable (prev1)
 doesn't show up; also, when I export the dataset the prev1 variable
 doesn't show up in the exported file. Is there a way to make the
 variable show up on both the call function but more importantly on the
 exported file? Or am I forced to create dummy variables elsewhere(much
 tougher)?
 
 
 Thanks,
 
 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.
 
 
 
 -- 
 
 Bert Gunter
 Genentech Nonclinical Biostatistics
 
 Internal Contact Info:
 Phone: 467-7374
 Website:
 http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
 
 __
 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.

-- 
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@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] problem wih plotrix:cluster.overplot

2013-01-30 Thread Jim Lemon

On 01/29/2013 06:53 PM, Jean Véronis wrote:

Hello,

I am trying to use cluster.overplot from package plotrix and I get an error message when 
I add the away parameter:

require(plotrix)
distance- read.table(distance.txt)
cmd- cmdscale(distance)
cp- cluster.overplot(cmd, away=2)

Error in if (sum(overplots)  1) { :
   missing value where TRUE/FALSE needed

If I don't use away, everything works fine.
I don't see anything in the documentation that explains this error.
Any help will be appreciated.


Hi Jean,
The away argument needs to have both an x and y distance to offset the 
points. Try:


cp-cluster.overplot(cmd,away=c(2,2))

I'll add this to the docs, 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.


[R] Relative Risk in logistic regression

2013-01-30 Thread aminreza Aamini
Hi all,
I am very grateful to all those who write to me
1) how i  can  obtain relative risk (risk ratio) in logistic regression in R.
2) how to obtain  the predicted risk for a certain individual using
fitted regression model in R.

Many thanks, in advance, for your help.
Amin.

__
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] Arima model estimated by Maximum likelihood conditional on a zero initial residual

2013-01-30 Thread ghjf fghjk
Hello,
I would like to estimate Arima model by Maximum likelihood conditional on a
zero initial residual.
I am using:
model - arima(y[1:N], order=c(1, 0, 1), method=ML, include.mean=TRUE)
model


What I have to use to estimate arima model by Maximum likelihood
conditional on a zero initial residual? Important is conditional on a zero
initial residual.

Thank you.

[[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] substring from behind

2013-01-30 Thread Mat
Hello together,

i have a question for substring.
I know i can filter a number like this one:
bill$No-substring(bill$Customer,2,4)

in this case i get the 2nd, 3rd and 4th number of my Customer ID.
But how can i do this, if i want the 2nd, 3rd and 4th number of a column.

Like this one.
I have: Mercedes_02352
Audi_03555
and now i want to filter this data.frame to
235
355

can you help me?

Thanks.

Mat



--
View this message in context: 
http://r.789695.n4.nabble.com/substring-from-behind-tp4657029.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] problem wih plotrix:cluster.overplot

2013-01-30 Thread Jean Véronis
great! many thanks!
Le 30 janv. 2013 à 09:52, Jim Lemon j...@bitwrit.com.au a écrit :

 On 01/29/2013 06:53 PM, Jean Véronis wrote:
 Hello,
 
 I am trying to use cluster.overplot from package plotrix and I get an error 
 message when I add the away parameter:
 
 require(plotrix)
 distance- read.table(distance.txt)
 cmd- cmdscale(distance)
 cp- cluster.overplot(cmd, away=2)
 
 Error in if (sum(overplots)  1) { :
   missing value where TRUE/FALSE needed
 
 If I don't use away, everything works fine.
 I don't see anything in the documentation that explains this error.
 Any help will be appreciated.
 
 Hi Jean,
 The away argument needs to have both an x and y distance to offset the 
 points. Try:
 
 cp-cluster.overplot(cmd,away=c(2,2))
 
 I'll add this to the docs, 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] substring from behind

2013-01-30 Thread Jorge I Velez
Hi Mat,

The following should get you started:

 s - Mercedes_02352
 substr(s, nchar(s) - 3, nchar(s) - 1)
[1] 235


 # defining a function
 foo - function(x, a = 3, b = 1) substr(s, nchar(x) - a, nchar(x) - b)
 foo(s)
[1] 235

HTH,
Jorge.-


On Wed, Jan 30, 2013 at 8:05 PM, Mat  wrote:

 Hello together,

 i have a question for substring.
 I know i can filter a number like this one:
 bill$No-substring(bill$Customer,2,4)

 in this case i get the 2nd, 3rd and 4th number of my Customer ID.
 But how can i do this, if i want the 2nd, 3rd and 4th number of a column.

 Like this one.
 I have: Mercedes_02352
 Audi_03555
 and now i want to filter this data.frame to
 235
 355

 can you help me?

 Thanks.

 Mat



 --
 View this message in context:
 http://r.789695.n4.nabble.com/substring-from-behind-tp4657029.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.


[[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] recoding variables again :(

2013-01-30 Thread David Studer
Hello everybody!

I have again a rather simple question concerning recoding of variables:

I have a variable/data-frame column BIRTHPLACE containing abbreviations of
the 26 swiss counties (AG, AI, AR, BE, ZH, ... )
as well as international country codes (USA, GER, ESP, etc.) and another
variable RES_STA indicating the
residence status (A, B, C, X, Y)

My goal is now to create a new variable VARNEW under the following
conditions:

   - should be the RESIDENCE_STATUS
   - except:
  - if RESIDENCE_STATUS is X and at the same time BIRTHPLACE is one of
  the 26
  swiss counties then it should be swiss
  - otherweise it should be unknown


I have already tried the following code:
mydata$VARNEW-mydata$RESIDENCE_STATUS  # setting VARNEW as
RESIDENCE_STATUS

idx-(mydata$RESIDENCE_STATUS==X  !(# TRUE: unknown; FALSE:
swiss
 mydata$BIRTHPLACE==AG |
 mydata$BIRTHPLACE==BE |
 mydata$BIRTHPLACE==AR
 ...
 )
)

and then?

Thank you for any help!

David

[[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] recoding variables again :(

2013-01-30 Thread Jorge I Velez
Hi David,

Check

?%in%

for a simpler approach.

Regards,
Jorge.-


On Wed, Jan 30, 2013 at 8:42 PM, David Studer  wrote:

 Hello everybody!

 I have again a rather simple question concerning recoding of variables:

 I have a variable/data-frame column BIRTHPLACE containing abbreviations of
 the 26 swiss counties (AG, AI, AR, BE, ZH, ... )
 as well as international country codes (USA, GER, ESP, etc.) and another
 variable RES_STA indicating the
 residence status (A, B, C, X, Y)

 My goal is now to create a new variable VARNEW under the following
 conditions:

- should be the RESIDENCE_STATUS
- except:
   - if RESIDENCE_STATUS is X and at the same time BIRTHPLACE is one of
   the 26
   swiss counties then it should be swiss
   - otherweise it should be unknown


 I have already tried the following code:
 mydata$VARNEW-mydata$RESIDENCE_STATUS  # setting VARNEW as
 RESIDENCE_STATUS

 idx-(mydata$RESIDENCE_STATUS==X  !(# TRUE: unknown; FALSE:
 swiss
  mydata$BIRTHPLACE==AG |
  mydata$BIRTHPLACE==BE |
  mydata$BIRTHPLACE==AR
  ...
  )
 )

 and then?

 Thank you for any help!

 David

 [[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.


[R] Fwd:

2013-01-30 Thread CALEF ALEJANDRO
http://www.consultadifesapdl.it/6cmpqy.php

__
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] Relative Risk in logistic regression

2013-01-30 Thread aminreza Aamini
Hi all,
I am very grateful to all those who write to me
1) how i  can  obtain relative risk (risk ratio) in logistic regression in R.
2) how to obtain  the predicted risk for a certain individual using
fitted regression model in R.

Many thanks, in advance, for your help.

Amin.

__
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] Netcdf and Raster Package Questions, Need .asc File for GIS

2013-01-30 Thread Roger Bivand
Douglas M. Hultstrand dmhultst at metstat.com writes:

 
 Hello R-Group,
 
 I am new working with netcdf files and the raster package in R.I am 
 trying to read in a netcdf file using the package ncdf.I am able to 
 get the lat, lon and parameter I need and can plot using 
 fill.contour.

Please post on R-sig-geo, where the raster developers often handle questions
like this.

Roger

__
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] recoding variables again :(

2013-01-30 Thread arun
Hi,


set.seed(125)
dat1-data.frame(BIRTHPLACE=sample(c(AG,AI,AR,BE,ZH,USA,GER,ESP),20,replace=TRUE),RES_STA=sample(LETTERS[c(1:3,24:25)],20,replace=TRUE))
dat1$VARNEW-ifelse(dat1$RES_STA==X  
dat1$BIRTHPLACE%in%c(AG,AI,AR,BE,ZH),swiss,unknown)
A.K.



- Original Message -
From: David Studer stude...@gmail.com
To: r-help@r-project.org
Cc: 
Sent: Wednesday, January 30, 2013 4:42 AM
Subject: [R] recoding variables again :(

Hello everybody!

I have again a rather simple question concerning recoding of variables:

I have a variable/data-frame column BIRTHPLACE containing abbreviations of
the 26 swiss counties (AG, AI, AR, BE, ZH, ... )
as well as international country codes (USA, GER, ESP, etc.) and another
variable RES_STA indicating the
residence status (A, B, C, X, Y)

My goal is now to create a new variable VARNEW under the following
conditions:

   - should be the RESIDENCE_STATUS
   - except:
      - if RESIDENCE_STATUS is X and at the same time BIRTHPLACE is one of
      the 26
      swiss counties then it should be swiss
      - otherweise it should be unknown


I have already tried the following code:
mydata$VARNEW-mydata$RESIDENCE_STATUS          # setting VARNEW as
RESIDENCE_STATUS

idx-(mydata$RESIDENCE_STATUS==X  !(        # TRUE: unknown; FALSE:
swiss
mydata$BIRTHPLACE==AG |
mydata$BIRTHPLACE==BE |
mydata$BIRTHPLACE==AR
...
)
)

and then?

Thank you for any help!

David

    [[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] I think you misunderstood my explantation.

2013-01-30 Thread arun
Hi,

Your dataset had already some missing values.  So, I need to subset only those 
rows that are not missing.
!is.na(temp$ACTIVE_KWH)
# [1]  TRUE  TRUE  TRUE FALSE  TRUE FALSE FALSE  TRUE  TRUE  TRUE  TRUE FALSE
#[13]  TRUE  TRUE  TRUE
temp$ACTIVE_KWH[!is.na(temp$ACTIVE_KWH)]
#[1] 1201.9 1202.2 1202.8 1203.9   12.0 1206.0 1206.3 1206.5 1207.3 1207.9
#[11] 1208.4

?diff() will get the differences between successive values
diff(temp$ACTIVE_KWH[!is.na(temp$ACTIVE_KWH)])
 #[1] 0.3 0.6 1.1 -1191.9  1194.0 0.3 0.2 0.8 0.6
#[10] 0.5

#Here, the length is 1 less than the previous case as the first value is 
removed.
 diff(temp$ACTIVE_KWH[!is.na(temp$ACTIVE_KWH)])0
# [1] FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE

#Added `FALSE` at the beginning to make the length equal to subset data
indx- c(FALSE,diff(temp$ACTIVE_KWH[!is.na(temp$ACTIVE_KWH)])0)
indx 
#[1] FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE

#Using this index, further subset the already subset data for differences of 
values 0
 temp$ACTIVE_KWH[!is.na(temp$ACTIVE_KWH)][indx]
#[1] 12
temp$ACTIVE_KWH[!is.na(temp$ACTIVE_KWH)][indx]- NA #changed to NA

#Similarly for REACTIVE_KWH
Hope this helps.
A.K.










From: 남윤주 jamansymp...@naver.com
To: arun smartpink...@yahoo.com 
Sent: Wednesday, January 30, 2013 12:51 AM
Subject: Re: I think you misunderstood my explantation.


Oh, I forgot to ask about those code.
Can u expain what dose that mean?

Using the first dataset temp:
temp$ACTIVE_KWH[!is.na(temp$ACTIVE_KWH)][c(FALSE,diff(temp$ACTIVE_KWH[!is.na(temp$ACTIVE_KWH)])
 0)]-NA
temp$REACTIVE_KWH[!is.na(temp$REACTIVE_KWH)][c(FALSE,diff(temp$REACTIVE_KWH[!is.na(temp$REACTIVE_KWH)])
 0)]-NA 
-Original Message-
From: arunsmartpink...@yahoo.com 
To: 남윤주jamansymp...@naver.com; 
Cc: R helpr-help@r-project.org; 
Sent: 2013-01-30 (수) 10:37:18
Subject: Re: I think you misunderstood my explantation.

Hi,
Sorry, I didn't check your codes previously.

I hope this works for you (especially the 0).
Using the first dataset temp:
temp$ACTIVE_KWH[!is.na(temp$ACTIVE_KWH)][c(FALSE,diff(temp$ACTIVE_KWH[!is.na(temp$ACTIVE_KWH)])
 0)]-NA
temp$REACTIVE_KWH[!is.na(temp$REACTIVE_KWH)][c(FALSE,diff(temp$REACTIVE_KWH[!is.na(temp$REACTIVE_KWH)])
 0)]-NA
temp
#  ID    CTIME ACTIVE_KWH REACTIVE_KWH
#1  HM001 201212121301 1201.9   1115.5
#2  HM001 201212121302 1202.2   1115.8
#3  HM001 201212121303 1202.8   1115.8
#4  HM001 201212121304 NA   1116.1
#5  HM001 201212121305 1203.9   1116.7
#6  HM001 201212121306 NA   1116.7
#7  HM001 201212121307 NA   1116.7
#8  HM001 201212121308 NA   NA
#9  HM001 201212121309 1206.0   1118.2
#10 HM001 201212121310 1206.3   1118.6
#11 HM001 201212121311 1206.5   1118.8
#12 HM001 201212121312 NA   NA
#13 HM001 201212121313 1207.3   NA
#14 HM001 201212121314 1207.9   1121.1
#15 HM001 201212121315 1208.4   1121.3
temp1$ACTIVE_KWH[!is.na(temp1$ACTIVE_KWH)][c(FALSE,diff(temp1$ACTIVE_KWH[!is.na(temp1$ACTIVE_KWH)])
 0)]-NA

#Similarly with the second dataset:
temp1$ACTIVE_KWH[!is.na(temp1$ACTIVE_KWH)][c(FALSE,diff(temp1$ACTIVE_KWH[!is.na(temp1$ACTIVE_KWH)])
 0)]-NA
temp1$REACTIVE_KWH[!is.na(temp1$REACTIVE_KWH)][c(FALSE,diff(temp1$REACTIVE_KWH[!is.na(temp1$REACTIVE_KWH)])
 0)]-NA


A.K.







From: 남윤주 jamansymptom@naver.com
To: arun smartpink111@yahoo.com 
Sent: Tuesday, January 29, 2013 7:42 PM
Subject: I think you misunderstood my explantation.


Hi,

Assume that first CTIME value is '20120101'. It means ACTIVE_KWH measured 
from  '20120101' to present.
show example below row.

1  HM001 201212121301 1201.9 1115.5

1 row's  ACTIVE_KWH   accumulated value that measured from '20120101' to 
'201212121301'.
when CTIME is '201212121301',  ACTIVE_KWH  is '1201.9'.  And, when  CTIME is  
'201212121302', ACTIVE_KWH  is '1202.2'.
It means that 0.3 is measured during 1 minute.  And  ACTIVE_KWH  is a 
accumulated value.
Thus, ACTIVE_KWH  must increase, as CTIME  increases.
You got it?  So, I have to define strange value as subtraction value like ( 
temp$ACTIVE_KWH[i] -  temp$ACTIVE_KWH[i-1])  50). '50' can be chagned.
-
 for(i in 2:m){
 temp$ACTIVE_KWH[i]- ifelse(temp$ACTIVE_KWH[i]- temp$ACTIVE_KWH[i-1]0,NA, 
temp$ACTIVE_KWH[i])
}
--
But, in this case,  critical error occured. If  temp$ACTIVE_KWH[3] is NA, 
posterior data (temp$ACTIVE_KWH[4], [5], [6]...)  is imputed as NA.
Last mail contains Detailed source code and result. 
Can you recommend better idea to avoid imputed dataset as a successive NA. 
-Original Message-
From: arunsmartpink111@yahoo.com 
To: 남윤주jamansymptom@naver.com; 
Cc: R helpr-help@r-project.org; 
Sent: 

Re: [R] Fastest way to compare a single value with all values in one column of a data frame

2013-01-30 Thread nalluri pratap
Hi Dimitri,
 
Does this help?
 
k1-data.frame(item=sample(rep(letters),10,replace=T),a=c(1:10),b=11:20)
k2-data.frame(item=f,a=3,b=10)
merge-function(y,x)
{
if(y$amin(x$a))
{
  x-rbind(x,y)
  x-x[-which.min(x$a),]
}
return(x)
}
merge(k2,k1)
 
or much faster way would be to refer library(sqldf).

--- On Wed, 30/1/13, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com 
wrote:


From: Dimitri Liakhovitski dimitri.liakhovit...@gmail.com
Subject: [R] Fastest way to compare a single value with all values in one 
column of a data frame
To: r-help r-help@r-project.org
Date: Wednesday, 30 January, 2013, 2:41 AM


Hello!

I have a large data frame x:
x-data.frame(item=letters[1:5],a=1:5,b=11:15)  # in actuality, x has 1000
rows
x$item-as.character(x$item)
I also have a small data frame y with just 1 row:
y-data.frame(item=f,a=3,b=10)
y$item-as.character(y$item)

I have to decide if y$a is larger than the smallest of all the values in
x$a. If it is, I want y to replace the whole row in x that has the lowest
value in column a.
This is how I'd do it.

if(y$amin(x$a)){
  whichmin-which(x$a==min(x$a))
  x[whichmin,]-y[1,]
}


I am wondering if there is a faster way of doing it. What would be the
fastest possible way? I'd have to do it, unfortunately, many-many times.

Thank you very much!

-- 
Dimitri Liakhovitski
gfk.com http://marketfusionanalytics.com/

    [[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] Integration of mixed normal distribution

2013-01-30 Thread Rui Barradas

Hello,

You could do something like the following.


fun - function(x, mean, sd1, sd2, p)
dnorm(x, mean, sd1)*p + dnorm(x, mean, sd2)*(1 - p)

fun2 - function(x1, x2, mean, sd1, sd2, p){
p1 - pnorm(x2, mean, sd1) - pnorm(x1, mean, sd1)
p2 - pnorm(x2, mean, sd2) - pnorm(x1, mean, sd2)
p1*p + p2*(1 - p)
}

integrate(fun, 0, 1, mean = 0, sd1 = 1, sd2 = 2, p = 0.5)
fun2(0, 1, mean = 0, sd1 = 1, sd2 = 2, p = 0.5)


Hope this helps,

Rui Barradas


Em 30-01-2013 09:19, Johannes Radinger escreveu:

Hi,

I already found a conversation on the integration of a normal
distribution and two
suggested solutions
(https://stat.ethz.ch/pipermail/r-help/2007-January/124008.html):

1) integrate(dnorm, 0,1, mean = 0, sd = 1.2)

and

2) pnorm(1, mean = 0, sd = 1.2) - pnorm(0, mean = 0, sd = 1.2)

where the pnorm-approach is supposed to be faster and with higher precision.

I want to integrate a mixed normal distribution like:
normaldistr_1 * p + normaldistr_2 * (1-p)

where p is between 0 and 1 and the means for both distributions are 0
but the standard deviations differ.

In addition, I want to get the integrals from x to infinity or from -
infinity to x for
the mixed distribution.

Can that be done with high precision in R and if yes how?

best regards,

Johannes

__
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] Fastest way to compare a single value with all values in one column of a data frame

2013-01-30 Thread Jessica Streicher
If you wanted this for all values in x that are smaller, i'd use

x[x$a  y$a,] - y

for just the smallest:

x[intersect(which(x$a  y$a),which.min(x$a)),] - y


On 29.01.2013, at 22:11, Dimitri Liakhovitski wrote:

 Hello!
 
 I have a large data frame x:
 x-data.frame(item=letters[1:5],a=1:5,b=11:15)  # in actuality, x has 1000
 rows
 x$item-as.character(x$item)
 I also have a small data frame y with just 1 row:
 y-data.frame(item=f,a=3,b=10)
 y$item-as.character(y$item)
 
 I have to decide if y$a is larger than the smallest of all the values in
 x$a. If it is, I want y to replace the whole row in x that has the lowest
 value in column a.
 This is how I'd do it.
 
 if(y$amin(x$a)){
  whichmin-which(x$a==min(x$a))
  x[whichmin,]-y[1,]
 }
 
 
 I am wondering if there is a faster way of doing it. What would be the
 fastest possible way? I'd have to do it, unfortunately, many-many times.
 
 Thank you very much!
 
 -- 
 Dimitri Liakhovitski
 gfk.com http://marketfusionanalytics.com/
 
   [[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] Sweave files generating miktex errors

2013-01-30 Thread Duncan Murdoch

On 13-01-29 6:04 PM, Troy S wrote:

Ok, yes I realize it.  So let me try to fix it:
I removed the sty files, and set TEXINPUTS to
'C:\R\R-2.15.2\share\texmf\tex\latex

I am back where I started: the tex file will not process.
Please let me know what I should do to fix the issue.


Follow my advice in the original message?

Duncan Murdoch


Troy

On Tue, Jan 29, 2013 at 2:20 PM, Duncan Murdoch
murdoch.dun...@gmail.com mailto:murdoch.dun...@gmail.com wrote:

On 13-01-29 4:55 PM, Troy S wrote:

Duncan,
Copying all 3 sty files to my working directory solved the
problem.  I'm
still curious why this was necessary in my new install.  Duncan,
many
thanks!


You do realize that you have now done a Very Bad Thing, I hope.

Duncan Murdoch


Troy

On Tue, Jan 29, 2013 at 10:58 AM, Duncan Murdoch
murdoch.dun...@gmail.com mailto:murdoch.dun...@gmail.com
mailto:murdoch.duncan@gmail.__com
mailto:murdoch.dun...@gmail.com wrote:

 On 29/01/2013 1:37 PM, Troy S wrote:

 Dear useRs--

 I have been using Sweave with miktex for years, but on
a new
 install on
 Windows XP, miktex seems to be hung up on single
quotes.  See
 example below.

 Digging through stackexchange, I found using
 \usepackage[noae]{Sweave} in
 the tex file solved the problem.  My questions are:

 --Why would this happen?  I have the ae package installed.

 --If inserting [noae] is the solution, how do I have
this done
 by Sweave?

 I'll start with the error messages followed by the tex file
 outputted by
 Sweave.

 Any help, please?\


 I don't know if this is the cause of your problem, but you
are doing
 one Bad Thing:  you have a copy of Sweave.sty in the same
directory
 as your document.  This is Bad because it is very easy to
end up
 with Sweave.sty from R version X while using Sweave in R
version Y,
 where X != Y.   You should leave Sweave.sty where it is in
the R
 installation, and use

 R CMD Sweave --pdf testsweave.Rnw

 (or one of the many equivalents) to process it.

 Duncan Murdoch


 Troy
  
 This is pdfTeX, Version 3.1415926-2.4-1.40.13 (MiKTeX 2.9)
 entering extended mode
 (C:\Documents and Settings\v\My Documents\testsweave.tex
 LaTeX2e 2011/06/27
 Babel v3.8m and hyphenation patterns for english,
afrikaans,
 ancientgreek, ar
 abic, armenian, assamese, basque, bengali, bokmal,
bulgarian,
 catalan,
 coptic,
 croatian, czech, danish, dutch, esperanto, estonian,
farsi, finnish,
 french, ga
 lician, german, german-x-2012-05-30, greek, gujarati,
hindi,
 hungarian,
 iceland
 ic, indonesian, interlingua, irish, italian, kannada,
kurmanji,
 latin,
 latvian,
lithuanian, malayalam, marathi, mongolian, mongolianlmc,
 monogreek,
 ngerman, n
 german-x-2012-05-30, nynorsk, oriya, panjabi, pinyin,
polish,
 portuguese,
 roman
 ian, russian, sanskrit, serbian, slovak, slovenian,
spanish,
 swedish,
 swissgerm
 an, tamil, telugu, turkish, turkmen, ukenglish, ukrainian,
 uppersorbian,
 usengl
 ishmax, welsh, loaded.
 (c:\miktex2.9.4757\tex\latex\
 base\article.cls
 Document Class: article 2007/10/19 v1.4h Standard LaTeX
document
 class
 (c:\miktex2.9.4757\tex\latex\base\size10.clo))

 (C:\Documents and Settings\v\My Documents\Sweave.sty
 (c:\miktex2.9.4757\tex\latex\base\ifthen.sty)
 (c:\miktex2.9.4757\tex\latex\graphics\graphicx.sty
 (c:\miktex2.9.4757\tex\latex\graphics\keyval.sty)
 (c:\miktex2.9.4757\tex\latex\graphics\graphics.sty
 (c:\miktex2.9.4757\tex\latex\graphics\trig.sty)
 (c:\miktex2.9.4757\tex\latex\00miktex\graphics.cfg)
 (c:\miktex2.9.4757\tex\latex\pdftex-def\pdftex.def

(c:\miktex2.9.4757\tex\generic\oberdiek\infwarerr.sty)

(c:\miktex2.9.4757\tex\generic\oberdiek\ltxcmds.sty))))

Re: [R] rpart

2013-01-30 Thread Adams, Jean
Carol,

Actually, you have only five nodes, numbered 1, 2, 3, 6, and 7.
And all five nodes are included in your plot.
Nodes 1 and 3 are branching nodes; nodes 2, 6, and 7 are terminal nodes.

Try typing just the name of the rpart object for a very brief text version
of the tree.
 rpart.res

Jean


On Sun, Jan 27, 2013 at 1:31 PM, carol white wht_...@yahoo.com wrote:

 Hi,
 When I look at the summary of an rpart object run on my data, I get 7
 nodes but when I plot the rpart object, I get only 3 nodes. Should the
 number of nodes not match in the results of the 2 functions (summary and
 plot) or it is not always the same?

 Look forward to your reply,

 Carol
 
  summary(rpart.res)
 Call:
 rpart(formula = mydata$class ~ ., data = as.data.frame(t(mydata)))
   n= 62

  CP nsplit rel errorxerror  xstd
 1 0.6363636  0 1.000 1.000 0.1712469
 2 0.1363636  1 0.3636364 0.6818182 0.1532767
 3 0.010  2 0.2272727 0.7727273 0.1596659

 Variable importance
   Hsa.627   Hsa.692 Hsa.692.2  Hsa.3306   Hsa.601   Hsa.831  Hsa.1832
 Hsa.2456
1913111010 8
 6 6
  Hsa.8147  Hsa.1131 Hsa.692.1
 6 5 5

 Node number 1: 62 observations,complexity param=0.6363636
   predicted class=t  expected loss=0.3548387  P(node) =1
 class counts:2240
probabilities: 0.355 0.645
   left son=2 (14 obs) right son=3 (48 obs)
   Primary splits:
   Hsa.62759.83to the left,  improve=15.05376, (0 missing)
   Hsa.8147   1696.23  to the right, improve=14.46790, (0 missing)
   Hsa.37937  379.39   to the right, improve=13.75358, (0 missing)
   Hsa.692.2  842.305  to the right, improve=12.38710, (0 missing)
   Hsa.1832   735.805  to the right, improve=11.90495, (0 missing)
   Surrogate splits:
   Hsa.692.2  1086.655 to the right, agree=0.903, adj=0.571, (0 split)
   Hsa.3306   170.515  to the left,  agree=0.887, adj=0.500, (0 split)
   Hsa.60188.065   to the left,  agree=0.887, adj=0.500, (0 split)
   Hsa.6921251.99  to the right, agree=0.871, adj=0.429, (0 split)
   Hsa.831281.54   to the left,  agree=0.871, adj=0.429, (0 split)

 Node number 2: 14 observations
   predicted class=n  expected loss=0  P(node) =0.2258065
 class counts:14 0
probabilities: 1.000 0.000

 Node number 3: 48 observations,complexity param=0.1363636
   predicted class=t  expected loss=0.167  P(node) =0.7741935
 class counts: 840
probabilities: 0.167 0.833
   left son=6 (7 obs) right son=7 (41 obs)
   Primary splits:
   Hsa.8147   1722.605 to the right, improve=4.915215, (0 missing)
   Hsa.1832   681.145  to the right, improve=4.915215, (0 missing)
   Hsa.1410   49.985   to the left,  improve=4.915215, (0 missing)
   Hsa.2456   186.195  to the right, improve=4.915215, (0 missing)
   Hsa.11616  969.085  to the right, improve=4.915215, (0 missing)
   Surrogate splits:
   Hsa.1832   681.145  to the right, agree=1.000, adj=1.000, (0 split)
   Hsa.2456   186.195  to the right, agree=1.000, adj=1.000, (0 split)
   Hsa.6921048.375 to the right, agree=0.979, adj=0.857, (0 split)
   Hsa.692.1  1136.75  to the right, agree=0.979, adj=0.857, (0 split)
   Hsa.1131   1679.54  to the right, agree=0.979, adj=0.857, (0 split)

 Node number 6: 7 observations
   predicted class=n  expected loss=0.2857143  P(node) =0.1129032
 class counts: 5 2
probabilities: 0.714 0.286

 Node number 7: 41 observations
   predicted class=t  expected loss=0.07317073  P(node) =0.6612903
 class counts: 338
probabilities: 0.073 0.927

 __
 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] remove label from specific axis

2013-01-30 Thread e-letter
Readers,

For a graph plot instruction:

plot(seq(10:50),type='h',yaxt='n',yaxs='i',lab=c(20,2,2),xlab='x axis
label',bty='l',main='graph title')

how to remove y-axis label and keep the x-axis label?

_
r2151

__
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] remove label from specific axis

2013-01-30 Thread Rui Barradas

Hello,

Just use ylab = .

Hope this helps,

Rui Barradas

Em 30-01-2013 13:33, e-letter escreveu:

Readers,

For a graph plot instruction:

plot(seq(10:50),type='h',yaxt='n',yaxs='i',lab=c(20,2,2),xlab='x axis
label',bty='l',main='graph title')

how to remove y-axis label and keep the x-axis label?

_
r2151

__
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] recoding variables again :(

2013-01-30 Thread nalluri pratap
dat1$VARNEW-rep(unknown,nrow(dat1))
dat1$VARNEW[dat1$RES_STA==X  dat1$BIRTHPLACE %in% 
c(AG,AI,AR,BE,ZH)]-swiss

--- On Wed, 30/1/13, arun smartpink...@yahoo.com wrote:


From: arun smartpink...@yahoo.com
Subject: Re: [R] recoding variables again :(
To: stude...@gmail.com stude...@gmail.com
Cc: R help r-help@r-project.org
Date: Wednesday, 30 January, 2013, 5:06 PM


Hi,


set.seed(125)
dat1-data.frame(BIRTHPLACE=sample(c(AG,AI,AR,BE,ZH,USA,GER,ESP),20,replace=TRUE),RES_STA=sample(LETTERS[c(1:3,24:25)],20,replace=TRUE))
dat1$VARNEW-ifelse(dat1$RES_STA==X  
dat1$BIRTHPLACE%in%c(AG,AI,AR,BE,ZH),swiss,unknown)
A.K.



- Original Message -
From: David Studer stude...@gmail.com
To: r-help@r-project.org
Cc: 
Sent: Wednesday, January 30, 2013 4:42 AM
Subject: [R] recoding variables again :(

Hello everybody!

I have again a rather simple question concerning recoding of variables:

I have a variable/data-frame column BIRTHPLACE containing abbreviations of
the 26 swiss counties (AG, AI, AR, BE, ZH, ... )
as well as international country codes (USA, GER, ESP, etc.) and another
variable RES_STA indicating the
residence status (A, B, C, X, Y)

My goal is now to create a new variable VARNEW under the following
conditions:

   - should be the RESIDENCE_STATUS
   - except:
      - if RESIDENCE_STATUS is X and at the same time BIRTHPLACE is one of
      the 26
      swiss counties then it should be swiss
      - otherweise it should be unknown


I have already tried the following code:
mydata$VARNEW-mydata$RESIDENCE_STATUS          # setting VARNEW as
RESIDENCE_STATUS

idx-(mydata$RESIDENCE_STATUS==X  !(        # TRUE: unknown; FALSE:
swiss
mydata$BIRTHPLACE==AG |
mydata$BIRTHPLACE==BE |
mydata$BIRTHPLACE==AR
...
)
)

and then?

Thank you for any help!

David

    [[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.

[[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] Sweave files generating miktex errors

2013-01-30 Thread Michael Friendly

On 1/29/2013 6:04 PM, Troy S wrote:

Ok, yes I realize it.  So let me try to fix it:
I removed the sty files, and set TEXINPUTS to
'C:\R\R-2.15.2\share\texmf\tex\latex

I am back where I started: the tex file will not process.
Please let me know what I should do to fix the issue.
Troy


Don't do that either.

Go to Programs -Miktex - Maintenance (Admin) - Settings
and on the Roots tab, add a folder, e.g., c:\localtexmf
having the same structure as the default texmf tree.
E.g., I have there \tex\latex\..., \bibtex\{bib,bst} ...
where I put all things tex that aren't installed directly
by Miktex


--
Michael Friendly Email: friendly AT yorku DOT ca
Professor, Psychology Dept.  Chair, Quantitative Methods
York University  Voice: 416 736-2100 x66249 Fax: 416 736-5814
4700 Keele StreetWeb:   http://www.datavis.ca
Toronto, ONT  M3J 1P3 CANADA

__
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] Relative Risk in logistic regression

2013-01-30 Thread nalluri pratap
Relative risk = exp(coef(model))

--- On Wed, 30/1/13, aminreza Aamini amin.r@gmail.com wrote:


From: aminreza Aamini amin.r@gmail.com
Subject: [R] Relative Risk in logistic regression
To: R-help R-help@r-project.org
Date: Wednesday, 30 January, 2013, 4:19 PM


Hi all,
I am very grateful to all those who write to me
1) how i  can  obtain relative risk (risk ratio) in logistic regression in R.
2) how to obtain  the predicted risk for a certain individual using
fitted regression model in R.

Many thanks, in advance, for your help.

Amin.

__
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] Sweave files generating miktex errors

2013-01-30 Thread Duncan Murdoch

On 13-01-30 8:52 AM, Michael Friendly wrote:

On 1/29/2013 6:04 PM, Troy S wrote:

Ok, yes I realize it.  So let me try to fix it:
I removed the sty files, and set TEXINPUTS to
'C:\R\R-2.15.2\share\texmf\tex\latex

I am back where I started: the tex file will not process.
Please let me know what I should do to fix the issue.
Troy


Don't do that either.

Go to Programs -Miktex - Maintenance (Admin) - Settings
and on the Roots tab, add a folder, e.g., c:\localtexmf
having the same structure as the default texmf tree.
E.g., I have there \tex\latex\..., \bibtex\{bib,bst} ...
where I put all things tex that aren't installed directly
by Miktex



I think this is better than making copies of Sweave.sty in every project 
in that it's only one place that needs fixing when you upgrade R, but 
why not make use of the facilities in R to handle this?


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.


Re: [R] Fastest way to compare a single value with all values in one column of a data frame

2013-01-30 Thread arun
Hi,
I guess you could also use:


 x[match(min(x$a),x$a[x$ay$a]),]- y
 x
#  item a  b
#1    f 3 10
#2    b 2 12
#3    c 3 13
#4    d 4 14
#5    e 5 15
A.K.



- Original Message -
From: Dimitri Liakhovitski dimitri.liakhovit...@gmail.com
To: r-help r-help@r-project.org
Cc: 
Sent: Tuesday, January 29, 2013 4:11 PM
Subject: [R] Fastest way to compare a single value with all values in one 
column of a data frame

Hello!

I have a large data frame x:
x-data.frame(item=letters[1:5],a=1:5,b=11:15)  # in actuality, x has 1000
rows
x$item-as.character(x$item)
I also have a small data frame y with just 1 row:
y-data.frame(item=f,a=3,b=10)
y$item-as.character(y$item)

I have to decide if y$a is larger than the smallest of all the values in
x$a. If it is, I want y to replace the whole row in x that has the lowest
value in column a.
This is how I'd do it.

if(y$amin(x$a)){
  whichmin-which(x$a==min(x$a))
  x[whichmin,]-y[1,]
}


I am wondering if there is a faster way of doing it. What would be the
fastest possible way? I'd have to do it, unfortunately, many-many times.

Thank you very much!

-- 
Dimitri Liakhovitski
gfk.com http://marketfusionanalytics.com/

    [[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] Relative Risk in logistic regression

2013-01-30 Thread nalluri pratap
Example from linear regression help (?lm)
 
ctl - c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt - c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group - gl(2,10,20, labels=c(Ctl,Trt))
weight - c(ctl, trt)
lm.D9 - lm(weight ~ group)
lm.D90 - lm(weight ~ group - 1)
 
prediction_error= lm.D90$residuals

--- On Wed, 30/1/13, aminreza Aamini amin.r@gmail.com wrote:


From: aminreza Aamini amin.r@gmail.com
Subject: [R] Relative Risk in logistic regression
To: R-help R-help@r-project.org
Date: Wednesday, 30 January, 2013, 4:19 PM


Hi all,
I am very grateful to all those who write to me
1) how i  can  obtain relative risk (risk ratio) in logistic regression in R.
2) how to obtain  the predicted risk for a certain individual using
fitted regression model in R.

Many thanks, in advance, for your help.

Amin.

__
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] substring from behind

2013-01-30 Thread arun
Hi,
You could use:
dat1-data.frame(col1=c(Mercedes_02352,Audi_03555))
dat1[,1]-as.numeric(gsub(.*_\\d{1}(.*)\\d{1}$,\\1,dat1[,1])) #if the 
number of digits are the same
 dat1
#  col1
#1  235
#2  355
A.K.



- Original Message -
From: Mat matthias.we...@fnt.de
To: r-help@r-project.org
Cc: 
Sent: Wednesday, January 30, 2013 4:05 AM
Subject: [R] substring from behind

Hello together,

i have a question for substring.
I know i can filter a number like this one:
bill$No-substring(bill$Customer,2,4)

in this case i get the 2nd, 3rd and 4th number of my Customer ID.
But how can i do this, if i want the 2nd, 3rd and 4th number of a column.

Like this one.
I have: Mercedes_02352
Audi_03555
and now i want to filter this data.frame to
235
355

can you help me?

Thanks.

Mat



--
View this message in context: 
http://r.789695.n4.nabble.com/substring-from-behind-tp4657029.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.


[R] temporal correlogram

2013-01-30 Thread Valerie Lehouck
Hi all,

I’ve just started to learn working with R.

I wonder if it is possible to make a ‘temporal correlogram’ in R and how to
do it. Actually what I have are movement tracks of birds, existing as
XY-positions every 5 minutes for a duration of at least 60 minutes (but up
to 8 hours). From these tracks, I calculated step lengths (ie distances
travelled within each 5 min-step) and turning angles (also per 5 min-step)
for each ‘tracking session’ (I tracked each individual bird several times).
I manually calculated the correlation between step-legths at time t and
t+5min and they are strongluy correlated. I want to know for how many time
steps this correlation holds. Therefore,I want to calculate autocorrelations
(between step lengths, between turning angles - and eventually also between
step lengths and turning angles, but that’s more complex) for subsequent
steps (so I need a moving window frame for delta time/step). On the Y-axis,
I would then have rho (autocorrelation coefficient for step length or
turning angle), and on the X-axis, delta time (as time steps 0, 5, 10,15,
... minutes). Ideal would be to have the average rho + CI (or SD) displayed
over all individuals (or tracking sessions). Is there a package to do this i
R? I searched the web but found only correlograms for spatial data
(sncf-package), not temporal.

 

Thank you very much for your kind assistance!

Valérie


--



Valérie Lehouck

Assistant Professor

Research Unit Terrestrial Ecology

Ghent University

KL Ledeganckstraat 35

9000 Ghent

Belgium

Tel.: +32(0)9/264 52 58

website: http://www.ecology.ugent.be/terec/personal.php?pers=vl




[[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] (no subject)

2013-01-30 Thread Meenakshi Shankar Santhakumar


Dear Team,
I am getting the following error message when try to run vb application
The program was running fine in 32 windows 7 machine.
When i moved the same program to 64 bit windows 8 machine i am getting the 
following error
Error in inDL(x, as.logical(local), as.logical(now), ...) : unable to load 
shared object 'C:/Program Files/R/R-2.15.1/library/stats/libs/i386/stats.dll':  
LoadLibrary failure:  The specified module could not be found.
During startup - Warning message:package 'stats' in options(defaultPackages) 
was not found  
[[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] Percentages in bar plot

2013-01-30 Thread Naser Jamil
Dear R-users,
Though it's a silly thing to ask, but I'm not getting a way out. I wish to
find the percentage distribution for a data vector 'stop'. The coomand
below is giving the frequency distribution.  May I know the option to see
the percentages instead of frequencies.  Similarly, what option I should
put in a histogram plot to see the percentages instead of frequencies?

-
stop-c(8,6,6,6,8,6,6,8,8,6,6,6,8,8,8)
barplot(table(stop))



Many thanks for your time.


Regards,
Jamil.

[[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] substring from behind

2013-01-30 Thread Isidro Hidalgo
It's possible the direct way in R:

customer - c(Mercedes_02352, Audi_03555)
substr(customer, nchar(customer) - 3, nchar(customer) - 1)

Isidro

 -Mensaje original-
 De: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 En nombre de Jorge I Velez
 Enviado el: miércoles, 30 de enero de 2013 10:50
 Para: Mat
 CC: r-help@r-project.org
 Asunto: Re: [R] substring from behind

 Hi Mat,

 The following should get you started:

  s - Mercedes_02352
  substr(s, nchar(s) - 3, nchar(s) - 1)
 [1] 235
 

  # defining a function
  foo - function(x, a = 3, b = 1) substr(s, nchar(x) - a, nchar(x) -
 b)
  foo(s)
 [1] 235

 HTH,
 Jorge.-


 On Wed, Jan 30, 2013 at 8:05 PM, Mat  wrote:

  Hello together,
 
  i have a question for substring.
  I know i can filter a number like this one:
  bill$No-substring(bill$Customer,2,4)
 
  in this case i get the 2nd, 3rd and 4th number of my Customer ID.
  But how can i do this, if i want the 2nd, 3rd and 4th number of a
 column.
 
  Like this one.
  I have: Mercedes_02352
  Audi_03555
  and now i want to filter this data.frame to
  235
  355
 
  can you help me?
 
  Thanks.
 
  Mat
 
 
 
  --
  View this message in context:
  http://r.789695.n4.nabble.com/substring-from-behind-tp4657029.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.
 

   [[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] Percentages in bar plot

2013-01-30 Thread Rui Barradas

Hello,

Try

barplot(table(stop)/sum(table(stop)))


Hope this helps,

Rui Barradas

Em 30-01-2013 11:34, Naser Jamil escreveu:

Dear R-users,
Though it's a silly thing to ask, but I'm not getting a way out. I wish to
find the percentage distribution for a data vector 'stop'. The coomand
below is giving the frequency distribution.  May I know the option to see
the percentages instead of frequencies.  Similarly, what option I should
put in a histogram plot to see the percentages instead of frequencies?

-
stop-c(8,6,6,6,8,6,6,8,8,6,6,6,8,8,8)
barplot(table(stop))



Many thanks for your time.


Regards,
Jamil.

[[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] texture mapping images on the faces of a cuboid with rgl

2013-01-30 Thread ravi
Hi,
I am interested in mapping 6 different images on the faces of a cube. I found 
the full code for doing this here :
http://rwiki.sciviews.org/doku.php?id=graph_gallery:cube
But I am unable to adapt the code for my purpose. I would appreciate it if I 
could get some help on the following points :
1. My images are jpeg images with dimensions of 1936*2584*3. Must I seperately 
process the grey and rgb attributes as in the code in the above page. Would 
appreciate it if I could get some explicit help on processing the image matrix. 
I don't follow in detail how a square portion of the graphic is extracted also.
2. Instead of a cube, I am interested in mapping images on a cuboid (l!=b!=h). 
Could I get tips on how this can be done. How should the dimensions of the 
image matrix be tailored then?

3. The following line in the code appears to identify and fix the corner points 
:
coords - rbind(  c(0 , 2, 3),  c(1 , 3, 2),  c(3, 0 , 2),  c(2, 1 , 3),  c(2, 
3, 0 ),  c(3, 2, 1 )  )
How should I read and understand the orientation of the cube corners from this? 
A simple tip can get me started.


I would like to add some example code (to complement Romain Francois' code on 
the rwiki page referred to above). But, as can be seen from my questions, I 
don't understand this sufficiently to do this. But I hope that I have given 
sufficient information to explain my problem.
Thanks,
Ravi

[[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] Change rows and columns

2013-01-30 Thread John Kane
Please reply with context to the list. Most R-help readers do not use nabble.

I don't quite understand your question but do you mean something like ?names?

John Kane
Kingston ON Canada


 -Original Message-
 From: matthias.we...@fnt.de
 Sent: Tue, 29 Jan 2013 07:41:21 -0800 (PST)
 To: r-help@r-project.org
 Subject: Re: [R] Change rows and columns
 
 thx, that worked perfekt, but is there any way to convert my Number 1 row
 #  123
 up as column description?
 
 
 
 --
 View this message in context:
 http://r.789695.n4.nabble.com/Change-rows-and-columns-tp4656965p4656969.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.


FREE ONLINE PHOTOSHARING - Share your photos online with your friends and 
family!
Visit http://www.inbox.com/photosharing to find out more!

__
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] pROC in R

2013-01-30 Thread John Kane
I don't see what is happening from your code but you have a typo in the emai if 
not in your code.  It should be  library (pROC)

John Kane
Kingston ON Canada


 -Original Message-
 From: feth...@yahoo.fr
 Sent: Mon, 28 Jan 2013 14:44:50 + (GMT)
 To: r-help@r-project.org
 Subject: [R] pROC in R
 
 
 
 B Dear,
 
 I would like to use pROC software for my study, butB  I could not
 uploaded it in R. Could you please help me to overcome this problem?
 This is the message when I write Library (pROC) :
 
 Le chargement a nC)cessitC) le package : plyr
 Type 'citation(pROC)' for a citation.
 
 Attachement du package : b??pROCb??
 
 The following object(s) are masked from b??package:statsb??:
 
 B B  B  cov, smooth, var
 Thank you in advance
 
 Best Regards
 Fethi
 
 Student at Geneva university
   [[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.


FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks  orcas on your 
desktop!

__
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] Sweave files generating miktex errors

2013-01-30 Thread Troy S
Michael,

I added C:\R\R-2.15.2\share\texmf to the list of roots and hit apply and
that solved the problem.  Thanks!

Duncan, I did try the R CMD Sweave you suggested and that did not solve the
issue.  The problem was in  running LaTeX so how was your suggestion help
me?  It would have to copy the .sty files somewhere to help the situation.

Thanks guys.  I appreciate the help!
Troy

On Wed, Jan 30, 2013 at 5:52 AM, Michael Friendly frien...@yorku.ca wrote:

 On 1/29/2013 6:04 PM, Troy S wrote:

 Ok, yes I realize it.  So let me try to fix it:
 I removed the sty files, and set TEXINPUTS to
 'C:\R\R-2.15.2\share\texmf\**tex\latex

 I am back where I started: the tex file will not process.
 Please let me know what I should do to fix the issue.
 Troy


 Don't do that either.

 Go to Programs -Miktex - Maintenance (Admin) - Settings
 and on the Roots tab, add a folder, e.g., c:\localtexmf
 having the same structure as the default texmf tree.
 E.g., I have there \tex\latex\..., \bibtex\{bib,bst} ...
 where I put all things tex that aren't installed directly
 by Miktex


 --
 Michael Friendly Email: friendly AT yorku DOT ca
 Professor, Psychology Dept.  Chair, Quantitative Methods
 York University  Voice: 416 736-2100 x66249 Fax: 416 736-5814
 4700 Keele StreetWeb:   http://www.datavis.ca
 Toronto, ONT  M3J 1P3 CANADA



[[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] Fastest way to compare a single value with all values in one column of a data frame

2013-01-30 Thread arun
HI,

Sorry, my previous solution doesn't work.
This should work for your dataset:
set.seed(1851)
x- 
data.frame(item=sample(letters[1:5],20,replace=TRUE),a=sample(1:15,20,replace=TRUE),b=sample(20:30,20,replace=TRUE),stringsAsFactors=F)
y- data.frame(item=f,a=3,b=10,stringsAsFactors=F)
 x[x$a%in%which.min(x[x$ay$a,]$a),]- y #if there are multiple minimum values

set.seed(1241)
x1- 
data.frame(item=sample(letters[1:10],1e4,replace=TRUE),a=sample(1:30,1e4,replace=TRUE),b=sample(1:100,1e4,replace=TRUE),stringsAsFactors=F)
y1- data.frame(item=f,a=3,b=10,stringsAsFactors=F)
length(x1$a[x1$a==1])
#[1] 330
 system.time({x1[x1$a%in%which.min(x1[x1$ay1$a,]$a),]- y1})
#   user  system elapsed 
 # 0.000   0.000   0.001 
length(x1$a[x1$a==1])
#[1] 0


#For some reason, it is not working when the multiple number of minimum values 
 some value

set.seed(1241)
x1- 
data.frame(item=sample(letters[1:10],1e5,replace=TRUE),a=sample(1:30,1e5,replace=TRUE),b=sample(1:100,1e5,replace=TRUE),stringsAsFactors=F)
y1- data.frame(item=f,a=3,b=10,stringsAsFactors=F)
length(x1$a[x1$a==1])
#[1] 3404
x1[x1$a%in%which.min(x1[x1$ay1$a,]$a),]- y1
 length(x1$a[x1$a==1])
#[1] 3404 #not getting replaced

#However, if I try:
set.seed(1241)
 x1- 
data.frame(item=sample(letters[1:10],1e6,replace=TRUE),a=sample(1:5000,1e6,replace=TRUE),b=sample(1:100,1e6,replace=TRUE),stringsAsFactors=F)
 y1- data.frame(item=f,a=3,b=10,stringsAsFactors=F)
 length(x1$a[x1$a==1])
#[1] 208
 system.time(x1[x1$a%in%which.min(x1[x1$ay1$a,]$a),]- y1)
#user  system elapsed 
 # 0.124   0.016   0.138 
  length(x1$a[x1$a==1])
#[1] 0


#Tried Jessica's solution:
set.seed(1851)
 x- 
data.frame(item=sample(letters[1:5],20,replace=TRUE),a=sample(1:15,20,replace=TRUE),b=sample(20:30,20,replace=TRUE),stringsAsFactors=F)
 y- data.frame(item=f,a=3,b=10,stringsAsFactors=F)
 x[intersect(which(x$a  y$a),which.min(x$a)),] - y
 x
#   item  a  b
#1 a  8 25
#2 a 10 26
#3 f  3 10 #replaced
#4 e 15 26
#5 b 13 20
#6 a  5 23
#7 d  4 29
#8 e  2 24
#9 c  7 30
#10    e 14 24
#11    d  2 20
#12    e 10 21
#13    c 13 27
#14    d 12 23
#15    b 11 26
#16    e  5 22
#17    c  1 26  #it is not replaced
#18    a  8 21
#19    e 10 26
#20    c  2 22



A.K.





- Original Message -
From: Dimitri Liakhovitski dimitri.liakhovit...@gmail.com
To: r-help r-help@r-project.org
Cc: 
Sent: Tuesday, January 29, 2013 4:11 PM
Subject: [R] Fastest way to compare a single value with all values in one 
column of a data frame

Hello!

I have a large data frame x:
x-data.frame(item=letters[1:5],a=1:5,b=11:15)  # in actuality, x has 1000
rows
x$item-as.character(x$item)
I also have a small data frame y with just 1 row:
y-data.frame(item=f,a=3,b=10)
y$item-as.character(y$item)

I have to decide if y$a is larger than the smallest of all the values in
x$a. If it is, I want y to replace the whole row in x that has the lowest
value in column a.
This is how I'd do it.

if(y$amin(x$a)){
  whichmin-which(x$a==min(x$a))
  x[whichmin,]-y[1,]
}


I am wondering if there is a faster way of doing it. What would be the
fastest possible way? I'd have to do it, unfortunately, many-many times.

Thank you very much!

-- 
Dimitri Liakhovitski
gfk.com http://marketfusionanalytics.com/

    [[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] Relative Risk in logistic regression

2013-01-30 Thread Kevin E. Thorpe

On 01/30/2013 09:02 AM, nalluri pratap wrote:

Relative risk = exp(coef(model))



Only if you fit using the log link.  Using the logit link, this gives 
odds ratios.



--- On Wed, 30/1/13, aminreza Aamini amin.r@gmail.com wrote:


From: aminreza Aamini amin.r@gmail.com
Subject: [R] Relative Risk in logistic regression
To: R-help R-help@r-project.org
Date: Wednesday, 30 January, 2013, 4:19 PM


Hi all,
I am very grateful to all those who write to me
1) how i  can  obtain relative risk (risk ratio) in logistic regression in R.
2) how to obtain  the predicted risk for a certain individual using
fitted regression model in R.

Many thanks, in advance, for your help.

Amin.

__
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.




--
Kevin E. Thorpe
Head of Biostatistics,  Applied Health Research Centre (AHRC)
Li Ka Shing Knowledge Institute of St. Michael's
Assistant Professor, Dalla Lana School of Public Health
University of Toronto
email: kevin.tho...@utoronto.ca  Tel: 416.864.5776  Fax: 416.864.3016

__
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 use ...

2013-01-30 Thread Patrick Burns

There is now a blog post that attempts to
answer the question in the subject line:

http://www.burns-stat.com/the-three-dots-construct-in-r/

Pat

On 17/01/2013 14:36, Ivan Calandra wrote:

Dear users,

I'm trying to learn how to use the 

I have written a function (simplified here) that uses doBy::summaryBy():
# 'dat' is a data.frame from which the aggregation is computed
# 'vec_cat' is a integer vector defining which columns of the data.frame
should be use on the right side of the formula
# 'stat_fun' is the function that will be run to aggregate
stat.group - function(dat, vec_cat, stat_fun){
 require(doBy)
 df -
summaryBy(as.formula(paste0(.~,paste0(names(dat)[vec_cat],collapse=+))),
data=dat, FUN=stat_fun)
 return(df)
}

Example, works fine:
my_data - structure(list(cat = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L, 2L), .Label = c(A, B), class = factor), varnum =
c(-0.754816565434373,
-1.94101630973709, -0.102461836059522, -0.519952759645808,
-1.73772800855664,
-1.13939178585609, 0.522356715260142, -0.701428514907824, 1.45197576541159,
0.0844567413828095)), .Names = c(cat, varnum), row.names = c(NA,
-10L), class = data.frame)
stat.group(dat=my_data, vec_cat=1, stat_fun=mean)


Now summaryBy() has an ... argument and I would like to use it.
For example, I would like to be able to add the trim argument to my call
like this:
stat.group(dat=my_data, vec_cat=1, stat_fun=mean, trim=0.2)


I know I can do it using this ... but I have no idea how to do it.
I've tried to search for it, but a search with ... doesn't yield
interesting results!


Thank you in advance for your help!
Ivan



--
Patrick Burns
pbu...@pburns.seanet.com
twitter: @burnsstat @portfolioprobe
http://www.portfolioprobe.com/blog
http://www.burns-stat.com
(home of:
 'Impatient R'
 'The R Inferno'
 'Tao Te Programming')

__
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] Relative Risk in logistic regression

2013-01-30 Thread John Sorkin
I am not sure why one would want a relative risk from a logistic regression. 
The measure of association from a logistic regression is the odds ratio, not 
the relative risk.
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) Kevin 
E. Thorpe kevin.tho...@utoronto.ca 1/30/2013 11:14 AM 
On 01/30/2013 09:02 AM, nalluri pratap wrote:
 Relative risk = exp(coef(model))


Only if you fit using the log link.  Using the logit link, this gives 
odds ratios.

 --- On Wed, 30/1/13, aminreza Aamini amin.r@gmail.com wrote:


 From: aminreza Aamini amin.r@gmail.com
 Subject: [R] Relative Risk in logistic regression
 To: R-help R-help@r-project.org
 Date: Wednesday, 30 January, 2013, 4:19 PM


 Hi all,
 I am very grateful to all those who write to me
 1) how i  can  obtain relative risk (risk ratio) in logistic regression in R.
 2) how to obtain  the predicted risk for a certain individual using
 fitted regression model in R.

 Many thanks, in advance, for your help.

 Amin.

 __
 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.



-- 
Kevin E. Thorpe
Head of Biostatistics,  Applied Health Research Centre (AHRC)
Li Ka Shing Knowledge Institute of St. Michael's
Assistant Professor, Dalla Lana School of Public Health
University of Toronto
email: kevin.tho...@utoronto.ca  Tel: 416.864.5776  Fax: 416.864.3016

__
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 the sole use of the 
intended recipient(s) and may contain confidential and privileged information.  
Any unauthorized use, disclosure or distribution is prohibited.  If you are not 
the intended recipient, please contact the sender by reply email and destroy 
all copies of the original message. 
__
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] Relative Risk in logistic regression

2013-01-30 Thread Kevin E. Thorpe

On 01/30/2013 11:17 AM, John Sorkin wrote:

I am not sure why one would want a relative risk from a logistic
regression. The measure of association from a logistic regression is the
odds ratio, not the relative risk.
John



Yes, the natural measure, when using the logit link, is the OR.  I 
always use that myself, but if you use the log link, you get RR.  As for 
why you would, I would suggest it's because physicians think they 
understand a RR better than and OR.




Kevin E. Thorpe kevin.tho...@utoronto.ca 1/30/2013 11:14 AM 
On 01/30/2013 09:02 AM, nalluri pratap wrote:
  Relative risk = exp(coef(model))
 

Only if you fit using the log link.  Using the logit link, this gives
odds ratios.

  --- On Wed, 30/1/13, aminreza Aamini amin.r@gmail.com wrote:
 
 
  From: aminreza Aamini amin.r@gmail.com
  Subject: [R] Relative Risk in logistic regression
  To: R-help R-help@r-project.org
  Date: Wednesday, 30 January, 2013, 4:19 PM
 
 
  Hi all,
  I am very grateful to all those who write to me
  1) how i  can  obtain relative risk (risk ratio) in logistic
regression in R.
  2) how to obtain  the predicted risk for a certain individual using
  fitted regression model in R.
 
  Many thanks, in advance, for your help.
 
  Amin.
 
  __
  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.
 





--
Kevin E. Thorpe
Head of Biostatistics,  Applied Health Research Centre (AHRC)
Li Ka Shing Knowledge Institute of St. Michael's
Assistant Professor, Dalla Lana School of Public Health
University of Toronto
email: kevin.tho...@utoronto.ca  Tel: 416.864.5776  Fax: 416.864.3016

__
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] Relative Risk in logistic regression

2013-01-30 Thread John Sorkin
If you use a log link, you are not, I believe, performing a logistic regression!

 
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) Kevin 
E. Thorpe kevin.tho...@utoronto.ca 1/30/2013 11:22 AM 
On 01/30/2013 11:17 AM, John Sorkin wrote:
 I am not sure why one would want a relative risk from a logistic
 regression. The measure of association from a logistic regression is the
 odds ratio, not the relative risk.
 John


Yes, the natural measure, when using the logit link, is the OR.  I 
always use that myself, but if you use the log link, you get RR.  As for 
why you would, I would suggest it's because physicians think they 
understand a RR better than and OR.


 Kevin E. Thorpe kevin.tho...@utoronto.ca 1/30/2013 11:14 AM 
 On 01/30/2013 09:02 AM, nalluri pratap wrote:
   Relative risk = exp(coef(model))
  

 Only if you fit using the log link.  Using the logit link, this gives
 odds ratios.

   --- On Wed, 30/1/13, aminreza Aamini amin.r@gmail.com wrote:
  
  
   From: aminreza Aamini amin.r@gmail.com
   Subject: [R] Relative Risk in logistic regression
   To: R-help R-help@r-project.org
   Date: Wednesday, 30 January, 2013, 4:19 PM
  
  
   Hi all,
   I am very grateful to all those who write to me
   1) how i  can  obtain relative risk (risk ratio) in logistic
 regression in R.
   2) how to obtain  the predicted risk for a certain individual using
   fitted regression model in R.
  
   Many thanks, in advance, for your help.
  
   Amin.
  
   __
   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.
  




-- 
Kevin E. Thorpe
Head of Biostatistics,  Applied Health Research Centre (AHRC)
Li Ka Shing Knowledge Institute of St. Michael's
Assistant Professor, Dalla Lana School of Public Health
University of Toronto
email: kevin.tho...@utoronto.ca  Tel: 416.864.5776  Fax: 416.864.3016


Confidentiality Statement:
This email message, including any attachments, is for the sole use of the 
intended recipient(s) and may contain confidential and privileged information.  
Any unauthorized use, disclosure or distribution is prohibited.  If you are not 
the intended recipient, please contact the sender by reply email and destroy 
all copies of the original message. 
__
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] Programmatically give file name to a matrix

2013-01-30 Thread Greg Snow
This is FAQ 7.21.  The most important part of that answer is at the end
where it says that it is better to use a list.  Your code could be
something like:

plotroc - list()
for (i in levels(mergeTrn$Continent) {
  # matrix defined here
  plotroc[[ paste(plotroc_GBM_TRN_,i, sep=) ]] - matrix
}

now all of your created matrices are in the plotroc list (or whatever you
want to call it) and can be operated on using functions like sapply and
lapply.


On Wed, Jan 30, 2013 at 1:04 AM, Kumar Mainali kpmain...@gmail.com wrote:

 I have a situation when I need to save matrix with file names that are
 programmatically created.

 for (i in levels(mergeTrn$Continent)) {
 matrix here

 # I want to save this matrix with a file name that carries i from for
 loop. The following does not work.
 paste(plotroc_GBM_Trn_, i, sep=) - matrix

 }

 Thanks,
 Kumar

 --
 Section of Integrative Biology
 University of Texas at Austin
 Austin, Texas 78712, USA

 [[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.




-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

[[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] Relative Risk in logistic regression

2013-01-30 Thread Kevin E. Thorpe

On 01/30/2013 11:26 AM, John Sorkin wrote:

If you use a log link, you are not, I believe, performing a logistic
regression!


I guess strictly speaking, that is true.  I was being a little sloppy in 
terminology.




Kevin E. Thorpe kevin.tho...@utoronto.ca 1/30/2013 11:22 AM 
On 01/30/2013 11:17 AM, John Sorkin wrote:
  I am not sure why one would want a relative risk from a logistic
  regression. The measure of association from a logistic regression is the
  odds ratio, not the relative risk.
  John
 

Yes, the natural measure, when using the logit link, is the OR.  I
always use that myself, but if you use the log link, you get RR.  As for
why you would, I would suggest it's because physicians think they
understand a RR better than and OR.


  Kevin E. Thorpe kevin.tho...@utoronto.ca 1/30/2013 11:14 AM 
  On 01/30/2013 09:02 AM, nalluri pratap wrote:
Relative risk = exp(coef(model))
   
 
  Only if you fit using the log link.  Using the logit link, this gives
  odds ratios.
 
--- On Wed, 30/1/13, aminreza Aamini amin.r@gmail.com wrote:
   
   
From: aminreza Aamini amin.r@gmail.com
Subject: [R] Relative Risk in logistic regression
To: R-help R-help@r-project.org
Date: Wednesday, 30 January, 2013, 4:19 PM
   
   
Hi all,
I am very grateful to all those who write to me
1) how i  can  obtain relative risk (risk ratio) in logistic
  regression in R.
2) how to obtain  the predicted risk for a certain individual using
fitted regression model in R.
   
Many thanks, in advance, for your help.
   
Amin.
   
__
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]]
   
   



--
Kevin E. Thorpe
Head of Biostatistics,  Applied Health Research Centre (AHRC)
Li Ka Shing Knowledge Institute of St. Michael's
Assistant Professor, Dalla Lana School of Public Health
University of Toronto
email: kevin.tho...@utoronto.ca  Tel: 416.864.5776  Fax: 416.864.3016

__
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] RandomForest and Missing Values

2013-01-30 Thread nalluri pratap
If you wish to remove missing values, you can use the option 
na.action=na.omit.If you wish to Impute you can use rfImpute.

--- On Mon, 28/1/13, Lorenzo Isella lorenzo.ise...@gmail.com wrote:


From: Lorenzo Isella lorenzo.ise...@gmail.com
Subject: [R] RandomForest and Missing Values
To: r-h...@stat.math.ethz.ch
Date: Monday, 28 January, 2013, 10:07 PM


Dear All,
I would like to use a randomForest algorithm on a dataset.
The set is not particularly large/difficult to handle, but it has some
missing values (both factors and numerical values).
According to what I found

https://stat.ethz.ch/pipermail/r-help/2005-September/078880.html
https://stat.ethz.ch/pipermail/r-help/2007-January/123117.html

the randomForest package has a problem with missing data (essentially
you have to resort to some trick to introduce them into your dataset
--a median value, the most common factor, a linear interpolation
etc...).
Seen that I could not find a clear workaround for this (but I cannot
be the only one who has in mind to do a randomForest on a less than
perfect data set), can anyone help me out?
I am concerned about the consequences of introducing the missing
values into the data set.
The cforest function in the Party package does not seem to have this
limitation, but on the other hand the randomForest package has passed
the test of timeso should I drop it in this case?
Any suggestion is appreciated.
Cheers

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.

[[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 use ...

2013-01-30 Thread Bert Gunter
Because R can be interactive, I find that a little exploring through
the use of strategically placed browser() calls (?browser if you are
unfamiliar with this handy debugging tool) is often the fastest way to
solve little R puzzles like this.

For example, try this (in an R GUI):

f2 - function(y,...){ browser(); list(...) }
f1 - function(x,...){ browser(); f2(x,...) }

Now at the command line:

f1( x=1, z= 2:4)
## In the f1 browser  do ls() to see what's in the f1 environment
## and then do list(...) to see what's in the dots argument
## then issue the browser command  c  to continue
## and do the same in the f2 browser .

## then try:
 f1( x=1, y= 2:4)  ## and
 f1( 2:4)
 f1( y=2:4) ## this will produce an error in f2

I think this help give you a better idea of what's going on (or
totally confuse?!).

-- Bert




On Wed, Jan 30, 2013 at 8:15 AM, Patrick Burns pbu...@pburns.seanet.com wrote:
 There is now a blog post that attempts to
 answer the question in the subject line:

 http://www.burns-stat.com/the-three-dots-construct-in-r/

 Pat

 On 17/01/2013 14:36, Ivan Calandra wrote:

 Dear users,

 I'm trying to learn how to use the 

 I have written a function (simplified here) that uses doBy::summaryBy():
 # 'dat' is a data.frame from which the aggregation is computed
 # 'vec_cat' is a integer vector defining which columns of the data.frame
 should be use on the right side of the formula
 # 'stat_fun' is the function that will be run to aggregate
 stat.group - function(dat, vec_cat, stat_fun){
  require(doBy)
  df -

 summaryBy(as.formula(paste0(.~,paste0(names(dat)[vec_cat],collapse=+))),
 data=dat, FUN=stat_fun)
  return(df)
 }

 Example, works fine:
 my_data - structure(list(cat = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L,
 2L, 2L, 2L), .Label = c(A, B), class = factor), varnum =
 c(-0.754816565434373,
 -1.94101630973709, -0.102461836059522, -0.519952759645808,
 -1.73772800855664,
 -1.13939178585609, 0.522356715260142, -0.701428514907824,
 1.45197576541159,
 0.0844567413828095)), .Names = c(cat, varnum), row.names = c(NA,
 -10L), class = data.frame)
 stat.group(dat=my_data, vec_cat=1, stat_fun=mean)


 Now summaryBy() has an ... argument and I would like to use it.
 For example, I would like to be able to add the trim argument to my call
 like this:
 stat.group(dat=my_data, vec_cat=1, stat_fun=mean, trim=0.2)


 I know I can do it using this ... but I have no idea how to do it.
 I've tried to search for it, but a search with ... doesn't yield
 interesting results!


 Thank you in advance for your help!
 Ivan


 --
 Patrick Burns
 pbu...@pburns.seanet.com
 twitter: @burnsstat @portfolioprobe
 http://www.portfolioprobe.com/blog
 http://www.burns-stat.com
 (home of:
  'Impatient R'
  'The R Inferno'
  'Tao Te Programming')

 __
 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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

__
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] Sweave files generating miktex errors

2013-01-30 Thread Duncan Murdoch

On 13-01-30 11:00 AM, Troy S wrote:

Michael,

I added C:\R\R-2.15.2\share\texmf to the list of roots and hit apply and
that solved the problem.  Thanks!

Duncan, I did try the R CMD Sweave you suggested and that did not solve
the issue.  The problem was in  running LaTeX so how was your suggestion
help me?  It would have to copy the .sty files somewhere to help the
situation.


No, if you use the --pdf option (as I suggested!!) it would run LaTeX 
for you, after figuring out what distribution of LaTeX you're using, and 
putting together the right incantation to tell it to find the style files.


Please do not post your solution on a blog somewhere.  There is way too 
much bad advice about running Sweave on the net already.


Duncan Murdoch



Thanks guys.  I appreciate the help!
Troy

On Wed, Jan 30, 2013 at 5:52 AM, Michael Friendly frien...@yorku.ca
mailto:frien...@yorku.ca wrote:

On 1/29/2013 6:04 PM, Troy S wrote:

Ok, yes I realize it.  So let me try to fix it:
I removed the sty files, and set TEXINPUTS to
'C:\R\R-2.15.2\share\texmf\__tex\latex

I am back where I started: the tex file will not process.
Please let me know what I should do to fix the issue.
Troy


Don't do that either.

Go to Programs -Miktex - Maintenance (Admin) - Settings
and on the Roots tab, add a folder, e.g., c:\localtexmf
having the same structure as the default texmf tree.
E.g., I have there \tex\latex\..., \bibtex\{bib,bst} ...
where I put all things tex that aren't installed directly
by Miktex


--
Michael Friendly Email: friendly AT yorku DOT ca
Professor, Psychology Dept.  Chair, Quantitative Methods
York University  Voice: 416 736-2100 x66249
tel:416%20736-2100%20x66249 Fax: 416 736-5814 tel:416%20736-5814
4700 Keele StreetWeb: http://www.datavis.ca
Toronto, ONT  M3J 1P3 CANADA




__
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] Sweave files generating miktex errors

2013-01-30 Thread Troy S
Duncan,

Alas, I had left out the --pdf flag when I tried the solution.

I am glad I have an answer now, and a better understanding of the problem.

Troy

On Wed, Jan 30, 2013 at 9:50 AM, Duncan Murdoch murdoch.dun...@gmail.comwrote:

 On 13-01-30 11:00 AM, Troy S wrote:

 Michael,

 I added C:\R\R-2.15.2\share\texmf to the list of roots and hit apply and
 that solved the problem.  Thanks!

 Duncan, I did try the R CMD Sweave you suggested and that did not solve
 the issue.  The problem was in  running LaTeX so how was your suggestion
 help me?  It would have to copy the .sty files somewhere to help the
 situation.


 No, if you use the --pdf option (as I suggested!!) it would run LaTeX for
 you, after figuring out what distribution of LaTeX you're using, and
 putting together the right incantation to tell it to find the style files.

 Please do not post your solution on a blog somewhere.  There is way too
 much bad advice about running Sweave on the net already.

 Duncan Murdoch


 Thanks guys.  I appreciate the help!
 Troy

 On Wed, Jan 30, 2013 at 5:52 AM, Michael Friendly frien...@yorku.ca
 mailto:frien...@yorku.ca wrote:

 On 1/29/2013 6:04 PM, Troy S wrote:

 Ok, yes I realize it.  So let me try to fix it:
 I removed the sty files, and set TEXINPUTS to
 'C:\R\R-2.15.2\share\texmf\__**tex\latex


 I am back where I started: the tex file will not process.
 Please let me know what I should do to fix the issue.
 Troy


 Don't do that either.

 Go to Programs -Miktex - Maintenance (Admin) - Settings
 and on the Roots tab, add a folder, e.g., c:\localtexmf
 having the same structure as the default texmf tree.
 E.g., I have there \tex\latex\..., \bibtex\{bib,bst} ...
 where I put all things tex that aren't installed directly
 by Miktex


 --
 Michael Friendly Email: friendly AT yorku DOT ca
 Professor, Psychology Dept.  Chair, Quantitative Methods
 York University  Voice: 416 736-2100 x66249
 tel:416%20736-2100%20x66249 Fax: 416 736-5814 tel:416%20736-5814

 4700 Keele StreetWeb: http://www.datavis.ca
 Toronto, ONT  M3J 1P3 CANADA





[[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] Fastest way to compare a single value with all values in one column of a data frame

2013-01-30 Thread Dimitri Liakhovitski
Thank you, everyone! I'll try to test those different approaches. Really
appreciate your help!
Dimitri

On Wed, Jan 30, 2013 at 11:03 AM, arun smartpink...@yahoo.com wrote:

 HI,

 Sorry, my previous solution doesn't work.
 This should work for your dataset:
 set.seed(1851)
 x-
 data.frame(item=sample(letters[1:5],20,replace=TRUE),a=sample(1:15,20,replace=TRUE),b=sample(20:30,20,replace=TRUE),stringsAsFactors=F)
 y- data.frame(item=f,a=3,b=10,stringsAsFactors=F)
  x[x$a%in%which.min(x[x$ay$a,]$a),]- y #if there are multiple minimum
 values

 set.seed(1241)
 x1-
 data.frame(item=sample(letters[1:10],1e4,replace=TRUE),a=sample(1:30,1e4,replace=TRUE),b=sample(1:100,1e4,replace=TRUE),stringsAsFactors=F)
 y1- data.frame(item=f,a=3,b=10,stringsAsFactors=F)
 length(x1$a[x1$a==1])
 #[1] 330
  system.time({x1[x1$a%in%which.min(x1[x1$ay1$a,]$a),]- y1})
 #   user  system elapsed
  # 0.000   0.000   0.001
 length(x1$a[x1$a==1])
 #[1] 0


 #For some reason, it is not working when the multiple number of minimum
 values  some value

 set.seed(1241)
 x1-
 data.frame(item=sample(letters[1:10],1e5,replace=TRUE),a=sample(1:30,1e5,replace=TRUE),b=sample(1:100,1e5,replace=TRUE),stringsAsFactors=F)
 y1- data.frame(item=f,a=3,b=10,stringsAsFactors=F)
 length(x1$a[x1$a==1])
 #[1] 3404
 x1[x1$a%in%which.min(x1[x1$ay1$a,]$a),]- y1
  length(x1$a[x1$a==1])
 #[1] 3404 #not getting replaced

 #However, if I try:
 set.seed(1241)
  x1-
 data.frame(item=sample(letters[1:10],1e6,replace=TRUE),a=sample(1:5000,1e6,replace=TRUE),b=sample(1:100,1e6,replace=TRUE),stringsAsFactors=F)
  y1- data.frame(item=f,a=3,b=10,stringsAsFactors=F)
  length(x1$a[x1$a==1])
 #[1] 208
  system.time(x1[x1$a%in%which.min(x1[x1$ay1$a,]$a),]- y1)
 #user  system elapsed
  # 0.124   0.016   0.138
   length(x1$a[x1$a==1])
 #[1] 0


 #Tried Jessica's solution:
 set.seed(1851)
  x-
 data.frame(item=sample(letters[1:5],20,replace=TRUE),a=sample(1:15,20,replace=TRUE),b=sample(20:30,20,replace=TRUE),stringsAsFactors=F)
  y- data.frame(item=f,a=3,b=10,stringsAsFactors=F)
  x[intersect(which(x$a  y$a),which.min(x$a)),] - y
  x
 #   item  a  b
 #1 a  8 25
 #2 a 10 26
 #3 f  3 10 #replaced
 #4 e 15 26
 #5 b 13 20
 #6 a  5 23
 #7 d  4 29
 #8 e  2 24
 #9 c  7 30
 #10e 14 24
 #11d  2 20
 #12e 10 21
 #13c 13 27
 #14d 12 23
 #15b 11 26
 #16e  5 22
 #17c  1 26  #it is not replaced
 #18a  8 21
 #19e 10 26
 #20c  2 22



 A.K.





 - Original Message -
 From: Dimitri Liakhovitski dimitri.liakhovit...@gmail.com
 To: r-help r-help@r-project.org
 Cc:
 Sent: Tuesday, January 29, 2013 4:11 PM
 Subject: [R] Fastest way to compare a single value with all values in one
 column of a data frame

  Hello!

 I have a large data frame x:
 x-data.frame(item=letters[1:5],a=1:5,b=11:15)  # in actuality, x has 1000
 rows
 x$item-as.character(x$item)
 I also have a small data frame y with just 1 row:
 y-data.frame(item=f,a=3,b=10)
 y$item-as.character(y$item)

 I have to decide if y$a is larger than the smallest of all the values in
 x$a. If it is, I want y to replace the whole row in x that has the lowest
 value in column a.
 This is how I'd do it.

 if(y$amin(x$a)){
   whichmin-which(x$a==min(x$a))
   x[whichmin,]-y[1,]
 }


 I am wondering if there is a faster way of doing it. What would be the
 fastest possible way? I'd have to do it, unfortunately, many-many times.

 Thank you very much!

 --
 Dimitri Liakhovitski
  gfk.com http://marketfusionanalytics.com/

 [[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.htmlhttp://www.r-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




-- 
Dimitri Liakhovitski
gfk.com http://marketfusionanalytics.com/

[[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] Fastest way to compare a single value with all values in one column of a data frame

2013-01-30 Thread Dimitri Liakhovitski
Sorry - I should have clarified:
My identifiers (in column item) will always be unique. In other words,
one entry in column item will never be repeated - neither in x nor in y.
Dimitri

On Wed, Jan 30, 2013 at 1:27 PM, Dimitri Liakhovitski 
dimitri.liakhovit...@gmail.com wrote:

 Thank you, everyone! I'll try to test those different approaches. Really
 appreciate your help!
 Dimitri

  On Wed, Jan 30, 2013 at 11:03 AM, arun smartpink...@yahoo.com wrote:

 HI,

 Sorry, my previous solution doesn't work.
 This should work for your dataset:
 set.seed(1851)
 x-
 data.frame(item=sample(letters[1:5],20,replace=TRUE),a=sample(1:15,20,replace=TRUE),b=sample(20:30,20,replace=TRUE),stringsAsFactors=F)
 y- data.frame(item=f,a=3,b=10,stringsAsFactors=F)
  x[x$a%in%which.min(x[x$ay$a,]$a),]- y #if there are multiple minimum
 values

 set.seed(1241)
 x1-
 data.frame(item=sample(letters[1:10],1e4,replace=TRUE),a=sample(1:30,1e4,replace=TRUE),b=sample(1:100,1e4,replace=TRUE),stringsAsFactors=F)
 y1- data.frame(item=f,a=3,b=10,stringsAsFactors=F)
 length(x1$a[x1$a==1])
 #[1] 330
  system.time({x1[x1$a%in%which.min(x1[x1$ay1$a,]$a),]- y1})
 #   user  system elapsed
  # 0.000   0.000   0.001
 length(x1$a[x1$a==1])
 #[1] 0


 #For some reason, it is not working when the multiple number of minimum
 values  some value

 set.seed(1241)
 x1-
 data.frame(item=sample(letters[1:10],1e5,replace=TRUE),a=sample(1:30,1e5,replace=TRUE),b=sample(1:100,1e5,replace=TRUE),stringsAsFactors=F)
 y1- data.frame(item=f,a=3,b=10,stringsAsFactors=F)
 length(x1$a[x1$a==1])
 #[1] 3404
 x1[x1$a%in%which.min(x1[x1$ay1$a,]$a),]- y1
  length(x1$a[x1$a==1])
 #[1] 3404 #not getting replaced

 #However, if I try:
 set.seed(1241)
  x1-
 data.frame(item=sample(letters[1:10],1e6,replace=TRUE),a=sample(1:5000,1e6,replace=TRUE),b=sample(1:100,1e6,replace=TRUE),stringsAsFactors=F)
  y1- data.frame(item=f,a=3,b=10,stringsAsFactors=F)
  length(x1$a[x1$a==1])
 #[1] 208
  system.time(x1[x1$a%in%which.min(x1[x1$ay1$a,]$a),]- y1)
 #user  system elapsed
  # 0.124   0.016   0.138
   length(x1$a[x1$a==1])
 #[1] 0


 #Tried Jessica's solution:
 set.seed(1851)
  x-
 data.frame(item=sample(letters[1:5],20,replace=TRUE),a=sample(1:15,20,replace=TRUE),b=sample(20:30,20,replace=TRUE),stringsAsFactors=F)
  y- data.frame(item=f,a=3,b=10,stringsAsFactors=F)
  x[intersect(which(x$a  y$a),which.min(x$a)),] - y
  x
 #   item  a  b
 #1 a  8 25
 #2 a 10 26
 #3 f  3 10 #replaced
 #4 e 15 26
 #5 b 13 20
 #6 a  5 23
 #7 d  4 29
 #8 e  2 24
 #9 c  7 30
 #10e 14 24
 #11d  2 20
 #12e 10 21
 #13c 13 27
 #14d 12 23
 #15b 11 26
 #16e  5 22
 #17c  1 26  #it is not replaced
 #18a  8 21
 #19e 10 26
 #20c  2 22



 A.K.





 - Original Message -
 From: Dimitri Liakhovitski dimitri.liakhovit...@gmail.com
 To: r-help r-help@r-project.org
 Cc:
 Sent: Tuesday, January 29, 2013 4:11 PM
 Subject: [R] Fastest way to compare a single value with all values in one
 column of a data frame

  Hello!

 I have a large data frame x:
 x-data.frame(item=letters[1:5],a=1:5,b=11:15)  # in actuality, x has 1000
 rows
 x$item-as.character(x$item)
 I also have a small data frame y with just 1 row:
 y-data.frame(item=f,a=3,b=10)
 y$item-as.character(y$item)

 I have to decide if y$a is larger than the smallest of all the values in
 x$a. If it is, I want y to replace the whole row in x that has the lowest
 value in column a.
 This is how I'd do it.

 if(y$amin(x$a)){
   whichmin-which(x$a==min(x$a))
   x[whichmin,]-y[1,]
 }


 I am wondering if there is a faster way of doing it. What would be the
 fastest possible way? I'd have to do it, unfortunately, many-many times.

 Thank you very much!

 --
 Dimitri Liakhovitski
  gfk.com http://marketfusionanalytics.com/

 [[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.htmlhttp://www.r-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




 --
 Dimitri Liakhovitski
 gfk.com http://marketfusionanalytics.com/




-- 
Dimitri Liakhovitski
gfk.com http://marketfusionanalytics.com/

[[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] Fastest way to compare a single value with all values in one column of a data frame

2013-01-30 Thread arun
Hi,
Any chance x$a to have the same number repeated?

If `Item` and `a` are unique,  I guess both the solutions should work.

set.seed(1851)
x- 
data.frame(item=sample(letters[1:20],20,replace=F),a=sample(1:45,20,replace=F),b=sample(20:50,20,replace=F),stringsAsFactors=F)
y- data.frame(item=z,a=3,b=10,stringsAsFactors=F)

x[intersect(which(x$a  y$a),which.min(x$a)),]
 #  item a  b
#17    c 1 48
 x[x$a==which.min(x$a[x$ay$a]),]
#   item a  b
#17    c 1 48
#or 

x[x$a%in%which.min(x$a[x$ay$a]),]
#   item a  b
#17    c 1 48

x[x$a%in%which.min(x$a[x$ay$a]),]-y

tail(x)
#   item  a  b
#15    q 45 30
#16    g 10 23
#17    z  3 10
#18    r 15 39
#19    l 18 45
#20    t 35 33

#However, if `item` column is unique, but `a` is not, then the one I mentioned 
previously arise.
set.seed(1851)
x1- 
data.frame(item=sample(letters[1:20],20,replace=F),a=sample(1:10,20,replace=T),b=sample(20:50,20,replace=F),stringsAsFactors=F)
y1- data.frame(item=z,a=3,b=10,stringsAsFactors=F)


x1[intersect(which(x1$a  y1$a),which.min(x1$a)),]
 # item a  b
#3    s 1 41
x1[x1$a==which.min(x1$a[x1$ay1$a]),]
 #  item a  b
#3 s 1 41
#11    h 1 46
#17    c 1 48
x1[x1$a==which.min(x1$a[x1$ay1$a]),]- y1
A.K.



From: Dimitri Liakhovitski dimitri.liakhovit...@gmail.com
To: arun smartpink...@yahoo.com 
Cc: R help r-help@r-project.org; Jessica Streicher j.streic...@micromata.de 
Sent: Wednesday, January 30, 2013 1:49 PM
Subject: Re: [R] Fastest way to compare a single value with all values in one 
column of a data frame


Sorry - I should have clarified:
My identifiers (in column item) will always be unique. In other words, one 
entry in column item will never be repeated - neither in x nor in y.
Dimitri


On Wed, Jan 30, 2013 at 1:27 PM, Dimitri Liakhovitski 
dimitri.liakhovit...@gmail.com wrote:

Thank you, everyone! I'll try to test those different approaches. Really 
appreciate your help!
Dimitri


On Wed, Jan 30, 2013 at 11:03 AM, arun smartpink...@yahoo.com wrote:

HI,

Sorry, my previous solution doesn't work.
This should work for your dataset:
set.seed(1851)
x- 
data.frame(item=sample(letters[1:5],20,replace=TRUE),a=sample(1:15,20,replace=TRUE),b=sample(20:30,20,replace=TRUE),stringsAsFactors=F)
y- data.frame(item=f,a=3,b=10,stringsAsFactors=F)
 x[x$a%in%which.min(x[x$ay$a,]$a),]- y #if there are multiple minimum values

set.seed(1241)
x1- 
data.frame(item=sample(letters[1:10],1e4,replace=TRUE),a=sample(1:30,1e4,replace=TRUE),b=sample(1:100,1e4,replace=TRUE),stringsAsFactors=F)
y1- data.frame(item=f,a=3,b=10,stringsAsFactors=F)
length(x1$a[x1$a==1])
#[1] 330
 system.time({x1[x1$a%in%which.min(x1[x1$ay1$a,]$a),]- y1})
#   user  system elapsed
 # 0.000   0.000   0.001
length(x1$a[x1$a==1])
#[1] 0


#For some reason, it is not working when the multiple number of minimum 
values  some value

set.seed(1241)
x1- 
data.frame(item=sample(letters[1:10],1e5,replace=TRUE),a=sample(1:30,1e5,replace=TRUE),b=sample(1:100,1e5,replace=TRUE),stringsAsFactors=F)
y1- data.frame(item=f,a=3,b=10,stringsAsFactors=F)
length(x1$a[x1$a==1])
#[1] 3404
x1[x1$a%in%which.min(x1[x1$ay1$a,]$a),]- y1
 length(x1$a[x1$a==1])
#[1] 3404 #not getting replaced

#However, if I try:
set.seed(1241)
 x1- 
data.frame(item=sample(letters[1:10],1e6,replace=TRUE),a=sample(1:5000,1e6,replace=TRUE),b=sample(1:100,1e6,replace=TRUE),stringsAsFactors=F)
 y1- data.frame(item=f,a=3,b=10,stringsAsFactors=F)
 length(x1$a[x1$a==1])
#[1] 208
 system.time(x1[x1$a%in%which.min(x1[x1$ay1$a,]$a),]- y1)
#user  system elapsed
 # 0.124   0.016   0.138
  length(x1$a[x1$a==1])
#[1] 0


#Tried Jessica's solution:
set.seed(1851)
 x- 
data.frame(item=sample(letters[1:5],20,replace=TRUE),a=sample(1:15,20,replace=TRUE),b=sample(20:30,20,replace=TRUE),stringsAsFactors=F)
 y- data.frame(item=f,a=3,b=10,stringsAsFactors=F)
 x[intersect(which(x$a  y$a),which.min(x$a)),] - y

 x
#   item  a  b
#1 a  8 25
#2 a 10 26
#3 f  3 10 #replaced
#4 e 15 26
#5 b 13 20
#6 a  5 23
#7 d  4 29
#8 e  2 24
#9 c  7 30
#10    e 14 24
#11    d  2 20
#12    e 10 21
#13    c 13 27
#14    d 12 23
#15    b 11 26
#16    e  5 22
#17    c  1 26  #it is not replaced
#18    a  8 21
#19    e 10 26
#20    c  2 22




A.K.





- Original Message -
From: Dimitri Liakhovitski dimitri.liakhovit...@gmail.com
To: r-help r-help@r-project.org
Cc:
Sent: Tuesday, January 29, 2013 4:11 PM
Subject: [R] Fastest way to compare a single value with all values in one 
column of a data frame


Hello!

I have a large data frame x:
x-data.frame(item=letters[1:5],a=1:5,b=11:15)  # in actuality, x has 1000
rows
x$item-as.character(x$item)
I also have a small data frame y with just 1 row:
y-data.frame(item=f,a=3,b=10)
y$item-as.character(y$item)

I have to decide if y$a is larger than the smallest of all the values in
x$a. If it is, I want y to replace the whole row in x that has the lowest
value in column a.
This is how I'd do it.

if(y$amin(x$a)){
  whichmin-which(x$a==min(x$a))
  

Re: [R] starting values in glm(..., family = binomial(link =log))

2013-01-30 Thread Fischer, Felix
Thanks for your replies! It seems, that I can fit my model now, when I can 
provide the right starting values; however there remain warnings, such as:

1: In log(ifelse(y == 1, 1, (1 - y)/(1 - mu))) : NaNs wurden erzeugt
2: step size truncated due to divergence
3: step size truncated: out of bounds
...

That makes me feel uncomfortable and I wonder whether I can trust the fitted 
model. Why is this kind of regression so picky about starting values compared 
to logistic regression? And is there a way to explain the difference between 
binomial - quasibinomial to a simple mind like mine?

Best,
Felix

Von: Ravi Varadhan [mailto:ravi.varad...@jhu.edu]
Gesendet: Mittwoch, 30. Januar 2013 17:02
An: Fischer, Felix
Cc: r-help@r-project.org
Betreff: [R] starting values in glm(..., family = binomial(link =log))

Try this:

Age_log_model = glm(Arthrose ~ Alter, data=x, start=c(-1, 0), 
family=quasibinomial(link = log))

Ravi

Ravi Varadhan, Ph.D.
Assistant Professor
The Center on Aging and Health
Division of Geriatric Medicine  Gerontology
Johns Hopkins University
rvarad...@jhmi.edumailto:rvarad...@jhmi.edu
410-502-2619


[[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] Going in circles

2013-01-30 Thread Casey,Richard
Hi, we're trying to install rJava on SLES 11.

With:

R CMD INSTALL rJava_0.9-3.tar.gz

It says:

configure: error: One or more Java configuration variables are not set.
Make sure R is configured with full Java support (including JDK). Run
R CMD javareconf
as root to add Java support to R.

So we run:

R CMD javareconf

It says:

Updating Java configuration in /apps/R-2.14.2/lib64/R
Done.

and appears to update R correctly.  But if we run this again:

R CMD INSTALL rJava_0.9-3.tar.gz

It gives the same error message:

configure: error: One or more Java configuration variables are not set.
Make sure R is configured with full Java support (including JDK). Run
R CMD javareconf
as root to add Java support to R.

So we're going in circles with this.  Is javareconf not fully configuring R?  
Are we missing something?


[[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] starting values in glm(..., family = binomial(link =log))

2013-01-30 Thread Ravi Varadhan
Try this:

Age_log_model = glm(Arthrose ~ Alter, data=x, start=c(-1, 0), 
family=quasibinomial(link = log))

Ravi

Ravi Varadhan, Ph.D.
Assistant Professor
The Center on Aging and Health
Division of Geriatric Medicine  Gerontology
Johns Hopkins University
rvarad...@jhmi.edumailto:rvarad...@jhmi.edu
410-502-2619


[[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] non-metric multidimensional scaling

2013-01-30 Thread Myra Juckers

Hello,

I would like to perform an NMDS on the following:
I have two independent variables, which are sites and treatments. 
I have 6 sites which are peatlands. I collected 5 replicates (at the same time) 
from each of the sites. 
I used each of the replicates in a treatment.
There were 4 treatments. 2 were controls and the other two were a simulated 30 
day drought and a simulated 60 day drought.
From each of the replicates in each of the treatments I measured pH and 
nitrate, sulphate, dissolved organic carbon, calcium, magnesium, nickel, 
cobalt, aluminum, and copper concentrations. 
I tried performing an NMDS using the following tutorial 
http://strata.uga.edu/software/pdf/mdsTutorial.pdf. However, I did not take 
into account sites or treatments. All the data was used without making those 
distinctions. 
I would like to make an NMDS plot which distinguishes the points as sites and 
another plot which distinguishes the points as treatments but which still 
demonstrates where the pH, nitrate, sulphate, etc variables are located across 
the plot. 
Do you know how I can accomplish this? 
I hope I am clear in my explanation. 

Thank you,
Myra
  
[[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 does predict() calculate prediction intervals?

2013-01-30 Thread Kurt Rinehart
For a given linear regression, I wish to find the 2-tailed t-dist
probability that Y-hat = newly observed values. I generate prediction
intervals in predict() for plotting, but when I calculate my t-dist
probabilities, they don't agree. I have researched the issues with variance
of individual predictions and been advised to use the variance formula
below (in the code).

I presume my variance function differs from that used in predict(). Can
someone advise me as to why I cannot reproduce the results of predict()?

As a test, I calculated the prediction intervals about Y-hat by hand and
compared them to predict():

X - log10(c(780,54,520,703,1356,1900,2500,741,1500,600))
Y -
log10(c(0.037,0.036,0.026,0.0315,0.028,0.0099,0.00955,0.0405,0.019,0.0245))
dat - data.frame(cbind(X, Y))
mod - lm(Y ~ X, data = dat)
rm(X,Y)

## model predictions, y.hat, at the new X values
pred - data.frame(predict.lm(mod,newdata = obs, interval = prediction,
level = 0.95))

# 3 subsequent observations
obs - log10(data.frame(cbind(c(40, 200, 450), c(0.3, 0.06, .034
names(obs) - c(X, Y)

## Calculating t-dist, 2-tailed, 95% prediction intervals for new
observations
mse - anova(mod)[2,3]
new.x - obs$X - mean(dat$X)
sum.x2 - sum((dat$X - mean(dat$X))^2)
y.hat - pred$fit
var.y.hat - mse*(1+new.x^2/sum.x2)

upr - y.hat + qt(c(0.975), df = 8) * sqrt(var.y.hat)
lwr - y.hat + qt(c(0.025), df = 8) * sqrt(var.y.hat)
hand - data.frame(cbind(y.hat, lwr, upr))

#The limits are not the same
pred
hand

--
Thank you,
Kurt

[[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] starting values in glm(..., family = binomial(link =log))

2013-01-30 Thread Ravi Varadhan
I did not get any warnings when I ran your data/model example.

From: Fischer, Felix [mailto:felix.fisc...@charite.de]
Sent: Wednesday, January 30, 2013 11:19 AM
To: Ravi Varadhan
Cc: r-help@r-project.org
Subject: AW: [R] starting values in glm(..., family = binomial(link =log))

Thanks for your replies! It seems, that I can fit my model now, when I can 
provide the right starting values; however there remain warnings, such as:

1: In log(ifelse(y == 1, 1, (1 - y)/(1 - mu))) : NaNs wurden erzeugt
2: step size truncated due to divergence
3: step size truncated: out of bounds
...

That makes me feel uncomfortable and I wonder whether I can trust the fitted 
model. Why is this kind of regression so picky about starting values compared 
to logistic regression? And is there a way to explain the difference between 
binomial - quasibinomial to a simple mind like mine?

Best,
Felix

Von: Ravi Varadhan [mailto:ravi.varad...@jhu.edu]
Gesendet: Mittwoch, 30. Januar 2013 17:02
An: Fischer, Felix
Cc: r-help@r-project.orgmailto:r-help@r-project.org
Betreff: [R] starting values in glm(..., family = binomial(link =log))

Try this:

Age_log_model = glm(Arthrose ~ Alter, data=x, start=c(-1, 0), 
family=quasibinomial(link = log))

Ravi

Ravi Varadhan, Ph.D.
Assistant Professor
The Center on Aging and Health
Division of Geriatric Medicine  Gerontology
Johns Hopkins University
rvarad...@jhmi.edumailto:rvarad...@jhmi.edu
410-502-2619


[[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] Add axes to a 3D scene (afer makeTriangles)

2013-01-30 Thread David Winsemius


On Jan 30, 2013, at 3:09 AM, cgenolin wrote:


Hi all,

I am drawing some 3D surfaces using the Triangle tools (package  
misc3) and
drawScene.rgl. Do you know if it is possible to add axes and  
graduation on

the scene?



You offer no code or data,  so a specific answer is not called for.  
Certainly the specific answer to the possibility of labels in rgl  
graph is is yes. You might learn something by looking at the work  
that Ben Bolker and I put into a question requesting labels on the  
scatter3d function in package car;


http://stackoverflow.com/questions/8204972/carscatter3d-in-r-labeling-axis-better/8206320#8206320

--
David Winsemius, MD
Alameda, CA, USA

__
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] Fastest way to compare a single value with all values in one column of a data frame

2013-01-30 Thread Dimitri Liakhovitski
In realy, values in a will be not integers, but numeric. They will never be
identical, but it could be that they are pretty close - I don't know after
how many points after the comma matter.
Dimitri

On Wed, Jan 30, 2013 at 2:06 PM, arun smartpink...@yahoo.com wrote:

 Hi,
 Any chance x$a to have the same number repeated?

 If `Item` and `a` are unique,  I guess both the solutions should work.

 set.seed(1851)
 x-
 data.frame(item=sample(letters[1:20],20,replace=F),a=sample(1:45,20,replace=F),b=sample(20:50,20,replace=F),stringsAsFactors=F)
 y- data.frame(item=z,a=3,b=10,stringsAsFactors=F)

 x[intersect(which(x$a  y$a),which.min(x$a)),]
  #  item a  b
 #17c 1 48
  x[x$a==which.min(x$a[x$ay$a]),]
 #   item a  b
 #17c 1 48
 #or

 x[x$a%in%which.min(x$a[x$ay$a]),]
 #   item a  b
 #17c 1 48

 x[x$a%in%which.min(x$a[x$ay$a]),]-y

 tail(x)
 #   item  a  b
 #15q 45 30
 #16g 10 23
 #17z  3 10
 #18r 15 39
 #19l 18 45
 #20t 35 33

 #However, if `item` column is unique, but `a` is not, then the one I
 mentioned previously arise.
 set.seed(1851)
 x1-
 data.frame(item=sample(letters[1:20],20,replace=F),a=sample(1:10,20,replace=T),b=sample(20:50,20,replace=F),stringsAsFactors=F)
 y1- data.frame(item=z,a=3,b=10,stringsAsFactors=F)


 x1[intersect(which(x1$a  y1$a),which.min(x1$a)),]
  # item a  b
 #3s 1 41
 x1[x1$a==which.min(x1$a[x1$ay1$a]),]
  #  item a  b
 #3 s 1 41
 #11h 1 46
 #17c 1 48
 x1[x1$a==which.min(x1$a[x1$ay1$a]),]- y1
 A.K.


 
 From: Dimitri Liakhovitski dimitri.liakhovit...@gmail.com
 To: arun smartpink...@yahoo.com
 Cc: R help r-help@r-project.org; Jessica Streicher 
 j.streic...@micromata.de
 Sent: Wednesday, January 30, 2013 1:49 PM
 Subject: Re: [R] Fastest way to compare a single value with all values in
 one column of a data frame


 Sorry - I should have clarified:
 My identifiers (in column item) will always be unique. In other words,
 one entry in column item will never be repeated - neither in x nor in y.
 Dimitri


 On Wed, Jan 30, 2013 at 1:27 PM, Dimitri Liakhovitski 
 dimitri.liakhovit...@gmail.com wrote:

 Thank you, everyone! I'll try to test those different approaches. Really
 appreciate your help!
 Dimitri
 
 
 On Wed, Jan 30, 2013 at 11:03 AM, arun smartpink...@yahoo.com wrote:
 
 HI,
 
 Sorry, my previous solution doesn't work.
 This should work for your dataset:
 set.seed(1851)
 x-
 data.frame(item=sample(letters[1:5],20,replace=TRUE),a=sample(1:15,20,replace=TRUE),b=sample(20:30,20,replace=TRUE),stringsAsFactors=F)
 y- data.frame(item=f,a=3,b=10,stringsAsFactors=F)
  x[x$a%in%which.min(x[x$ay$a,]$a),]- y #if there are multiple minimum
 values
 
 set.seed(1241)
 x1-
 data.frame(item=sample(letters[1:10],1e4,replace=TRUE),a=sample(1:30,1e4,replace=TRUE),b=sample(1:100,1e4,replace=TRUE),stringsAsFactors=F)
 y1- data.frame(item=f,a=3,b=10,stringsAsFactors=F)
 length(x1$a[x1$a==1])
 #[1] 330
  system.time({x1[x1$a%in%which.min(x1[x1$ay1$a,]$a),]- y1})
 #   user  system elapsed
  # 0.000   0.000   0.001
 length(x1$a[x1$a==1])
 #[1] 0
 
 
 #For some reason, it is not working when the multiple number of minimum
 values  some value
 
 set.seed(1241)
 x1-
 data.frame(item=sample(letters[1:10],1e5,replace=TRUE),a=sample(1:30,1e5,replace=TRUE),b=sample(1:100,1e5,replace=TRUE),stringsAsFactors=F)
 y1- data.frame(item=f,a=3,b=10,stringsAsFactors=F)
 length(x1$a[x1$a==1])
 #[1] 3404
 x1[x1$a%in%which.min(x1[x1$ay1$a,]$a),]- y1
  length(x1$a[x1$a==1])
 #[1] 3404 #not getting replaced
 
 #However, if I try:
 set.seed(1241)
  x1-
 data.frame(item=sample(letters[1:10],1e6,replace=TRUE),a=sample(1:5000,1e6,replace=TRUE),b=sample(1:100,1e6,replace=TRUE),stringsAsFactors=F)
  y1- data.frame(item=f,a=3,b=10,stringsAsFactors=F)
  length(x1$a[x1$a==1])
 #[1] 208
  system.time(x1[x1$a%in%which.min(x1[x1$ay1$a,]$a),]- y1)
 #user  system elapsed
  # 0.124   0.016   0.138
   length(x1$a[x1$a==1])
 #[1] 0
 
 
 #Tried Jessica's solution:
 set.seed(1851)
  x-
 data.frame(item=sample(letters[1:5],20,replace=TRUE),a=sample(1:15,20,replace=TRUE),b=sample(20:30,20,replace=TRUE),stringsAsFactors=F)
  y- data.frame(item=f,a=3,b=10,stringsAsFactors=F)
  x[intersect(which(x$a  y$a),which.min(x$a)),] - y
 
  x
 #   item  a  b
 #1 a  8 25
 #2 a 10 26
 #3 f  3 10 #replaced
 #4 e 15 26
 #5 b 13 20
 #6 a  5 23
 #7 d  4 29
 #8 e  2 24
 #9 c  7 30
 #10e 14 24
 #11d  2 20
 #12e 10 21
 #13c 13 27
 #14d 12 23
 #15b 11 26
 #16e  5 22
 #17c  1 26  #it is not replaced
 #18a  8 21
 #19e 10 26
 #20c  2 22
 
 
 
 
 A.K.
 
 
 
 
 
 - Original Message -
 From: Dimitri Liakhovitski dimitri.liakhovit...@gmail.com
 To: r-help r-help@r-project.org
 Cc:
 Sent: Tuesday, January 29, 2013 4:11 PM
 Subject: [R] Fastest way to compare a single value with all values in
 one column of a data frame
 
 
 Hello!
 
 I have a large data frame x:
 

[R] arithmetic and logical operators

2013-01-30 Thread Dave Mitchell
Why, in R, does (0.1 + 0.05)  0.15 evaluate to True?  What am I missing
here?  How can I ensure this (ostensibly incorrect) behavior doesn't
introduce bugs into my code?  Thanks for your time.

Dave Mitchell

[[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] arithmetic and logical operators

2013-01-30 Thread R. Michael Weylandt
R FAQ 7.31 (Note, this isn't R specific, rather it's a problem with
the finitude of computers)

MW

On Wed, Jan 30, 2013 at 8:32 PM, Dave Mitchell dmmtc...@gmail.com wrote:
 Why, in R, does (0.1 + 0.05)  0.15 evaluate to True?  What am I missing
 here?  How can I ensure this (ostensibly incorrect) behavior doesn't
 introduce bugs into my code?  Thanks for your time.

 Dave Mitchell

 [[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] Relative Risk in logistic regression

2013-01-30 Thread David Winsemius


On Jan 30, 2013, at 5:49 AM, aminreza Aamini wrote:


Hi all,
I am very grateful to all those who write to me
1) how i  can  obtain relative risk (risk ratio) in logistic  
regression in R.

2) how to obtain  the predicted risk for a certain individual using
fitted regression model in R.


You obtain the predicted probabilities with something like:

predict(model, data.frame(x1=a, x2=30), type = response)

See ?predict.glm

This would give the odds ratios (similar but larger than the risk  
ratios):


exp(coef(model))

--
David Winsemius, MD
Alameda, CA, USA

__
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] arithmetic and logical operators

2013-01-30 Thread Berend Hasselman

On 30-01-2013, at 21:32, Dave Mitchell dmmtc...@gmail.com wrote:

 Why, in R, does (0.1 + 0.05)  0.15 evaluate to True?  What am I missing
 here?  How can I ensure this (ostensibly incorrect) behavior doesn't
 introduce bugs into my code?  Thanks for your time.
 

R-FAQ 7.31: 
http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f

Berend

__
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] arithmetic and logical operators

2013-01-30 Thread William Dunlap
 Why, in R, does (0.1 + 0.05)  0.15 evaluate to True?  

Because floating point arithmetic is done with a fixed
number of digits.   If you are working in base 10 and have
2 digits to work with you would have
   1/3 - .33
   2/3 - .67
so that
1/3 + 1/3  2/3

 How can I ensure this (ostensibly incorrect) behavior doesn't
 introduce bugs into my code?

You can index things with integers.  E.g., instead of storing 0.1, 0.05,
and 0.15, store  2, 1, and 3.  Do your comparisons on the integers
and multiply by 0.05 when you need to use them in that format.

You can work with numbers that are exactly representable with
52 binary digits, such as 1/1024 or 10^14+1/8.

You can work with smooth functions so the it doesn't matter
much what the sign of 0.15 - (0.10 + 0.05) is. 

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf
 Of Dave Mitchell
 Sent: Wednesday, January 30, 2013 12:32 PM
 To: r-help@r-project.org
 Subject: [R] arithmetic and logical operators
 
 Why, in R, does (0.1 + 0.05)  0.15 evaluate to True?  What am I missing
 here?  How can I ensure this (ostensibly incorrect) behavior doesn't
 introduce bugs into my code?  Thanks for your time.
 
 Dave Mitchell
 
   [[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 does predict() calculate prediction intervals?

2013-01-30 Thread Rolf Turner


Just look at the code of predict.lm().  It is reasonably perspicuous.
In particular look at res.var.

cheers,

Rolf Turner

On 01/31/2013 05:50 AM, Kurt Rinehart wrote:

For a given linear regression, I wish to find the 2-tailed t-dist
probability that Y-hat = newly observed values. I generate prediction
intervals in predict() for plotting, but when I calculate my t-dist
probabilities, they don't agree. I have researched the issues with variance
of individual predictions and been advised to use the variance formula
below (in the code).

I presume my variance function differs from that used in predict(). Can
someone advise me as to why I cannot reproduce the results of predict()?

As a test, I calculated the prediction intervals about Y-hat by hand and
compared them to predict():

X - log10(c(780,54,520,703,1356,1900,2500,741,1500,600))
Y -
log10(c(0.037,0.036,0.026,0.0315,0.028,0.0099,0.00955,0.0405,0.019,0.0245))
dat - data.frame(cbind(X, Y))
mod - lm(Y ~ X, data = dat)
rm(X,Y)

## model predictions, y.hat, at the new X values
pred - data.frame(predict.lm(mod,newdata = obs, interval = prediction,
level = 0.95))

# 3 subsequent observations
obs - log10(data.frame(cbind(c(40, 200, 450), c(0.3, 0.06, .034
names(obs) - c(X, Y)

## Calculating t-dist, 2-tailed, 95% prediction intervals for new
observations
mse - anova(mod)[2,3]
new.x - obs$X - mean(dat$X)
sum.x2 - sum((dat$X - mean(dat$X))^2)
y.hat - pred$fit
var.y.hat - mse*(1+new.x^2/sum.x2)

upr - y.hat + qt(c(0.975), df = 8) * sqrt(var.y.hat)
lwr - y.hat + qt(c(0.025), df = 8) * sqrt(var.y.hat)
hand - data.frame(cbind(y.hat, lwr, upr))

#The limits are not the same
pred
hand

--
Thank you,
Kurt

[[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] testing the multiple regression model

2013-01-30 Thread dada
Hi
I have 25 samples in my dataset. I have written a multiple regression model
and I would like to test it. 
I would like to train my model on 20 samples and then test it on 5
remaining. However I would like to test the model several times, each time
using different 5 samples out of 25 and check how well the model performs
each time. 
As I am new to R, I am not sure how the script should look like. Could you
please help me with this ? Thank you

 




--
View this message in context: 
http://r.789695.n4.nabble.com/testing-the-multiple-regression-model-tp4657119.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] fSeries not found in R

2013-01-30 Thread Yuan, Rebecca
Hello all,

When I tried to install fSeries in R, I got the following error messages:

install.packages(fSeries,dependencies=T)
Warning message:
package 'fSeries' is not available (for R version 2.15.2)

Is this package changing/merging to another package?

Thanks,

Rebecca

--
This message, and any attachments, is for the intended r...{{dropped:5}}

__
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] export figure by pdf command

2013-01-30 Thread MacQueen, Don
Works for me, so you will have to provide more information.

 x11()
 hist(rnorm(100))
 dev.copy2pdf(file='mytest.pdf')
X11 
  2 
 list.files(patt='mytest')
[1] mytest.pdf

-Don


-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 1/29/13 1:22 PM, hp wan huaping@gmail.com wrote:

Can you implement it using my provided example? I read the user guide
about dev.copy2pdf
but I still failed.

Thanks

2013/1/30 ilai ke...@math.montana.edu

 ?dev.copy2pdf

 On Tue, Jan 29, 2013 at 1:48 PM, hp wan huaping@gmail.com wrote:

 Dear R mailing listers,


 After plotting, I wanna save it as file in pdf format using
 pdf(name.pdf)
 command. It failed, but I can do it by GUI operation (file-save
as-pdf).

 e.g.

 x11()
 hist(x, breaks = 50, probability = FALSE)
 pdf(hist.pdf)

 [[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.

__
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] Programmatically give file name to a matrix

2013-01-30 Thread Kumar Mainali
Thank you Pascal and Greg for the suggestion. That is exactly what I needed!

- Kumar

On Wed, Jan 30, 2013 at 2:14 AM, Pascal Oettli kri...@ymail.com wrote:

 Hello,

 ?assign

 assign(paste(plotroc_GBM_Trn_**, i, sep=), matrix(rnorm(100),10,10))

 HTH,
 Pascal


 Le 30/01/2013 17:04, Kumar Mainali a écrit :

  I have a situation when I need to save matrix with file names that are
 programmatically created.

 for (i in levels(mergeTrn$Continent)) {
  matrix here

 # I want to save this matrix with a file name that carries i from for
 loop. The following does not work.
 paste(plotroc_GBM_Trn_, i, sep=) - matrix

 }

 Thanks,
 Kumar




-- 
Section of Integrative Biology
University of Texas at Austin
Austin, Texas 78712, USA

[[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] arithmetic and logical operators

2013-01-30 Thread Ted Harding
On 30-Jan-2013 20:39:34 Berend Hasselman wrote:
 
 On 30-01-2013, at 21:32, Dave Mitchell dmmtc...@gmail.com wrote:
 
 Why, in R, does (0.1 + 0.05)  0.15 evaluate to True?  What am I missing
 here?  How can I ensure this (ostensibly incorrect) behavior doesn't
 introduce bugs into my code?  Thanks for your time.
 
 
 R-FAQ 7.31:
 http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-num
 bers-are-equal_003f
 
 Berend

And, to put Dave's specific query into the context of that FAQ:

  (0.1 + 0.05)  0.15
  # [1] TRUE
  (0.1 + 0.05) - 0.15
  # [1] 2.775558e-17

so that tiny 2.775558e-17 is the inexactitude (due to finite
binary representation).

As an interesting variant:

  (1.0 + 0.5)  1.5
  # [1] FALSE
  (1.0 + 0.5) - 1.5
  # [1] 0

and that is because 1.0 and 0.5, and also 1.5, have exact finite
binary representations, e.g.:

  1.0 == 1.
  0.5 == 0.1000
  1.5 == 1.1000

whereas 0.1, 0.5 and 0.15 are these numbers divided by 10 = 2*5;
and while you can exactly do the /2 part (just shift right by
one binary place), you can't exactly divide by 5 in finite binary
arithmetic (any more than you can exactly divide by 3 in decimal),
because 5 is not a factor of the base (2) of the binary representation
(whereas, in decimal, both 2 and 5 are factors of 10; but 3 isn't).

Whereas R has the function all.equal() to give the right answer
for most things like

  (0.1 + 0.05) == 0.15
  # [1] FALSE
  all.equal((0.1 + 0.05), 0.15)
  # [1] TRUE

(because it tests for equality to within a very small tolerance,
by default the square root of the binary precision of a double
precision binary real number), R does not have a straightforward
method for testing the truth of (0.1 + 0.05)  0.15 (and that
is because the question is not clearly discernible from the
expression, when imprecision underlies it).

You could emulate all.equal() on the lines of

  (0.1 + 0.05)  (0.15 + .Machine$double.eps^0.5)
  # [1] FALSE
  (0.1 + 0.05)  (0.15 - .Machine$double.eps^0.5)
  # [1] FALSE

(or similar). Observe that

  .Machine$double.eps^0.5
  # [1] 1.490116e-08
  .Machine$double.eps
  # [1] 2.220446e-16

  (0.1 + 0.05) - 0.15
  # [1] 2.775558e-17

Hoping this helps,
Ted.

-
E-Mail: (Ted Harding) ted.hard...@wlandres.net
Date: 30-Jan-2013  Time: 23:22:53
This message was sent by XFMail

__
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] Packages with functionality related to Oil/Gas exploration

2013-01-30 Thread Keith Weintraub
Folks,

As the subject describes: I would like to know if there are packages that have 
functionality tailored for standard Oil/Gas exploration and monetization.

Thanks,
KW

--


[[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] XBRL data into R?

2013-01-30 Thread Anika Masters
Has anyone explored pulling XBRL formatted data into R?

[[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] Integration of mixed normal distribution

2013-01-30 Thread David Winsemius


On Jan 30, 2013, at 4:19 AM, Johannes Radinger wrote:


Hi,

I already found a conversation on the integration of a normal
distribution and two
suggested solutions
(https://stat.ethz.ch/pipermail/r-help/2007-January/124008.html):

1) integrate(dnorm, 0,1, mean = 0, sd = 1.2)

and

2) pnorm(1, mean = 0, sd = 1.2) - pnorm(0, mean = 0, sd = 1.2)

where the pnorm-approach is supposed to be faster and with higher  
precision.


I want to integrate a mixed normal distribution like:
normaldistr_1 * p + normaldistr_2 * (1-p)


I think if you check any calculus text you will find a theorem stating  
that


integral( a*f(x) + b*g(x) ) = a*integral(f(x)) + b*integral(g(x))


where p is between 0 and 1 and the means for both distributions are 0
but the standard deviations differ.

In addition, I want to get the integrals from x to infinity or from -
infinity to x for
the mixed distribution.

Can that be done with high precision in R and if yes how?


The application to this problem seems straightforward. The fact that  
you are using the range of -Inf to x should make the calculations  
easier.


--
David Winsemius, MD
Alameda, CA, USA

__
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] Packages with functionality related to Oil/Gas exploration

2013-01-30 Thread Ben Bolker
Keith Weintraub kw1958 at gmail.com writes:

 
 Folks,
 
 As the subject describes: I would like to know if there are 
 packages that have functionality tailored for
 standard Oil/Gas exploration and monetization.

  Check out the sos package: it will help you answer the
question yourself, probably more effectively than the people here ...

__
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 does predict() calculate prediction intervals?

2013-01-30 Thread Cade, Brian
Kurt:  You missed including the term 1/n in your var.y.hat calculation.  Do
that and pred and hand  are the same.

Brian

Brian S. Cade, PhD

U. S. Geological Survey
Fort Collins Science Center
2150 Centre Ave., Bldg. C
Fort Collins, CO  80526-8818

email:  brian_c...@usgs.gov
tel:  970 226-9326



On Wed, Jan 30, 2013 at 9:50 AM, Kurt Rinehart kurt.rineh...@uvm.eduwrote:

 For a given linear regression, I wish to find the 2-tailed t-dist
 probability that Y-hat = newly observed values. I generate prediction
 intervals in predict() for plotting, but when I calculate my t-dist
 probabilities, they don't agree. I have researched the issues with variance
 of individual predictions and been advised to use the variance formula
 below (in the code).

 I presume my variance function differs from that used in predict(). Can
 someone advise me as to why I cannot reproduce the results of predict()?

 As a test, I calculated the prediction intervals about Y-hat by hand and
 compared them to predict():

 X - log10(c(780,54,520,703,1356,1900,2500,741,1500,600))
 Y -
 log10(c(0.037,0.036,0.026,0.0315,0.028,0.0099,0.00955,0.0405,0.019,0.0245))
 dat - data.frame(cbind(X, Y))
 mod - lm(Y ~ X, data = dat)
 rm(X,Y)

 ## model predictions, y.hat, at the new X values
 pred - data.frame(predict.lm(mod,newdata = obs, interval = prediction,
 level = 0.95))

 # 3 subsequent observations
 obs - log10(data.frame(cbind(c(40, 200, 450), c(0.3, 0.06, .034
 names(obs) - c(X, Y)

 ## Calculating t-dist, 2-tailed, 95% prediction intervals for new
 observations
 mse - anova(mod)[2,3]
 new.x - obs$X - mean(dat$X)
 sum.x2 - sum((dat$X - mean(dat$X))^2)
 y.hat - pred$fit
 var.y.hat - mse*(1+new.x^2/sum.x2)

 upr - y.hat + qt(c(0.975), df = 8) * sqrt(var.y.hat)
 lwr - y.hat + qt(c(0.025), df = 8) * sqrt(var.y.hat)
 hand - data.frame(cbind(y.hat, lwr, upr))

 #The limits are not the same
 pred
 hand

 --
 Thank you,
 Kurt

 [[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.


[R] betadisper plot

2013-01-30 Thread Myra Juckers




Hello,

I tried to make a betadisper plot; however, it is quite messy at the moment 
with lines and symbols. 
I made two plots, one focusing on sites and the other on treatments.
This is the code that I used:

plot(betadisper(vegdist(y.nth,method=euclidean),site))
plot(betadisper(vegdist(y.nth,method=euclidean),treatment))

I have a few questions pertaining to how I could clean up the figures for 
interpretation purposes:
How would I be able to place labels on the centroids, which would enable me to 
identify which centroid is associated with which site or treatment?
How do I remove the lines emerging from each of the centroids?
Is it possible to display labels of the y-variables used in making the figure. 
Because the centroids indicate site or treatment which are the independent 
variables, but would it also be possible to display the distribution of 
y-variables? 

Thank you,
Myra



  
[[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] Writing audio files (.wav) in a different directory

2013-01-30 Thread Humberto Mohr
Hi.

I'm trying to export a .wav file using the writeWave function from tuneR
package in a different folder than the default getwd().
After reading through the manuals of some audio packages I couldn't figure
it out.

I'm picking one 3-hour .wav file and asking the function to take a sample
of 1 minute (from minute 100 to minute 101 of the 3-hour file) and saving
it in an object rec.

Here is what I'm doing:

 filename-QUm0B24x_SMS05_20100831_052100.wav
 min.ini-100
 min.fin-101

 library(tuneR)
 rec-readWave(filename,min.ini,min.fin,minutes)
 writeWave(rec,cut1.wav)

It is writing the file in the same directory of the filename object. What
I want to do is to write the cut1.wav file in a different folder.

Any suggestions?

Thanks in advance!

-- 
*Humberto Mohr*
*
*
Mestrando do PPG-Ecologia do Instituto Nacional de Pesquisas da Amazônia
(INPA)
Graduate student of the Master Program in Ecology in the National Institute
of Amazon Research (INPA)

[[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] Writing audio files (.wav) in a different directory

2013-01-30 Thread Humberto Mohr
   Hi.


 I'm trying to export a .wav file using the writeWave function from tuneR
 package in a different folder than the default getwd().
 After reading through the manuals of some audio packages I couldn't figure
 it out.

 I'm picking one 3-hour .wav file and asking the function to take a sample
 of 1 minute (from minute 100 to minute 101 of the 3-hour file) and saving
 it in an object rec.

 Here is what I'm doing:

  filename-QUm0B24x_SMS05_20100831_052100.wav
  min.ini-100
  min.fin-101

  library(tuneR)
  rec-readWave(filename,min.ini,min.fin,minutes)
  writeWave(rec,cut1.wav)

 It is writing the file in the same directory of the filename object.
 What I want to do is to write the cut1.wav file in a different folder.

 Any suggestions?

 Thanks in advance!

 --
 *Humberto Mohr*
 *
 *
 Mestrando do PPG-Ecologia do Instituto Nacional de Pesquisas da Amazônia
 (INPA)
 Graduate student of the Master Program in Ecology in the National
 Institute of Amazon Research (INPA)


[[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] Please, problem using “bcPower”

2013-01-30 Thread Beatriz González
Hello,

I would like to perform a Box-Cox (“bcPower”) transformation on my data. 
For this, I am determining lambda using the “powerTransform” function. 
However, with one of my variables I get the following 

Warning Message:
In estimateTransform(x, y, NULL, ...) :
  Convergence failure: return code = 52 My variable is: 
 x
 [1] 0.0001031130 0.0001029480 0.0001040010 0.0001037940 0.0001046280 
0.927650 0.942960
 [8] 0.950250 0.949780 0.988210 0.975860 0.962850 
0.0001015800 0.0001009190
[15] 0.0001035350 0.0001033210 0.0001028420 0.0001023150 0.0001033000 
0.0001036910 0.0001026890
[22] 0.0001032480 0.0001012160 0.0001031270 0.0001034390 0.0001028180 
0.0001034820 0.0001022700
[29] 0.0001042640 0.0001046720 0.0001045860 0.0001045160 0.0001045850 
0.0001038040 0.0001037020
[36] 0.0001034050 0.0001048150 0.0001017180 0.0001017920 0.0001032730 
0.0001029420 0.0001025220
[43] 0.0001031490 0.0001036995 0.0001039735 0.0001014877 0.0001027960 And my 
code is:dlambda - powerTransform(x) #It is here where I get the warning message
x_BCx - bcPower(x, lambda= dlambda$lambda, jacobian.adjusted= FALSE)
 Does anyone know why I may be getting this Warning Message?  If you require 
more details please get in touch.

Many thanks in advance!

Bea
[[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] Package name

2013-01-30 Thread Ortiz, John

Dear list,

Can I use a character to set the name of a R package? like this (-)

for example (sdp-R)

Thanks,

John
__
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] Writing audio files (.wav) in a different directory

2013-01-30 Thread Jeff Newmiller
Put the directory name into the filename string. The syntax for doing that is 
somewhat OS dependent, but for most cases you can use / as the separator. You 
really should Google file path and your OS and learn how to do this, because 
it is broadly applicable outside of R (not an R-help question). Look for info 
on absolute path and relative path.
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Humberto Mohr humberto.m...@gmail.com wrote:

Hi.

I'm trying to export a .wav file using the writeWave function from
tuneR
package in a different folder than the default getwd().
After reading through the manuals of some audio packages I couldn't
figure
it out.

I'm picking one 3-hour .wav file and asking the function to take a
sample
of 1 minute (from minute 100 to minute 101 of the 3-hour file) and
saving
it in an object rec.

Here is what I'm doing:

 filename-QUm0B24x_SMS05_20100831_052100.wav
 min.ini-100
 min.fin-101

 library(tuneR)
 rec-readWave(filename,min.ini,min.fin,minutes)
 writeWave(rec,cut1.wav)

It is writing the file in the same directory of the filename object.
What
I want to do is to write the cut1.wav file in a different folder.

Any suggestions?

Thanks in advance!

__
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] Add axes to a 3D scene (afer makeTriangles)

2013-01-30 Thread Christophe Genolini

Hi David,

Thanks for your answer.
Here is my (simplified) code :

 8 -
library(misc3d)

#
### Fonction that draw a point A=(x,y,z), with radius r

misc3dPoint - function(A,r,color=black,alpha=1){
   t1 - c(A[1]+r,A[2],A[3],A[1],A[2]+r,A[3],A[1],A[2],A[3]+r)
   t2 - c(A[1]+r,A[2],A[3],A[1],A[2]+r,A[3],A[1],A[2],A[3]-r)
   t3 - c(A[1]+r,A[2],A[3],A[1],A[2]-r,A[3],A[1],A[2],A[3]+r)
   t4 - c(A[1]+r,A[2],A[3],A[1],A[2]-r,A[3],A[1],A[2],A[3]-r)
   t5 - c(A[1]-r,A[2],A[3],A[1],A[2]+r,A[3],A[1],A[2],A[3]+r)
   t6 - c(A[1]-r,A[2],A[3],A[1],A[2]+r,A[3],A[1],A[2],A[3]-r)
   t7 - c(A[1]-r,A[2],A[3],A[1],A[2]-r,A[3],A[1],A[2],A[3]+r)
   t8 - c(A[1]-r,A[2],A[3],A[1],A[2]-r,A[3],A[1],A[2],A[3]-r)
return(data.frame(rbind(t1,t2,t3,t4,t5,t6,t7,t8),color=color,alpha=alpha))
}

#
### Fonction that draw several points MA=(A,B,C,D,...)

misc3dPoints - function(MA,r,color=black,alpha=1){
   dataV - data.frame()
   if(length(r)==1){r - rep(r,ncol(MA))}else{}
   if(length(color)==1){color - rep(color,ncol(MA))}else{}
   if(length(alpha)==1){alpha - rep(alpha,ncol(MA))}else{}
   for(i in 1:ncol(MA)){
   dataV - 
rbind(dataV,misc3dPoint(MA[,i],r[i],color=color[i],alpha=alpha[i]))
   }
   return(dataV)
}

### Some points (points are in colomn)
MA - 
cbind(c(3.5,3.5,3.5),c(3,2,1),c(1.5,1,0.5),c(0.3,0.3,0.3),c(0,0,0),c(4,4,4))[3:1,]

### The radius of the points
r = 0.3

### Building the list of triangle3d from the points
listOfTriangles - misc3dPoints(MA,r,color=c(1:4,1,1),alpha=c(1,1,1,1,0,0))

### Making the scene
myScene - makeTriangles(
  v1=as.matrix(listOfTriangles[,1:3]),
  v2=as.matrix(listOfTriangles[,4:6]),
  v3=as.matrix(listOfTriangles[,7:9]),
  color=listOfTriangles$color,alpha=listOfTriangles$alpha
)

### Drawing the scene
drawScene.rgl(myScene,xlim=c(0,4),ylim=c(0,4),zlim=c(0,4))

### Then, I export the triangles into an asy file (with is the final pupose of 
all this)
library(longitudinalData)
saveTrianglessASY(myScene)

 8 -

So I rewrite my question: is it possible to add some axes to the myScene 
object?

Christophe



On Jan 30, 2013, at 3:09 AM, cgenolin wrote:


Hi all,

I am drawing some 3D surfaces using the Triangle tools (package misc3) and
drawScene.rgl. Do you know if it is possible to add axes and graduation on
the scene?



You offer no code or data,  so a specific answer is not called for. Certainly the specific answer 
to the possibility of labels in rgl graph is is yes. You might learn something by looking at the 
work that Ben Bolker and I put into a question requesting labels on the scatter3d function in 
package car;


http://stackoverflow.com/questions/8204972/carscatter3d-in-r-labeling-axis-better/8206320#8206320




--
Christophe Genolini
Maître de conférences en bio-statistique
Vice président Communication interne et animation du campus
Université Paris Ouest Nanterre La Défense

__
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.