[R] R for Reuters
Can we download data of Reuters from R? Just like we have RBloomberg, do we have something like RReuters? Is this under the developing stage? [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] t-test
John Mason wrote: I have downloaded the latest version of R and continue to have the same problem I did with the previuos version which is that I am unable to run a two-sample t-test in R-commander. I can run a paired t-test and a one sample t-test but not a two-sample t-test or one factor ANOVA. The data have been both imported and entered directly into R-cmdr and I can run regressions and basic data summaries on these data but not the t-tests described above. Any ideas? Windows XP on a Dell built within last year. John Have you converted your grouping variables to factors? Rcmdr is pretty insistent on that point. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] BradleyTerry subscript out of bounds
I don't see the problem with the following... the citations and baseball data work fine, but my simulated data seems to give BTm a headache. What am I missing? --- library(BradleyTerry) library(doBy) ng - 100 players - factor( sort( c( jeff, mike, paul, rich ) ) ) np - length( players ) p1 - factor( c( rep( jeff, ng ) , rep( levels( players ), np ) ) , levels=players ) p2 - factor( c( rep( mike, ng ) , rep( levels( players ), each=np ) ) , levels=players ) p1s - c( rnorm( n=ng, mean=-0.5, sd=2 ), rep( 1, np^2 ) ) p2s - c( rnorm( n=ng, mean=0.5, sd=2 ), rep( 0, np^2 ) ) results - data.frame( winner=factor( levels(players)[ ifelse(p1sp2s,p2,p1)], levels=players ) , loser=factor( levels(players)[ ifelse(p1sp2s,p1,p2) ], levels=players) , Freq=c( rep( 1, ng ), rep( 1, np^2) ) ) results - summaryBy(Freq ~ winner + loser, data=results, FUN=c(sum) ) attr(results, names) - c( winner, loser, Freq ) results.btm - BTm( results ~ .. ) # this spits out an error: Error in BTm(results ~ ..) : subscript out of bounds sessionInfo() R version 2.0.1, 2004-11-15, i386-pc-linux-gnu attached base packages: [1] methods stats graphics grDevices utils datasets [7] base other attached packages: BradleyTerry brlr doByHmisc 0.8-5 0.8-81.6 3.0-1 I have also tried this on Windows XP with R version 2.3.1 with same result. -- --- Jeff NewmillerThe . . Go Live... DCN:[EMAIL PROTECTED]Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Help with histograms
The iPlots package provides interactive graphics. One way to to what you want to do would be to create a variable with all values and a second binary variable recording which are the 16 special cases. Draw an interactive histogram of the first with ihist and an interactive barchart of the second with ibar. Then click on the bar for the 16 special cases. Antony __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] strange logical results
Dear R People: I am getting some odd results when using logical operators: x - seq(from=-1,to=1,by=0.1) x [1] -1.0 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 [16] 0.5 0.6 0.7 0.8 0.9 1.0 x == -1 [1] TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE x == -0.9 [1] FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE x == -0.8 [1] FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE x == -0.7 [1] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE x == -0.6 [1] FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE x == -0.5 [1] FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE x == -0.4 [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE Should this show as true also, please? I saw this in both Windows and LINUX Versions 2.4.0 Thanks in advance, Sincerely, Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] strange logical results
Erin Hodgess wrote: Dear R People: I am getting some odd results when using logical operators: x - seq(from=-1,to=1,by=0.1) x [1] -1.0 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 [16] 0.5 0.6 0.7 0.8 0.9 1.0 x == -1 [1] TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE x == -0.9 [1] FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE x == -0.8 [1] FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE x == -0.7 [1] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE x == -0.6 [1] FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE x == -0.5 [1] FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE x == -0.4 [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE Should this show as true also, please? They are not exactly equal. You could use all.equal() to test for nearly equal. x[7] == -0.4 [1] FALSE all.equal(x[7], -0.4) [1] TRUE all.equal(x[7], -0.4, tol = 0) [1] Mean relative difference: 2.775558e-16 I saw this in both Windows and LINUX Versions 2.4.0 Thanks in advance, Sincerely, Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Error message using normality test in vars
I'm running a vector-time series model with the vars package. When I test the univariate and multivariate normality of the residuals using normality(), I get the results, but also this warning Warning messages: 1: longer object length is not a multiple of shorter object length in: b2 - rep(3, 4) 2: longer object length is not a multiple of shorter object length in: b2 - rep(3, 4) What does this mean and do I need to worry about it. Dear David, thanks for pointing this out. The warning is caused in the calculation of the kurtosis in function .jb.multi which is contained in R/internal.R. The relevant expression should be 'rep(3, K)'. An updated version of package 'vars' will be submitted in due course. I will ship you version of the corrected package off list. Best, Bernhard * Confidentiality Note: The information contained in this mess...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] What's meaning of the lambda in nlrq output
I used the nlrq function in the package quantreg. There is a lambda in the output when I set trace=TRUE. With different start point, the results are converged, but the last lambda is different. I want to know the meaning lambda=1 and lambda=0. Many Thanks! Examples of output 1. Where the last lambda=1: 108.6581 : 0.3 8.0 iter0 value 108.658087 final value 49.875178 converged lambda = 0.6304686 49.87518 : 0.3539175 5.6116474 iter0 value 48.123700 final value 48.120120 converged lambda = 0.7646881 48.12012 : 0.4701847 6.4582566 iter0 value 47.833255 final value 47.832257 converged lambda = 0.8588522 47.83226 : 0.5052472 6.8564865 final value 47.802009 converged lambda = 1 47.80201 : 0.5257616 7.0207726 iter0 value 47.776363 final value 47.747994 stopped after 4 iterations lambda = 0.5044797 47.74799 : 0.5474859 7.1612348 final value 47.746067 converged lambda = 1 47.74607 : 0.5503345 7.1881443 iter0 value 47.746099 final value 47.746099 converged lambda = 0.999864 47.7461 : 0.5502692 7.1879762 2. Where the last lambda=0: 54.16497 : 0.6 8.0 iter0 value 54.164967 final value 47.768140 converged lambda = 0.2133083 47.76814 : 0.5560481 7.2205976 iter0 value 47.768140 final value 47.767343 converged lambda = 0.004997877 47.76734 : 0.5557633 7.2172873 iter0 value 47.787967 final value 47.747700 stopped after 3 iterations lambda = 0.1719594 47.7477 : 0.547935 7.165428 iter0 value 47.799883 final value 47.747700 converged lambda = 0 47.7477 : 0.547935 7.165428 -- Shg SUN @China __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] R for Reuters
Hi Shubha, There is no reuter link in R. It does not exist in Splus either nor in matlab. Apparently this is a legal type of issue from reuter who is keeping its data proprietary. AA. - Original Message From: Shubha Vishwanath Karanth [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Sent: Friday, December 29, 2006 3:44:01 AM Subject: [R] R for Reuters Can we download data of Reuters from R? Just like we have RBloomberg, do we have something like RReuters? Is this under the developing stage? [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] CV by rpart/mvpart
The rpart function allows one to give the cross-validation groups explicitly. So if the number of observations was 10, you could use rpart( y ~ x1 + x2, data=mydata, xval=c(1,1,2,2,3,3,1,3,2,1)) which causes observations 1,2,7, and 10 to be left out of the first xval sample, 3,4, and 9 out of the second, etc. I was going to write read the manual page for control.rpart, but it seems I forgot to put this feature into the documentation! Terry Therneau On 12/28/06, Pedro Ramirez [EMAIL PROTECTED] wrote: Dear R-list, I am using the rpart/mvpart-package for selecting a right-sized regression tree by 10-fold cross-validation. My question: Is there a possibility to find out for every observation in which of the ten folds it is lying? I want to use the same folds for validating another regression method (moving averages) in order to choose the better one. Thanks a lot, Pedro __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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 debug R program?
On Loops: The apply coomands are better, faster than loops. If there are lots of loops or nested loops then you should be able to replace some of the loops with an apply command. If you have nested loops I'd recommend replacing loops on the inside first. R seems better designed using the apply commands. It seems to be optimized for memory usage. I found this especially true when I was doing numerical analysis and/or boot strap types of things. Quotes from help: Description: Returns a vector or array or list of values obtained by applying a function to margins of an array. good luck I wrote a R program which has loops. When I run the program, it crashed. I would like to identify in which loop the pragram crashed, how can I debug ? I'm new to R, could somebody please give me a general idea about debugging in R.(I'm a C/C++ programmer and have general knowledge about program debugging.) Thank you! Best, __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] problems with arima()
Hi! I have problems with the function arima(), it takes too much time to run (15 minuts) it is normal? for example I put: a-arima(d7,c(0,0,5),seasonal=list(order=c(0,1,2),period=7)) where d7 is a daily time serie with 3600 observations Are there another function to modelize 2 seasonalities at the same time? another question : When I add a matrix to regresion the function arima() shows an error : Erro en optim(init[mask], armaCSS, method = BFGS, hessian = FALSE, : valor no finito provisto por optim what happen? how can I do to regres a matrix with artificial variables in the model sarima? [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] strange logical results
This is FAQ 7.31 in the R FAQ. Basically computers in general have problems exactly representing all but a few floating point numbers, so while 2 numbers may look the same when displayed (rounded to a couple of digits), they are different if you look at them in full precision due to different roundings. Functions like all.equal deal with this by checking to see if numbers are close enough rather than equal. The general rule is to not expect exact equality between floating point numbers. This is a problem for computers in general, not just R. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Erin Hodgess Sent: Friday, December 29, 2006 3:36 AM To: r-help@stat.math.ethz.ch Subject: [R] strange logical results Dear R People: I am getting some odd results when using logical operators: x - seq(from=-1,to=1,by=0.1) x [1] -1.0 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 [16] 0.5 0.6 0.7 0.8 0.9 1.0 x == -1 [1] TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE x == -0.9 [1] FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE x == -0.8 [1] FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE x == -0.7 [1] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE x == -0.6 [1] FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE x == -0.5 [1] FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE x == -0.4 [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE Should this show as true also, please? I saw this in both Windows and LINUX Versions 2.4.0 Thanks in advance, Sincerely, Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Why giving negative density when doing kernel density estimate?
Why? And how to solve it? The code and result are following, data=rnorm(50) kde=density(data,n=20,from=-1,to=10) kde$x;kde$y [1] -1.000 -0.4210526 0.1578947 0.7368421 1.3157895 1.8947368 [7] 2.4736842 3.0526316 3.6315789 4.2105263 4.7894737 5.3684211 [13] 5.9473684 6.5263158 7.1052632 7.6842105 8.2631579 8.8421053 [19] 9.4210526 10.000 [1] 2.422392e-01 3.877025e-01 4.746580e-01 2.757747e-01 1.787630e-01 [6] 1.102396e-01 2.331694e-02 3.294412e-04 2.260746e-07 6.996146e-12 [11] -1.179461e-18 -1.226790e-17 8.892545e-18 1.144173e-17 -1.881253e-17 [16] -2.782621e-17 -5.314722e-18 -1.691545e-17 -1.986261e-17 -2.498227e-17 Best, Junjie Li Tsinghua Univercity [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] coded to categorical variables in a large dataset
I am working with a dataset where there are 5 possible outcomes (coded 1:5), I would like to create 5 categorical variables (event1...event5). I am using a for loop an if statements, but I have a large dataset( approx 100,000 rows) it takes quite a bit of time, is there a way to speed this up? Here is some sample code of what I am currently doing. test2 -rep(seq(1:5),2000) event1 - rep(0,nrow(test2)) event2 - rep(0,nrow(test2)) event3 - rep(0,nrow(test2)) event4 - rep(0,nrow(test2)) event5 - rep(0,nrow(test2)) for(i in 1:length(event1)) { if (test2[i]==1) { event1[i]=1 } if (test2[i]==2) { event2[i]=1 } if (test2[i]==3) { event3[i]=1 } if (test2[i]==4) { event4[i]=1 } if (test2[i]==5) { event5[i]=1 } } thanks, Spencer [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] coded to categorical variables in a large dataset
sj wrote: I am working with a dataset where there are 5 possible outcomes (coded 1:5), I would like to create 5 categorical variables (event1...event5). I am using a for loop an if statements, but I have a large dataset( approx 100,000 rows) it takes quite a bit of time, is there a way to speed this up? Here is some sample code of what I am currently doing. Here is one way you might do it: X - sample(1:5, 100, replace=TRUE) # Your 5 event variables in a matrix model.matrix(lm(rnorm(length(X)) ~ as.factor(X) - 1)) Also, along the lines of your approach below, the following using ifelse() might be better: event3 - ifelse(test2 == 3, 1, 0) I'm sure other people will post different solutions probably more elegant than these. test2 -rep(seq(1:5),2000) event1 - rep(0,nrow(test2)) event2 - rep(0,nrow(test2)) event3 - rep(0,nrow(test2)) event4 - rep(0,nrow(test2)) event5 - rep(0,nrow(test2)) for(i in 1:length(event1)) { if (test2[i]==1) { event1[i]=1 } if (test2[i]==2) { event2[i]=1 } if (test2[i]==3) { event3[i]=1 } if (test2[i]==4) { event4[i]=1 } if (test2[i]==5) { event5[i]=1 } } thanks, Spencer [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] coded to categorical variables in a large dataset
## The main reason for wanting such a coding is to use it in ## a linear model. Therefore, declare the variable to be a factor ## and use it directly. tmp - sample(1:5, 40, replace=TRUE) tmpf - factor(tmp) tmp.y - rnorm(40) tmp.aov - aov(tmp.y ~ tmpf) summary(tmp.aov) contrasts(tmpf) update(tmp.aov, x=TRUE)$x[1:6,] ## If you really want to see the redundant column 1 of ## of the contrasts, that can be done with the statement contrasts(tmpf) contrasts(tmpf, how.many=5) - contr.treatment(5, contrasts=FALSE) contrasts(tmpf) tmp2.aov - aov(tmp.y ~ tmpf) summary(tmp2.aov) update(tmp2.aov, x=TRUE)$x[1:6,] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] coded to categorical variables in a large dataset
try this: test2 - rep(seq(1:5),2000) #setup a data frame and index into the columns result - data.frame(event1=rep(0,length(test2)), event2=rep(0,length(test2)), + event3=rep(0,length(test2)), event4=rep(0,length(test2)), event5=rep(0,length(test2))) for (i in seq(ncol(result))){ + result[[i]] - ifelse(test2 == i, 1, 0) + } str(result) 'data.frame': 1 obs. of 5 variables: $ event1: num 1 0 0 0 0 1 0 0 0 0 ... $ event2: num 0 1 0 0 0 0 1 0 0 0 ... $ event3: num 0 0 1 0 0 0 0 1 0 0 ... $ event4: num 0 0 0 1 0 0 0 0 1 0 ... $ event5: num 0 0 0 0 1 0 0 0 0 1 ... On 12/29/06, sj [EMAIL PROTECTED] wrote: I am working with a dataset where there are 5 possible outcomes (coded 1:5), I would like to create 5 categorical variables (event1...event5). I am using a for loop an if statements, but I have a large dataset( approx 100,000 rows) it takes quite a bit of time, is there a way to speed this up? Here is some sample code of what I am currently doing. test2 -rep(seq(1:5),2000) event1 - rep(0,nrow(test2)) event2 - rep(0,nrow(test2)) event3 - rep(0,nrow(test2)) event4 - rep(0,nrow(test2)) event5 - rep(0,nrow(test2)) for(i in 1:length(event1)) { if (test2[i]==1) { event1[i]=1 } if (test2[i]==2) { event2[i]=1 } if (test2[i]==3) { event3[i]=1 } if (test2[i]==4) { event4[i]=1 } if (test2[i]==5) { event5[i]=1 } } thanks, Spencer [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Difference of array and vector
Hi, I am really new at R. Does anyone know what is the real difference of vector and array, except that many operations that expect an array does not work on a vector? Thanks, Geoffrey ___=0A= =0A= =0A= The information in this email or in any file attached hereto is=0A= intended only for the personal and confidential use of the individual=0A= or entity to which it is addressed and may contain information that is=0A= proprietary and confidential. If you are not the intended recipient of=0A= this message you are hereby notified that any review, dissemination,=0A= distribution or copying of this message is strictly prohibited. This communi= cation is for information purposes only and should not be regarded as an off= er to sell or as a solicitation of an offer to buy any financial product. Em= ail transmission cannot be guaranteed to be secure or error-free. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] coded to categorical variables in a large dataset
As Richard has already pointed out you may only need to convert your numeric vector to a factor but just in case here are a few direct answers: Using X from Chuck's post here are two ways of creating a 100x5 matrix of indicator variables: model.matrix(~ X-1, list(X = factor(X))) outer(X, 1:5, ==)+0 # To create eventi variables # here is a way of creating them event1 - (X == 1) + 0 # and similarly for 2, 3, 4, 5 # or do it in a loop for(i in 1:5) assign(paste(event, i, sep = ), (X == i) + 0) # or create as columns of a data frame f - function(i, j) (X == j) + 0 as.data.frame(mapply(f, paste(event, 1:5, sep = ), 1:5)) On 12/29/06, sj [EMAIL PROTECTED] wrote: I am working with a dataset where there are 5 possible outcomes (coded 1:5), I would like to create 5 categorical variables (event1...event5). I am using a for loop an if statements, but I have a large dataset( approx 100,000 rows) it takes quite a bit of time, is there a way to speed this up? Here is some sample code of what I am currently doing. test2 -rep(seq(1:5),2000) event1 - rep(0,nrow(test2)) event2 - rep(0,nrow(test2)) event3 - rep(0,nrow(test2)) event4 - rep(0,nrow(test2)) event5 - rep(0,nrow(test2)) for(i in 1:length(event1)) { if (test2[i]==1) { event1[i]=1 } if (test2[i]==2) { event2[i]=1 } if (test2[i]==3) { event3[i]=1 } if (test2[i]==4) { event4[i]=1 } if (test2[i]==5) { event5[i]=1 } } thanks, Spencer [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] OT: any recommendation for scripting language
Wensui Liu [EMAIL PROTECTED] wrote: Right now, I am using SAS and S+/R. As a new year resolution, I am planning to learn a scripting language. from statisticians' point of view, which scripting language is worth to learn, perl, python, or any other recommendation? (Most likely, I will be learning it in windows.) Since I am not in research, I will prefer one widely used in industry and related to statistical work. I would second the recommendation by John Bollinger to look into Python. I haven't used Ruby, so I can't compare the two languages, but compared to Perl, Python has is considerably easier to understand and maintain. The language is widely used and is available on several platforms. The Python Web site includes tutorials, and the download includes an IDE with an interface to extensive help files. http://www.python.org/ -- Mike Prager, NOAA, Beaufort, NC * Opinions expressed are personal and not represented otherwise. * Any use of tradenames does not constitute a NOAA endorsement. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Difference of array and vector
On Dec 29, 2006, at 2:16 PM, Geoffrey Zhu wrote: Does anyone know what is the real difference of vector and array? # Here's a vector: letv - letters is.vector(letv) # Here's an array: leta - as.array(letters) is.array(leta) attributes(letv) attributes(leta) To understand the importance of attributes: http://www.burns-stat.com/pages/Spoetry/essentials.pdf There Burns writes (p. 3): An S array is merely a vector that has a dim attribute, and optionally a dimnames attribute. _ Professor Michael Kubovy University of Virginia Department of Psychology USPS: P.O.Box 400400Charlottesville, VA 22904-4400 Parcels:Room 102Gilmer Hall McCormick RoadCharlottesville, VA 22903 Office:B011+1-434-982-4729 Lab:B019+1-434-982-4751 Fax:+1-434-982-4766 WWW:http://www.people.virginia.edu/~mk9y/ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Failure loading library into second R 2.3.1 session on Windows XP
Hi. I am using R 2.3.1 on Windows XP. I had installed a library package into my first session and wanted the same package in my second session, so I went out to the CRAN mirror and tried to install the package, and got the following message: * utils:::menuInstallPkgs() trying URL 'http://cran.ssds.ucdavis.edu/bin/windows/contrib/2.3/corpcor_1.4.4.zip' Content type 'application/zip' length 133068 bytes opened URL downloaded 129Kb package 'corpcor' successfully unpacked and MD5 sums checked Warning: cannot remove prior installation of package 'corpcor' The downloaded packages are in C:\Documents and Settings\Talbot\Local Settings\Temp\RtmplCxarb\downloaded_packages updating HTML package descriptions library(corpcor) Error in library(corpcor) : there is no package called 'corpcor' * After rebooting my machine, I dug into this a little further. Upon installing a package from a CRAN mirror, it seems to stay on my hard drive, and I can load it in subsequent sessions from the Load package... menu without going back to get it from a CRAN mirror. However, if I do happen to retrieve it again from a CRAN mirror, it appears that may corrupt the version that was saved, and it no longer will be available from the Load package... menu. A reboot and re-retrieval of the package makes it available again; I don't know whether there's any less drastic solution. This behavior doesn't occur with every package, but I have experienced it with two different packages (corpcor and copula), so there seems to be something going on. I didn't see anything in the FAQ page about this, I wonder if anyone can tell me more about this issue. Thanks! -- TMK -- 212-460-5430home 917-656-5351cell __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] installation problems
Hi, I installed R-2.4.0 and R-2.4.1 on linux redhat (RHEL 3.0), and am encountering the following messages below. I searched the R FAQs and over the net, but couldn't find helpful information. When I check-all I do see some diff's (e.g., for stats, nls.Rout and nls.Rout.save in tests/stats.Rcheck/tests; cluster; and rpart'). I don't know if this is relevant. I have no problem with R-2.0.1, which I installed 1 1/2 years ago, and the Windows version. But I would like to use the recent versions. I would greatly appreciate any help. Thanks in advance. -Halim Damerdji % path_to_R_script/R R version 2.4.0 (2006-10-03) Copyright (C) 2006 The R Foundation for Statistical Computing ISBN 3-900051-07-0 == etc. Type 'q()' to quit R. Error in `parent.env-`(`*tmp*`, value = NULL) : use of NULL environment is defunct == twice In addition: Warning message: package utils in options(defaultPackages) was not found Error in `parent.env-`(`*tmp*`, value = NULL) : use of NULL environment is defunct == same for graphics In addition: Warning message: package stats in options(defaultPackages) was not found == same for methods help() Error : Could not find function help x - rnorm(20) Error : Could not find function rnorm [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] installation problems
Halim Damerdji wrote: Hi, I installed R-2.4.0 and R-2.4.1 on linux redhat (RHEL 3.0), and am encountering the following messages below. I searched the R FAQs and over the net, but couldn't find helpful information. When I check-all I do see some diff's (e.g., for stats, nls.Rout and nls.Rout.save in tests/stats.Rcheck/tests; cluster; and rpart'). I don't know if this is relevant. Minor differences due to numerical inaccuracies in the last digits are expected. For the error below: You have probably some old workspace or a library with outdated packages around. Delete and try again. Best, Uwe Ligges I have no problem with R-2.0.1, which I installed 1 1/2 years ago, and the Windows version. But I would like to use the recent versions. I would greatly appreciate any help. Thanks in advance. -Halim Damerdji % path_to_R_script/R R version 2.4.0 (2006-10-03) Copyright (C) 2006 The R Foundation for Statistical Computing ISBN 3-900051-07-0 == etc. Type 'q()' to quit R. Error in `parent.env-`(`*tmp*`, value = NULL) : use of NULL environment is defunct == twice In addition: Warning message: package utils in options(defaultPackages) was not found Error in `parent.env-`(`*tmp*`, value = NULL) : use of NULL environment is defunct == same for graphics In addition: Warning message: package stats in options(defaultPackages) was not found == same for methods help() Error : Could not find function help x - rnorm(20) Error : Could not find function rnorm [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Difference of array and vector
I had had problems getting my head around what an array was as opposed to a data frame and where vectors fitted into the two. I found a useful URL on the same website eluded to below. http://www.burns-stat.com/pages/Tutor/unwilling_S.pdf Go to the heading The Look and Feel of Objects Farrel Michael Kubovy [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] # Here's a vector: letv - letters is.vector(letv) # Here's an array: leta - as.array(letters) is.array(leta) attributes(letv) attributes(leta) To understand the importance of attributes: http://www.burns-stat.com/pages/Spoetry/essentials.pdf There Burns writes (p. 3): An S array is merely a vector that has a dim attribute, and optionally a dimnames attribute. _ Professor Michael Kubovy University of Virginia Department of Psychology USPS: P.O.Box 400400Charlottesville, VA 22904-4400 Parcels:Room 102Gilmer Hall McCormick RoadCharlottesville, VA 22903 Office:B011+1-434-982-4729 Lab:B019+1-434-982-4751 Fax:+1-434-982-4766 WWW:http://www.people.virginia.edu/~mk9y/ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Failure loading library into second R 2.3.1 session on Windows XP
You can only expect that update / reinstall a ***package*** works if you have not yet loaded it into your R session. Hence close R, start it without loading the relevant package and then update/reinstall. Best, Uwe Ligges Talbot Katz wrote: Hi. I am using R 2.3.1 on Windows XP. I had installed a library package into my first session and wanted the same package in my second session, so I went out to the CRAN mirror and tried to install the package, and got the following message: * utils:::menuInstallPkgs() trying URL 'http://cran.ssds.ucdavis.edu/bin/windows/contrib/2.3/corpcor_1.4.4.zip' Content type 'application/zip' length 133068 bytes opened URL downloaded 129Kb package 'corpcor' successfully unpacked and MD5 sums checked Warning: cannot remove prior installation of package 'corpcor' The downloaded packages are in C:\Documents and Settings\Talbot\Local Settings\Temp\RtmplCxarb\downloaded_packages updating HTML package descriptions library(corpcor) Error in library(corpcor) : there is no package called 'corpcor' * After rebooting my machine, I dug into this a little further. Upon installing a package from a CRAN mirror, it seems to stay on my hard drive, and I can load it in subsequent sessions from the Load package... menu without going back to get it from a CRAN mirror. However, if I do happen to retrieve it again from a CRAN mirror, it appears that may corrupt the version that was saved, and it no longer will be available from the Load package... menu. A reboot and re-retrieval of the package makes it available again; I don't know whether there's any less drastic solution. This behavior doesn't occur with every package, but I have experienced it with two different packages (corpcor and copula), so there seems to be something going on. I didn't see anything in the FAQ page about this, I wonder if anyone can tell me more about this issue. Thanks! -- TMK -- 212-460-5430 home 917-656-5351 cell __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Survfit with a coxph object
I am fitting a coxph model on a large dataset (approx 100,000 patients), and then trying to estimate the survival curves for several new patients based on the coxph object using survfit. When I run coxph I get the coxph object back fairly quickly however when I try to run survfit it does not come back. I am wondering if their is a more efficient way to get predicted survival curves from a coxph object.predict.coxph does not seem to generate survival curves. here is some sample code that mirrors what I am trying to do with my dataset, I get results using this code but it still takes a long time, my dataset includes quite a few more covariates, so any suggestions on speeding this up would be greatly appreciated. library(survival) ### generate sample data time - rexp(10,(1/180)) ag - rnorm(10,38,12) sx - sample(x=c(0,1),10,replace=TRUE) ac - factor(sample(x=c(1,2,3,4,5),10,replace=TRUE),levels=c(1:5)) ev - sample(x=c(0,1),10,replace=TRUE) c1 - as.data.frame(cbind(ag,sx,ac)) #generate newdata ts - as.data.frame (cbind(ag[23:24],sx[1000:1001],factor(ac[9000:9001],levels=c(1:5 colnames(ts) - c(ag,sx,ac) cph - coxph(Surv(time,ev)~ ag+sx+ac,data=c1) survfit(cph,newdata=ts,individual=F) thanks, Spencer [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Failure loading library into second R 2.3.1 session on Windows XP
Hi Uwe. Thank you so much for responding! I guess I wasn't entirely clear about the problem. If I make the mistake of trying to install a package from CRAN in a second session after I've already installed it in a previous session, it won't install in the second session, and even if I close the second session and open a subsequent newer session, it won't install in that one either. At least, I can't figure out how to do it, because it's no longer in the Load packages... menu, and if I load it from CRAN, I get that funny error message: Warning: cannot remove prior installation of package 'corpcor' Now, after having gone through this, I know enough not to reload a package from CRAN. But it appears that the only ways to solve the problem, if it occurs, are pretty drastic, either reboot the machine (which is what I did) or reinstall R (which seems to be what you're suggesting?). I was hoping that there might be a better alternative, or at least that the development team might look into this issue for future releases. This doesn't affect every package, but I've seen it in the first two packages I tried it with. -- TMK -- 212-460-5430home 917-656-5351cell From: Uwe Ligges [EMAIL PROTECTED] To: Talbot Katz [EMAIL PROTECTED] CC: r-help@stat.math.ethz.ch Subject: Re: [R] Failure loading library into second R 2.3.1 session on Windows XP Date: Fri, 29 Dec 2006 23:05:15 +0100 You can only expect that update / reinstall a ***package*** works if you have not yet loaded it into your R session. Hence close R, start it without loading the relevant package and then update/reinstall. Best, Uwe Ligges Talbot Katz wrote: Hi. I am using R 2.3.1 on Windows XP. I had installed a library package into my first session and wanted the same package in my second session, so I went out to the CRAN mirror and tried to install the package, and got the following message: * utils:::menuInstallPkgs() trying URL 'http://cran.ssds.ucdavis.edu/bin/windows/contrib/2.3/corpcor_1.4.4.zip' Content type 'application/zip' length 133068 bytes opened URL downloaded 129Kb package 'corpcor' successfully unpacked and MD5 sums checked Warning: cannot remove prior installation of package 'corpcor' The downloaded packages are in C:\Documents and Settings\Talbot\Local Settings\Temp\RtmplCxarb\downloaded_packages updating HTML package descriptions library(corpcor) Error in library(corpcor) : there is no package called 'corpcor' * After rebooting my machine, I dug into this a little further. Upon installing a package from a CRAN mirror, it seems to stay on my hard drive, and I can load it in subsequent sessions from the Load package... menu without going back to get it from a CRAN mirror. However, if I do happen to retrieve it again from a CRAN mirror, it appears that may corrupt the version that was saved, and it no longer will be available from the Load package... menu. A reboot and re-retrieval of the package makes it available again; I don't know whether there's any less drastic solution. This behavior doesn't occur with every package, but I have experienced it with two different packages (corpcor and copula), so there seems to be something going on. I didn't see anything in the FAQ page about this, I wonder if anyone can tell me more about this issue. Thanks! -- TMK -- 212-460-5430 home 917-656-5351 cell __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] coded to categorical variables in a large dataset
On Fri, 29 Dec 2006, sj wrote: I am working with a dataset where there are 5 possible outcomes (coded 1:5), I would like to create 5 categorical variables (event1...event5). I am using a for loop an if statements, but I have a large dataset( approx 100,000 rows) it takes quite a bit of time, is there a way to speed this up? Here is some sample code of what I am currently doing. test2 -rep(seq(1:5),2000) [...] As Richard suggested you may not want to do this at all, but ... If you want these as a matrix, this is fast and direct: mat - diag(5)[ test2, ] If not as a matrix event1 - as.numeric( test2 == 1 ) is concise and for (i in 1:5) assign(paste(event,i,sep=), as.numeric( test2==i )) is about as fast as you can get. HTH, Chuck Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:[EMAIL PROTECTED] UC San Diego http://biostat.ucsd.edu/~cberry/ La Jolla, San Diego 92093-0717 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] strange logical results
Hi Erin, You would be safe on a machine that represented floating point numbers in base 10, and I haven't seen one of those for such a long time... All modern machines use base 2 for floating point numbers. The moral of the story is not to believe what you see printed. The number you see printed innocently as '-0.4' has been arrived at by two different processes and uses two different *approximations* to the real thing on a binary machine, and my chance they have arrived at a slightly different result. Slight, but enough to make '==' ring the alarm. Here is a demo. x - seq(-1,1,by=0.1) x[7] - (-0.4) [1] 1.110223e-16 So the method used by seq() to arrive at an approximation to -0.4 is just slightly different from the method used by the parser when it reads the characters '-0.4' and translates them into a floating point number. It just so happens that for the others you checked the two approximations agreed, but you can't trust that to happen all the time. Moral of the story: don't use the '==' or '!=' operators with floating point numbers. It's an old tale but still current. OK, so what can you do to implement the idea of checking equality 'within a tolerance'? I'm glad you asked. You can write a couple of binary operators yourself. There is an object called .Machine that is a list of machine constants. The obvious one to compare the difference with is .Machine$double.eps `%~=%` - function(a, b) abs(a - b) .Machine$double.eps `%~!%` - function(a, b) abs(a - b) .Machine$double.eps x %~=% -0.4 [1] FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [15] FALSE FALSE FALSE FALSE FALSE FALSE FALSE x %~!% -0.4 [1] TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [15] TRUE TRUE TRUE TRUE TRUE TRUE TRUE The world is approximately sane once more. Bill Venables. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Erin Hodgess Sent: Friday, 29 December 2006 8:36 PM To: r-help@stat.math.ethz.ch Subject: [R] strange logical results Dear R People: I am getting some odd results when using logical operators: x - seq(from=-1,to=1,by=0.1) x [1] -1.0 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 [16] 0.5 0.6 0.7 0.8 0.9 1.0 x == -1 [1] TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE x == -0.9 [1] FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE x == -0.8 [1] FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE x == -0.7 [1] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE x == -0.6 [1] FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE x == -0.5 [1] FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE x == -0.4 [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE Should this show as true also, please? I saw this in both Windows and LINUX Versions 2.4.0 Thanks in advance, Sincerely, Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Failure loading library into second R 2.3.1 session on Windows XP
Hi, it sounds like you mixing up the words install and load. Basically, you only have to *install* a package once on your computer, but have to load it for every R session which you are going to use it in. So, in your case install it once, using either install.packages(corpcor) or the corresponding menu in RGui (on Windows), and then use library(corpcor) every time you want to *load* the package (typically once per R session). See An Introduction to R for further explainations. Details: When you try to install a package a second time the previous installation is overwritten. However, if another R session has the same package loaded, some of the files of the package might be looked, and won't be released until the package is unloaded or you quit the R session. Thus, when you try to install the package a second time (in another R session or even the same) it will not work. This is expected. Hope this helps Henrik On 12/30/06, Talbot Katz [EMAIL PROTECTED] wrote: Hi Uwe. Thank you so much for responding! I guess I wasn't entirely clear about the problem. If I make the mistake of trying to install a package from CRAN in a second session after I've already installed it in a previous session, it won't install in the second session, and even if I close the second session and open a subsequent newer session, it won't install in that one either. At least, I can't figure out how to do it, because it's no longer in the Load packages... menu, and if I load it from CRAN, I get that funny error message: Warning: cannot remove prior installation of package 'corpcor' Now, after having gone through this, I know enough not to reload a package from CRAN. But it appears that the only ways to solve the problem, if it occurs, are pretty drastic, either reboot the machine (which is what I did) or reinstall R (which seems to be what you're suggesting?). I was hoping that there might be a better alternative, or at least that the development team might look into this issue for future releases. This doesn't affect every package, but I've seen it in the first two packages I tried it with. -- TMK -- 212-460-5430home 917-656-5351cell From: Uwe Ligges [EMAIL PROTECTED] To: Talbot Katz [EMAIL PROTECTED] CC: r-help@stat.math.ethz.ch Subject: Re: [R] Failure loading library into second R 2.3.1 session on Windows XP Date: Fri, 29 Dec 2006 23:05:15 +0100 You can only expect that update / reinstall a ***package*** works if you have not yet loaded it into your R session. Hence close R, start it without loading the relevant package and then update/reinstall. Best, Uwe Ligges Talbot Katz wrote: Hi. I am using R 2.3.1 on Windows XP. I had installed a library package into my first session and wanted the same package in my second session, so I went out to the CRAN mirror and tried to install the package, and got the following message: * utils:::menuInstallPkgs() trying URL 'http://cran.ssds.ucdavis.edu/bin/windows/contrib/2.3/corpcor_1.4.4.zip' Content type 'application/zip' length 133068 bytes opened URL downloaded 129Kb package 'corpcor' successfully unpacked and MD5 sums checked Warning: cannot remove prior installation of package 'corpcor' The downloaded packages are in C:\Documents and Settings\Talbot\Local Settings\Temp\RtmplCxarb\downloaded_packages updating HTML package descriptions library(corpcor) Error in library(corpcor) : there is no package called 'corpcor' * After rebooting my machine, I dug into this a little further. Upon installing a package from a CRAN mirror, it seems to stay on my hard drive, and I can load it in subsequent sessions from the Load package... menu without going back to get it from a CRAN mirror. However, if I do happen to retrieve it again from a CRAN mirror, it appears that may corrupt the version that was saved, and it no longer will be available from the Load package... menu. A reboot and re-retrieval of the package makes it available again; I don't know whether there's any less drastic solution. This behavior doesn't occur with every package, but I have experienced it with two different packages (corpcor and copula), so there seems to be something going on. I didn't see anything in the FAQ page about this, I wonder if anyone can tell me more about this issue. Thanks! -- TMK -- 212-460-5430 home 917-656-5351 cell __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
Re: [R] installation problems
Hi Uwe, Thank you very much for the hint. I had a .Renviron in my home directory pointing to my 2.0.1 version. After removing that file, everything worked fine. Thanks again! Happy new year. Best regards, -Halim On 12/29/06, Uwe Ligges [EMAIL PROTECTED] wrote: Halim Damerdji wrote: Hi, I installed R-2.4.0 and R-2.4.1 on linux redhat (RHEL 3.0), and am encountering the following messages below. I searched the R FAQs and over the net, but couldn't find helpful information. When I check-all I do see some diff's (e.g., for stats, nls.Rout and nls.Rout.save in tests/stats.Rcheck/tests; cluster; and rpart'). I don't know if this is relevant. Minor differences due to numerical inaccuracies in the last digits are expected. For the error below: You have probably some old workspace or a library with outdated packages around. Delete and try again. Best, Uwe Ligges I have no problem with R-2.0.1, which I installed 1 1/2 years ago, and the Windows version. But I would like to use the recent versions. I would greatly appreciate any help. Thanks in advance. -Halim Damerdji % path_to_R_script/R R version 2.4.0 (2006-10-03) Copyright (C) 2006 The R Foundation for Statistical Computing ISBN 3-900051-07-0 == etc. Type 'q()' to quit R. Error in `parent.env-`(`*tmp*`, value = NULL) : use of NULL environment is defunct == twice In addition: Warning message: package utils in options(defaultPackages) was not found Error in `parent.env-`(`*tmp*`, value = NULL) : use of NULL environment is defunct == same for graphics In addition: Warning message: package stats in options(defaultPackages) was not found == same for methods help() Error : Could not find function help x - rnorm(20) Error : Could not find function rnorm [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] wrapping mle()
Hi, How can we set the environment for the minuslog function in mle()? The call in this code fails because the ll function cannot find the object 'y'. Modifying from the example in ?mle: library(stats4) ll - function(ymax=15, xhalf=6) { -sum(stats::dpois(y, lambda=ymax/(1+x/xhalf), log=TRUE)) } fit.mle - function(FUN, x, y) { loglik.fun - match.fun(FUN) mle(loglik.fun, method=L-BFGS-B, lower=c(0, 0)) } fit.mle(ll, x=0:10, y=c(26, 17, 13, 12, 20, 5, 9, 8, 5, 4, 8)) How should fit.mle be constructed so that ll works on the appropriate environment? Thanks in advance for any advice on this. -- Seb __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] wrapping mle()
Add the line marked ### so that the environment of loglik.fun is reset to the environment within fit.mle so that it can find y there: library(stats4) ll - function(ymax=15, xhalf=6) { -sum(stats::dpois(y, lambda=ymax/(1+x/xhalf), log=TRUE)) } fit.mle - function(FUN, x, y) { loglik.fun - match.fun(FUN) environment(loglik.fun) - environment() ### mle(loglik.fun, method=L-BFGS-B, lower=c(0, 0)) } fit.mle(ll, x=0:10, y=c(26, 17, 13, 12, 20, 5, 9, 8, 5, 4, 8)) On 12/30/06, Sebastian P. Luque [EMAIL PROTECTED] wrote: Hi, How can we set the environment for the minuslog function in mle()? The call in this code fails because the ll function cannot find the object 'y'. Modifying from the example in ?mle: library(stats4) ll - function(ymax=15, xhalf=6) { -sum(stats::dpois(y, lambda=ymax/(1+x/xhalf), log=TRUE)) } fit.mle - function(FUN, x, y) { loglik.fun - match.fun(FUN) mle(loglik.fun, method=L-BFGS-B, lower=c(0, 0)) } fit.mle(ll, x=0:10, y=c(26, 17, 13, 12, 20, 5, 9, 8, 5, 4, 8)) How should fit.mle be constructed so that ll works on the appropriate environment? Thanks in advance for any advice on this. -- Seb __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Failure loading library into second R 2.3.1 session on Windows XP
On Fri, 29 Dec 2006, Uwe Ligges wrote: You can only expect that update / reinstall a ***package*** works if you have not yet loaded it into your R session. Hence close R, start it without loading the relevant package and then update/reinstall. And for the record, this is answered in rw-FAQ Q4.8. Best, Uwe Ligges Talbot Katz wrote: Hi. I am using R 2.3.1 on Windows XP. I had installed a library package into my first session and wanted the same package in my second session, so I went out to the CRAN mirror and tried to install the package, and got the following message: * utils:::menuInstallPkgs() trying URL 'http://cran.ssds.ucdavis.edu/bin/windows/contrib/2.3/corpcor_1.4.4.zip' Content type 'application/zip' length 133068 bytes opened URL downloaded 129Kb package 'corpcor' successfully unpacked and MD5 sums checked Warning: cannot remove prior installation of package 'corpcor' The downloaded packages are in C:\Documents and Settings\Talbot\Local Settings\Temp\RtmplCxarb\downloaded_packages updating HTML package descriptions library(corpcor) Error in library(corpcor) : there is no package called 'corpcor' * After rebooting my machine, I dug into this a little further. Upon installing a package from a CRAN mirror, it seems to stay on my hard drive, and I can load it in subsequent sessions from the Load package... menu without going back to get it from a CRAN mirror. However, if I do happen to retrieve it again from a CRAN mirror, it appears that may corrupt the version that was saved, and it no longer will be available from the Load package... menu. A reboot and re-retrieval of the package makes it available again; I don't know whether there's any less drastic solution. This behavior doesn't occur with every package, but I have experienced it with two different packages (corpcor and copula), so there seems to be something going on. I didn't see anything in the FAQ page about this, I wonder if anyone can tell me more about this issue. Thanks! -- TMK -- 212-460-5430 home 917-656-5351 cell __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] wrapping mle()
On Fri, 29 Dec 2006, Sebastian P. Luque wrote: Hi, How can we set the environment for the minuslog function in mle()? The call in this code fails because the ll function cannot find the object 'y'. Modifying from the example in ?mle: library(stats4) ll - function(ymax=15, xhalf=6) { -sum(stats::dpois(y, lambda=ymax/(1+x/xhalf), log=TRUE)) } fit.mle - function(FUN, x, y) { loglik.fun - match.fun(FUN) mle(loglik.fun, method=L-BFGS-B, lower=c(0, 0)) } fit.mle(ll, x=0:10, y=c(26, 17, 13, 12, 20, 5, 9, 8, 5, 4, 8)) How should fit.mle be constructed so that ll works on the appropriate environment? Thanks in advance for any advice on this. You need to set the environment of ll to that containing your data objects. This would happen automatically if you defined ll in the function fit.mle. A brutal solution would be fit.mle - function(FUN, x, y) { loglik.fun - match.fun(FUN) environment(loglik.fun) - sys.frame(sys.nframe()) mle(loglik.fun, method=L-BFGS-B, lower=c(0, 0)) } but of course that would remove the previous environment from the scope, so you may need something like env - sys.frame(sys.nframe()) parent.env(env) - environment(ll) environment(loglik.fun) - env -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Evaluating Entire Matlab code at a time
Hi. On 12/30/06, Bhanu Kalyan.K [EMAIL PROTECTED] wrote: Dear Mr.Bengtsson, The steps you have suggested are working for single lines of matlab statements. But, as i mentioned earlier, If i want to see the output of an entire matlab code (say swissroll.m) then you suggested me to do res - evaluate(matlab, swissroll). When i did this the output looks something like: res - evaluate(matlab, swissroll) Sending expression on the Matlab server to be evaluated...: 'swissroll' Received an 'MatlabException' reply (-1) from the Matlab server: 'Undefined function or variable 'lle'.' Error in list(evaluate(matlab, swissroll) = environment, evaluate.Matlab(matlab, swissroll) = environment, : [2006-12-30 11:58:32] Exception: MatlabException: Undefined function or variable 'lle'. at throw(Exception(...)) at throw.default(MatlabException: , lasterr) at throw(MatlabException: , lasterr) at readResult.Matlab(this) at readResult(this) at evaluate.Matlab(matlab, swissroll) at evaluate(matlab, swissroll) // Here another matlab window titled Figure no.1 (corresponding to the actual matlab output of swissroll.m) opened, but the window is blank. No output is being displayed. However, when i used the same command for another matlab code, kMeansCluster.m, the warnings/Exceptions generated are similar to that os swissroll.m. Here is the output: res - evaluate(matlab, kMeansCluster;) Sending expression on the Matlab server to be evaluated...: 'kMeansCluster;' Received an 'MatlabException' reply (-1) from the Matlab server: 'Undefined function or variable 'kMeansCluster'.' Error in list(evaluate(matlab, kMeansCluster;) = environment, evaluate.Matlab(matlab, kMeansCluster;) = environment, : [2006-12-30 11:56:34] Exception: MatlabException: Undefined function or variable 'kMeansCluster'. at throw(Exception(...)) at throw.default(MatlabException: , lasterr) at throw(MatlabException: , lasterr) at readResult.Matlab(this) at readResult(this) at evaluate.Matlab(matlab, kMeansCluster;) at evaluate(matlab, kMeansCluster;) The warnings generated are almost similar for those two different matlab codes. So i feel that the problem lies with the R and not the code. What do u suggest? how to deal with this? To me this looks like Matlab can't find those commands, and then it has nothing to with R. Make sure your Matlab scripts are available in the Matlab path or in the working directory of Matlab. You check the working directory of Matlab with: evaluate(matlab, pwd=cd();); pwd - getVariable(matlab, pwd)$pwd; print(pwd); Check to see if your scripts are in the working directory: evaluate(matlab, files=dir();) files - getVariable(matlab, files)$files unlist(files[name,,]) If not, you have to update your Matlab path or change the working directory. Hope this helps Henrik Bhanu Kalyan K BTech CSE Final Year [EMAIL PROTECTED] Tel :+91-9885238228 __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.