Re: [R] Vector comparison to matrix
Probably you use the idea from unique.matrix, that is 1) form a string from each row and 2) call match() to see which strings match your pattern row. On Sun, 14 Aug 2005, Todd Remund wrote: I am looking for a fast way to count the number of rows in a matrix are identical to a pattern vector. For example, if I am interested in counting the number of row vectors in a matrix that are identical to (1,2,3) what would I do? I have tried the identical statement in a loop but this is far too slow. I have a very large matrix and need to avoid loops at all costs. -- 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
Re: [R] scratch a figure
jonathenwu at hotmail.com writes: I have generated a figure using rgl.surface(),how can I scratch this figure? thanks a lot. Assuming you mean print: Try rgl.snapshot, which produces a png file that can be printed by any standard paint program. Dieter __ 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
[R] return unique values from date/time class object
Background: OS: Linux Mandrake 10.1 release: R 2.0.0 editor: GNU Emacs 21.3.2 front-end: ESS 5.2.3 - Colleagues I have a wind speed time series with a normal frequency distribution and a spike in the 5 metres/second bin. The most likely explanation is that the instrument was returning duplicate values at this speed. To check this, I want to extract all the unique times from the series. However, unique() works with vectors and the object is POSIXt class. I've looked for a similar function to unique() that will work with this class, but have failed to find one. Any suggestions? Thanks Sam Sam McClatchie, Biological oceanography South Australian Aquatic Sciences Centre PO Box 120, Henley Beach 5022 Adelaide, South Australia email [EMAIL PROTECTED] Cellular: 0431 304 497 Telephone: (61-8) 8207 5448 FAX: (61-8) 8207 5481 Research home page http://www.members.iinet.net.au/~s.mcclatchie/ /\ ...xX(° °)Xx / \\ (((° (((° ...xX(°O°)Xx __ 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
Re: [R] Vector comparison to matrix
On Mon, 15 Aug 2005, Prof Brian Ripley wrote: Probably you use the idea from unique.matrix, that is 1) form a string from each row and 2) call match() to see which strings match your pattern row. If your matrix A really does have short rows like c(1,2,3) and millions of them, another idea is to do target - rep(c(1,2,3), each= nrow(A)) rowSums(A != target) == 0 For wider rows my first suggestion is probably faster. On Sun, 14 Aug 2005, Todd Remund wrote: I am looking for a fast way to count the number of rows in a matrix are identical to a pattern vector. For example, if I am interested in counting the number of row vectors in a matrix that are identical to (1,2,3) what would I do? I have tried the identical statement in a loop but this is far too slow. I have a very large matrix and need to avoid loops at all costs. -- 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
Re: [R] return unique values from date/time class object
Hi Sam It works for me: ss-Sys.time() sss-rep(ss,5) ss-Sys.time() sss-c(sss,ss) sss [1] 2005-08-15 10:04:02 Střední Evropa (letní čas) 2005-08-15 10:04:02 Střední Evropa (letní čas) [3] 2005-08-15 10:04:02 Střední Evropa (letní čas) 2005-08-15 10:04:02 Střední Evropa (letní čas) [5] 2005-08-15 10:04:02 Střední Evropa (letní čas) 2005-08-15 10:04:35 Střední Evropa (letní čas) # six values but only 2 different unique(sss) [1] 2005-08-15 10:04:02 Střední Evropa (letní čas) 2005-08-15 10:04:35 Střední Evropa (letní čas) # 2 values str(sss) 'POSIXct', format: chr [1:6] 2005-08-15 10:04:02 2005-08-15 10:04:02 2005-08-15 10:04:02 2005-08-15 10:04:02 2005- 08-15 10:04:02 ... # posix format as well HTH Petr On 15 Aug 2005 at 16:57, McClatchie, Sam (PIRSA-SARDI) wrote: Background: OS: Linux Mandrake 10.1 release: R 2.0.0 editor: GNU Emacs 21.3.2 front-end: ESS 5.2.3 - Colleagues I have a wind speed time series with a normal frequency distribution and a spike in the 5 metres/second bin. The most likely explanation is that the instrument was returning duplicate values at this speed. To check this, I want to extract all the unique times from the series. However, unique() works with vectors and the object is POSIXt class. I've looked for a similar function to unique() that will work with this class, but have failed to find one. Any suggestions? Thanks Sam Sam McClatchie, Biological oceanography South Australian Aquatic Sciences Centre PO Box 120, Henley Beach 5022 Adelaide, South Australia email [EMAIL PROTECTED] Cellular: 0431 304 497 Telephone: (61-8) 8207 5448 FAX: (61-8) 8207 5481 Research home page http://www.members.iinet.net.au/~s.mcclatchie/ /\ ...xX(° °)Xx / \\ (((° (((° ...xX(°O°)Xx __ 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 Petr Pikal [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
Re: [R] Problem with lme4
I did as you suggested by just running just R (--vanilla) and that seemed to work. Not sure what the problem was though. Thanks Peter Douglas Bates wrote: On 8/12/05, Peter Ho [EMAIL PROTECTED] wrote: Hi, I cannot seem to get lme4 to work. I have installed the lme4 and Matrix package with apt-get. and both can be found in /usr/lib/R/site-library. When I tried an example for lmer, R could not find the function lmer(), Try using install.packages(Matrix) install.packages(lme4) in R instead. I have not created and uploaded new Debian packages of the lme4 and Matrix R packages for several weeks. The versions on CRAN are more recent than the versions on the Debian archives. library(lme4) Attaching package: 'lme4' The following object(s) are masked from package:nlme : getCovariateFormula getResponseFormula groupedData Error in autoloader(name = confint, package = MASS) : autoloader did not find 'confint' in 'MASS' Try not to have the nlme and the lme4 packages loaded simultaneously. It appears that you may have had Rcmdr loaded causing many of the other packages to be loaded. It would be better to use --vanilla in the call to R and keep the number of loaded packages to a minimum until you can work out the problem of where lmer can be found. It is a bit confusing. The lmer function was in the lme4 package but now is in the Matrix package. (fm1 - lmer(decrease ~ treatment + (1|rowpos) + (1|colpos), + OrchardSprays)) Error: couldn't find function lmer Is this a bug with the lme4 package for Debian (r-cran-lme4)? Peter # R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. Loading Tcl/Tk interface ... done Loading required package: tcltk Loading required package: rgl Loading required package: zoo Loading required package: strucchange Loading required package: sandwich Loading required package: relimp Loading required package: nnet Loading required package: graphics Loading required package: grDevices Loading required package: stats Loading required package: nlme Attaching package: 'nlme' The following object(s) are masked from package:stats : contr.SAS Loading required package: mvtnorm Loading required package: multcomp Loading required package: mgcv This is mgcv 1.2-4 Loading required package: MASS Loading required package: lmtest Loading required package: lattice Loading required package: grid Loading required package: foreign Loading required package: effects Loading required package: car Loading required package: abind [Previously saved workspace restored] library(Matrix) library(lme4) Attaching package: 'lme4' The following object(s) are masked from package:nlme : getCovariateFormula getResponseFormula groupedData Error in autoloader(name = confint, package = MASS) : autoloader did not find 'confint' in 'MASS' (fm1 - lmer(decrease ~ treatment + (1|rowpos) + (1|colpos), + OrchardSprays)) Error: couldn't find function lmer __ 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 __ 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
[R] Semicolons (was: clip to keep coordinate system?)
On Tue, Aug 09, 2005 at 07:49:36AM -0700, Thomas Lumley wrote: On Tue, 9 Aug 2005 [EMAIL PROTECTED] wrote: dear R wizards: plot( 1, 1, ylim=(2,10), xlim=(2,10), type=n); rect( -1, -1, 12, 12, col=gray(0.99) ); unfortunately wipes out the border axes around the plot. how do I keep this? I think you meant plot( 1, 1, ylim=c(2,10), xlim=c(2,10), type=n) rect( -1, -1, 12, 12, col=gray(0.99) ) Your code has two syntax errors and two spurious semicolons. What's wrong with the semicolons? Technically, they're not necessary, but they definitely improve readability without doing any harm. Best regards, Jan -- +- Jan T. Kim ---+ |*NEW*email: [EMAIL PROTECTED] | |*NEW*WWW: http://www.cmp.uea.ac.uk/people/jtk | *-= hierarchical systems are for files, not for humans =-* __ 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
[R] stepAIC invalid scope argument
I am trying to replicate the first example from stepAIC from the MASS package with my own dataset but am running into error. If someone can point where I have gone wrong, I would appreciate it very much. Here is an example : set.seed(1) df - data.frame( x1=rnorm(1000), x2=rnorm(1000), x3=rnorm(1000) ) df$y - 0.5*df$x1 + rnorm(1000, mean=8, sd=0.5) # pairs(df); head(df) lo - aov( y ~ 1, data=df ) hi - aov( y ~ .^2, data=df ) mid - aov( y ~ x2 + x3, data=df ) Running any of the following commands stepAIC( mid, scope=list(upper = ~x1 + x2 + x3 , lower = ~1) ) stepAIC( mid, scope=list(upper = hi , lower = lo) ) addterm( mid, ~ x1 + x2 + x3 ) addterm( lo, hi ) gives the same error message : Error in eval(expr, envir, enclos) : invalid second argument Here is a traceback of the first failed command : 14: eval(predvars, data, env) 13: model.frame.default(formula = y ~ x2 + x3 + x1, data = df, drop.unused.levels = TRUE) 12: model.frame(formula = y ~ x2 + x3 + x1, data = df, drop.unused.levels = TRUE) 11: eval(expr, envir, enclos) 10: eval(mf, parent.frame()) 9: lm(formula = y ~ x2 + x3 + x1, data = df, method = model.frame) 8: eval(expr, envir, enclos) 7: eval(fcall, env, parent.frame()) 6: model.frame.lm(fob, xlev = object$xlevels) 5: model.frame(fob, xlev = object$xlevels) 4: stats:::add1.lm(object, scope = scope, scale = scale) 3: addterm.lm(fit, scope$add, scale = scale, trace = max(0, trace - 1), k = k, ...) 2: addterm(fit, scope$add, scale = scale, trace = max(0, trace - 1), k = k, ...) 1: stepAIC(mid, scope = list(upper = ~x1 + x2 + x3, lower = ~1)) Any pointers would be much appreciated. Thank you. Regards, Adai __ 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
[R] error in predict glm (new levels cause problems)
Dear R-helpers, I try to perform glm's with negative binomial distributed data. So I use the MASS library and the commands: model_1 = glm.nb(response ~ y1 + y2 + ...+ yi, data = data.frame) and predict(model_1, newdata = data.frame) So far, I think everything should be ok. But when I want to perform a glm with a subset of the data, I run into an error message as soon as I want to predict values, based on the new model. The problem seems to be the reduced number of levels of one of the factors yi ( a categorical factor) in the subset of the original data set. On cran search I found some related hint, that the line mf$drop.unused.levels - TRUE in the glm (or glm.nb) function could cause the problem. Therefore I changed the line to mf$drop.unused.levels - FALSE . Indeed the error message disappears and when I compare the prediction of model_1 with the prediction of the model, carried out with the full data set but with the changed glm.nb function, I get the same predicted numbers. However, the change of glm.nb function was more of an intuitive action, and since I still consider myself as a beginner of R, I don't feel comfortable. So my questions: 1. Is there an easier way to solve my problem? 2. Do I affect the glm.nb function seriously, by changing the line mentioned above? Thank you for your help, Katharina PS: I am working with R 2.0.0 PPS: Concrete error message: Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) : factor I(kanton) has new level(s) GE -- K. Steinmann Botanisches Institut Universität Basel CH-4056 Basel Switzerland Tel 0041 61 267 35 02 E-mail: [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
Re: [R] Vector comparison to matrix
Hi Todd, Here is a function that was suggested to me by Gabor Grothendieck. This function counts the number of times each row of a matrix B occurs in another matrix A. rowmatch.count - function(a,b) { f - function(...) paste(..., sep=:) a2 - do.call(f, as.data.frame(a)) b2 - do.call(f, as.data.frame(b)) c(table(c(a2,unique(b2)))[b2] - 1) } If you are interested in finding the number of occurrences of a vector b instead, you can call this function as follows: rowmatch.count(A,t(as.matrix(b)) Hope this is helps, Ravi. -Original Message- From: [EMAIL PROTECTED] [mailto:r-help- [EMAIL PROTECTED] On Behalf Of Todd Remund Sent: Monday, August 15, 2005 1:13 AM To: r-help@stat.math.ethz.ch Subject: [R] Vector comparison to matrix I am looking for a fast way to count the number of rows in a matrix are identical to a pattern vector. For example, if I am interested in counting the number of row vectors in a matrix that are identical to (1,2,3) what would I do? I have tried the identical statement in a loop but this is far too slow. I have a very large matrix and need to avoid loops at all costs. Thanks for any help. Todd Remund __ 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 __ 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
Re: [R] stepAIC invalid scope argument
Try not to use the name of an R object ... the error is caused by using 'df' as the second argument to eval(). It works with DF in place of df. I don;t understand your subject line: that is not the error message you received. On Mon, 15 Aug 2005, Adaikalavan Ramasamy wrote: I am trying to replicate the first example from stepAIC from the MASS package with my own dataset but am running into error. If someone can point where I have gone wrong, I would appreciate it very much. Here is an example : set.seed(1) df - data.frame( x1=rnorm(1000), x2=rnorm(1000), x3=rnorm(1000) ) df$y - 0.5*df$x1 + rnorm(1000, mean=8, sd=0.5) # pairs(df); head(df) lo - aov( y ~ 1, data=df ) hi - aov( y ~ .^2, data=df ) mid - aov( y ~ x2 + x3, data=df ) Running any of the following commands stepAIC( mid, scope=list(upper = ~x1 + x2 + x3 , lower = ~1) ) stepAIC( mid, scope=list(upper = hi , lower = lo) ) addterm( mid, ~ x1 + x2 + x3 ) addterm( lo, hi ) gives the same error message : Error in eval(expr, envir, enclos) : invalid second argument Here is a traceback of the first failed command : 14: eval(predvars, data, env) 13: model.frame.default(formula = y ~ x2 + x3 + x1, data = df, drop.unused.levels = TRUE) 12: model.frame(formula = y ~ x2 + x3 + x1, data = df, drop.unused.levels = TRUE) 11: eval(expr, envir, enclos) 10: eval(mf, parent.frame()) 9: lm(formula = y ~ x2 + x3 + x1, data = df, method = model.frame) 8: eval(expr, envir, enclos) 7: eval(fcall, env, parent.frame()) 6: model.frame.lm(fob, xlev = object$xlevels) 5: model.frame(fob, xlev = object$xlevels) 4: stats:::add1.lm(object, scope = scope, scale = scale) 3: addterm.lm(fit, scope$add, scale = scale, trace = max(0, trace - 1), k = k, ...) 2: addterm(fit, scope$add, scale = scale, trace = max(0, trace - 1), k = k, ...) 1: stepAIC(mid, scope = list(upper = ~x1 + x2 + x3, lower = ~1)) Any pointers would be much appreciated. Thank you. Regards, Adai __ 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 -- 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
Re: [R] stepAIC invalid scope argument
In case it is unclear why in this case there is a problem: you are running a function (here model.frame) in the stats namespace and so it looks in the stats namespace before the workspace when looking for 'df'. On Mon, 15 Aug 2005, Prof Brian Ripley wrote: Try not to use the name of an R object ... the error is caused by using 'df' as the second argument to eval(). It works with DF in place of df. I don't understand your subject line: that is not the error message you received. On Mon, 15 Aug 2005, Adaikalavan Ramasamy wrote: I am trying to replicate the first example from stepAIC from the MASS package with my own dataset but am running into error. If someone can point where I have gone wrong, I would appreciate it very much. Here is an example : set.seed(1) df - data.frame( x1=rnorm(1000), x2=rnorm(1000), x3=rnorm(1000) ) df$y - 0.5*df$x1 + rnorm(1000, mean=8, sd=0.5) # pairs(df); head(df) lo - aov( y ~ 1, data=df ) hi - aov( y ~ .^2, data=df ) mid - aov( y ~ x2 + x3, data=df ) Running any of the following commands stepAIC( mid, scope=list(upper = ~x1 + x2 + x3 , lower = ~1) ) stepAIC( mid, scope=list(upper = hi , lower = lo) ) addterm( mid, ~ x1 + x2 + x3 ) addterm( lo, hi ) gives the same error message : Error in eval(expr, envir, enclos) : invalid second argument Here is a traceback of the first failed command : 14: eval(predvars, data, env) 13: model.frame.default(formula = y ~ x2 + x3 + x1, data = df, drop.unused.levels = TRUE) 12: model.frame(formula = y ~ x2 + x3 + x1, data = df, drop.unused.levels = TRUE) 11: eval(expr, envir, enclos) 10: eval(mf, parent.frame()) 9: lm(formula = y ~ x2 + x3 + x1, data = df, method = model.frame) 8: eval(expr, envir, enclos) 7: eval(fcall, env, parent.frame()) 6: model.frame.lm(fob, xlev = object$xlevels) 5: model.frame(fob, xlev = object$xlevels) 4: stats:::add1.lm(object, scope = scope, scale = scale) 3: addterm.lm(fit, scope$add, scale = scale, trace = max(0, trace - 1), k = k, ...) 2: addterm(fit, scope$add, scale = scale, trace = max(0, trace - 1), k = k, ...) 1: stepAIC(mid, scope = list(upper = ~x1 + x2 + x3, lower = ~1)) Any pointers would be much appreciated. Thank you. Regards, Adai __ 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 -- 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 -- 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
Re: [R] stepAIC invalid scope argument
You are right, it works fine with a different name. Its a bad habit that I need to shake off. The error message said that the second argument was invalid. The second argument in stepAIC and addterm is 'scope' and thus the title. Thank you again. Regards, Adai On Mon, 2005-08-15 at 15:23 +0100, Prof Brian Ripley wrote: Try not to use the name of an R object ... the error is caused by using 'df' as the second argument to eval(). It works with DF in place of df. I don;t understand your subject line: that is not the error message you received. On Mon, 15 Aug 2005, Adaikalavan Ramasamy wrote: I am trying to replicate the first example from stepAIC from the MASS package with my own dataset but am running into error. If someone can point where I have gone wrong, I would appreciate it very much. Here is an example : set.seed(1) df - data.frame( x1=rnorm(1000), x2=rnorm(1000), x3=rnorm(1000) ) df$y - 0.5*df$x1 + rnorm(1000, mean=8, sd=0.5) # pairs(df); head(df) lo - aov( y ~ 1, data=df ) hi - aov( y ~ .^2, data=df ) mid - aov( y ~ x2 + x3, data=df ) Running any of the following commands stepAIC( mid, scope=list(upper = ~x1 + x2 + x3 , lower = ~1) ) stepAIC( mid, scope=list(upper = hi , lower = lo) ) addterm( mid, ~ x1 + x2 + x3 ) addterm( lo, hi ) gives the same error message : Error in eval(expr, envir, enclos) : invalid second argument Here is a traceback of the first failed command : 14: eval(predvars, data, env) 13: model.frame.default(formula = y ~ x2 + x3 + x1, data = df, drop.unused.levels = TRUE) 12: model.frame(formula = y ~ x2 + x3 + x1, data = df, drop.unused.levels = TRUE) 11: eval(expr, envir, enclos) 10: eval(mf, parent.frame()) 9: lm(formula = y ~ x2 + x3 + x1, data = df, method = model.frame) 8: eval(expr, envir, enclos) 7: eval(fcall, env, parent.frame()) 6: model.frame.lm(fob, xlev = object$xlevels) 5: model.frame(fob, xlev = object$xlevels) 4: stats:::add1.lm(object, scope = scope, scale = scale) 3: addterm.lm(fit, scope$add, scale = scale, trace = max(0, trace - 1), k = k, ...) 2: addterm(fit, scope$add, scale = scale, trace = max(0, trace - 1), k = k, ...) 1: stepAIC(mid, scope = list(upper = ~x1 + x2 + x3, lower = ~1)) Any pointers would be much appreciated. Thank you. Regards, Adai __ 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 __ 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
Re: [R] scratch a figure
吴 昊 wrote: Hi, I have generated a figure using rgl.surface(),how can I scratch this figure? thanks a lot. Which version of rgl are you using? Current is 0.65. What does scratch mean? There are functions rgl.close(), rgl.clear(), rgl.pop(). You can also just close the window; a new one will be created the next time you draw something. Duncan Murdoch __ 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
[R] Re-sort list of vectors
Hi. Can anyone suggest a simple way to re-sort in R a list of vectors of the following form? input $1 a b c 1 2 3 $2 a b c 4 5 6 Output should be something like: a 1 1 2 4 b 1 2 2 5 c 1 3 2 6 I've been futzing with mapply(), outer(), split(), rbind() and so on but haven't found an elegant solution. Thanks, Jan. P.S. E-mailed CCs of posted replies appreciated. __ 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
Re: [R] Re-sort list of vectors
If all vectors in the list have the same length, why not use a matrix? Then you'd just transpose the matrix if you need to. If you really have to have it as a list, here's one possibility: x - list(1=c(a=1, b=2, c=3), 2=c(a=4, b=5, c=6)) x $1 a b c 1 2 3 $2 a b c 4 5 6 as.list(as.data.frame(t(matrix(unlist(x), nrow=3 $V1 [1] 1 4 $V2 [1] 2 5 $V3 [1] 3 6 Andy From: Jan Hummel Hi. Can anyone suggest a simple way to re-sort in R a list of vectors of the following form? input $1 a b c 1 2 3 $2 a b c 4 5 6 Output should be something like: a 1 1 2 4 b 1 2 2 5 c 1 3 2 6 I've been futzing with mapply(), outer(), split(), rbind() and so on but haven't found an elegant solution. Thanks, Jan. P.S. E-mailed CCs of posted replies appreciated. __ 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 __ 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
Re: [R] stepAIC invalid scope argument
On Mon, 15 Aug 2005, Adaikalavan Ramasamy wrote: You are right, it works fine with a different name. Its a bad habit that I need to shake off. The error message said that the second argument was invalid. The second argument in stepAIC and addterm is 'scope' and thus the title. OK, we'll improve the error message Thank you again. Regards, Adai On Mon, 2005-08-15 at 15:23 +0100, Prof Brian Ripley wrote: Try not to use the name of an R object ... the error is caused by using 'df' as the second argument to eval(). It works with DF in place of df. I don;t understand your subject line: that is not the error message you received. On Mon, 15 Aug 2005, Adaikalavan Ramasamy wrote: I am trying to replicate the first example from stepAIC from the MASS package with my own dataset but am running into error. If someone can point where I have gone wrong, I would appreciate it very much. Here is an example : set.seed(1) df - data.frame( x1=rnorm(1000), x2=rnorm(1000), x3=rnorm(1000) ) df$y - 0.5*df$x1 + rnorm(1000, mean=8, sd=0.5) # pairs(df); head(df) lo - aov( y ~ 1, data=df ) hi - aov( y ~ .^2, data=df ) mid - aov( y ~ x2 + x3, data=df ) Running any of the following commands stepAIC( mid, scope=list(upper = ~x1 + x2 + x3 , lower = ~1) ) stepAIC( mid, scope=list(upper = hi , lower = lo) ) addterm( mid, ~ x1 + x2 + x3 ) addterm( lo, hi ) gives the same error message : Error in eval(expr, envir, enclos) : invalid second argument Here is a traceback of the first failed command : 14: eval(predvars, data, env) 13: model.frame.default(formula = y ~ x2 + x3 + x1, data = df, drop.unused.levels = TRUE) 12: model.frame(formula = y ~ x2 + x3 + x1, data = df, drop.unused.levels = TRUE) 11: eval(expr, envir, enclos) 10: eval(mf, parent.frame()) 9: lm(formula = y ~ x2 + x3 + x1, data = df, method = model.frame) 8: eval(expr, envir, enclos) 7: eval(fcall, env, parent.frame()) 6: model.frame.lm(fob, xlev = object$xlevels) 5: model.frame(fob, xlev = object$xlevels) 4: stats:::add1.lm(object, scope = scope, scale = scale) 3: addterm.lm(fit, scope$add, scale = scale, trace = max(0, trace - 1), k = k, ...) 2: addterm(fit, scope$add, scale = scale, trace = max(0, trace - 1), k = k, ...) 1: stepAIC(mid, scope = list(upper = ~x1 + x2 + x3, lower = ~1)) Any pointers would be much appreciated. Thank you. Regards, Adai __ 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 -- 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
Re: [R] Way to make R idle for some time and try something again later
At 6:44 AM +0100 7/30/05, Prof Brian Ripley wrote: This depends on what else is going on. My guess is that you are running the Aqua GUI, and it is servicing the GUI which is taking the time, not R itself. Actually, no, I am not using the Aqua GUI. Not even a framework build: ../source/configure --enable-R-shlib --with-blas=-framework vecLib --with-lapack --enable-R-framework=no On all of Linux, Solaris and Windows (RGui or Rterm) Sys.sleep() does use very close to zero resources at the beginning of a session, but things may be different if e.g. tcltk widgets are in use. On Fri, 29 Jul 2005, Don MacQueen wrote: I done something very similar -- have R watch a file, and whenever new data is added to the file, read the new data from the file. In my case, new data was arriving once per minute, so I needed to have R wait about a minute before looking for new data. On my unix-based system, I found that if I usd I don't think your system IS `unix-based' (Unix is a trademark, and MacOS X is based on a rather different kernel). It is quite possible that it is behaving differently from the POSIX description of Unix system calls on which R is based for Unix-alikes. Sys.sleep( N ) then cpu usage immediately went up drastically. If the the system is otherwise fairly idle, cpu usage goes up to nearly 100%. A cpu monitor shows that R is using the cpu cycles. If I use instead system('sleep N') cpu usage does not go up. Does that freeze the GUI? It certainly freezes tcltk widgets on Unix. I've never tried it while using tcltk widgets. (and apologies for the delay; I've been away from the office for two weeks) (where N is the number of seconds to sleep) version _ platform powerpc-apple-darwin7.9.0 arch powerpc os darwin7.9.0 system powerpc, darwin7.9.0 status major2 minor1.1 year 2005 month06 day 20 language R At 12:13 PM -0700 7/29/05, Tae-Hoon Chung wrote: Hi, All; I have a question. In R, what is the best way to make R idle for a while and try something again later? For example, suppose there is an R job which accesses a file that may be shared with other active jobs. So when the file is being accessed by other job, your job will not be able to access the file and your job will crash because of that. To avoid this, you want your job to try to access the file repeatedly with some time interval, say every 10 seconds or something like that. Which is the best way to do this in R? -- 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 -- -- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA __ 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
Re: [R] Using nonlinear regression
Do you want to estimate the parameters of a lognormal distribution or learn how to do nonlinear regression in R? If the former, as far as I know, the best known method is maximum likelihood, for which the answer is to compute mean and standard deviations of the logs. This assumes you are talking about the 2-parameter lognormal. I don't know the best method for a 3-parameter lognormal. If that's what you want, PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html;. Doing so can increase the chances of getting a useful reply. If you want examples of nonlinear regression, have you considered nls and optim? spencer graves Mark Miller wrote: Attached is a copy of my code, the data and the plots obtained by varying terms manually, I was told that nonlinear regression in R could find the values for me, but I am unable to figure how exactly I could implement this. Any help would be very greatly appreciated as I am completely stuck on this problem. On Thursday 04 August 2005 13:40, you wrote: It might be good to have an example of your problem. On Aug 4, 2005, at 5:57 AM, Mark Miller wrote: Hi, I have been trying to figure out how to use the nonlinear regression to fit the cumulative lognormal distribution to a number of data points I have but I am a new R user and I cant quite decipher the notes on nonlinear regression. Any help in this regard will be greatly appreciated, my email address is [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 rm(list=ls()) outPut = read.csv(dataOut2.csv) arrive = outPut[1] register = outPut[2] complete = outPut[3] IAT = 0 TTR = 0 TTC = 0 TFR = 0 cnt = 1 for(i in array(2:dim(arrive)[1])) { temp = outPut[i,3]-outPut[i,2] if(temp 0) { IAT[cnt] = outPut[i,1]-outPut[i-1,1] TTR[cnt] = outPut[i,2]-outPut[i,1] TFR[cnt] = outPut[i,3]-outPut[i,2] cnt = cnt + 1 } } cumIAT = IAT/sum(IAT) for(i in array(2:length(IAT))) { cumIAT[i] = cumIAT[i-1]+cumIAT[i] } cumIAT[1] = 0 plot(cumIAT,do.point=F) TTR[cnt] = outPut[1,2]-outPut[1,1] TFR[cnt] = outPut[1,3]-outPut[1,2] # Plot for inter-arrival times x = seq(0,30,0.01) #postscript(cumIAT.ps) plot(ecdf(IAT), do.point=FALSE) lines(x, pexp(x,0.4)) dev.off() # rexp(100,0.21) x = seq(0,20,0.01) postscript(cumTTR.ps) plot(ecdf(TTR), do.point=FALSE) lines(x, plnorm(x,1,0.7)) dev.off() # rlnorm(100,1,0.7) # Plot for Time to complete from registered x = seq(0,30,0.01) postscript(cumTFR.ps) plot(ecdf(TFR), do.point=FALSE) lines(x*600, pbeta(x,1.4,4.3)) dev.off() # rbeta(100,1.6,5)*600 # Find the position with the leat time and hence the next avaliable ambulance minimum = function(toFind) { min = 0; pos = 0; for(i in array(1:length(toFind))) { if(i == 1) { min = toFind[i] pos = i } else { if(toFind[i] min) { min = toFind[i] pos = i } } } pos } ambsReq = 0 numAmbs = 0 numberAmbs = 0 avgWait = 1 numberAmbs2 = 0 avgWaitTime2 = 0 avgWaitTime = 0 counter = 0 counter2 = 1 cntO = 1 for(i in array(1:50)) { while(avgWait 0) { counter = counter + 1 numAmbs = numAmbs + 1 numberAmbs[counter] = numAmbs numCalls = 1 ambs = array(c(array(0,numAmbs)), dim=c(numAmbs,numCalls)) waitTime = ambs totalTime = ambs currTime = 0 timeTS = 0 IotherAT = 0 TotherTR = 0 for(i in array(1:500)) { #interAT = IAT(ceil(rand()*length(IAT))); interAT = rexp(1,0.21) #timeTR = TTR(ceil(rand()*length(TTR))); timeTR = rlnorm(1,1,0.7) #timeFR = TFR(ceil(rand()*length(TFR))); timeFR = rbeta(1,1.4,4.3)*600 IotherAT[i] = interAT TotherTR[i] = timeTR currTime = currTime + interAT pos = minimum(totalTime) if(ambs[pos,numCalls] != 0) { numCalls = numCalls + 1 ambs = array(c(ambs,array(0,numAmbs)), dim=c(numAmbs,numCalls)) waitTime = array(c(waitTime,array(0,numAmbs)), dim=c(numAmbs,numCalls)) if(totalTime[pos] currTime)
Re: [R] boot error: Error in statistic(data, original, ...) : unused argument(s) ( ...)
On Sat, 13 Aug 2005, Prof Brian Ripley wrote: I suspect you want AdjForBase2 - function (data, inds) and to refer to data[inds, 1] and data[inds, 2], but since your code is completely devoid of spaces and indentation, I have paid it little attention. http://msr.uwaterloo.ca/msr2005/papers/27.pdf describes a study of student computer science projects from CVS logs in which the only code feature correlated with the final grade was the number of times a space was used after a comma. [I'm not sure I like their analysis, though]. -thomas __ 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
Re: [R] retrieving large columns using RODBC
This appears to be an SQL issue. Look for a way to speed up your queries in Postgresql. I presume you haven't created an index on 'index', which means that every time you run your SELECT, Postgresql is forced to do a full table scan (not good). If the index doesn't solve the problem, look for some SQL help. -Original Message- From: Tamas K Papp [mailto:[EMAIL PROTECTED] Sent: Saturday, August 13, 2005 4:03 AM To: R-help mailing list Subject: [R] retrieving large columns using RODBC Hi, I have a large table in Postgresql (result of an MCMC simulation, with 1 million rows) and I would like to retrive colums (correspond to variables) using RODBC. I have a column called index which is used to order rows. Unfortunately, sqlQuery can't return all the values from a column at once (RODBC complains about lack of memory). So I am using the following code: getcolumns - function(channel, tablename, colnames, totalrows, ordered=TRUE,chunksize=1e5) { r - matrix(double(0),totalrows,length(colnames)) for (i in 1:ceiling(totalrows/chunksize)) { cat(.) r[((i-1)*chunksize+1):(i*chunksize)] - as.matrix( sqlQuery(channel, paste(SELECT, paste(colnames,collapse=, ), FROM, tablename, WHERE index =, i*chunksize, AND index , (i-1)*chunksize, if (ordered) ORDER BY index; else ;))) } cat(\n) drop(r) # convert to vector if needed } to retrieve it in chunks. However, this is very slow -- takes about 15 minutes on my machine. Is there a way to speed it up? I am running Linux on a powerbook, RODBC version 1.1-4, R 2.1.1. The machine has only 512 Mb of RAM. Thanks, Tamas __ 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 __ 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
[R] relation between cex.axis and pointsize in graphics device
I am not able to see the relation between this parameters. Will I get the same result with pointsize=24 and cex.axis=1 and pointsize=12 and cex.axis=2 It seems that the fonts will be only scaled when I am changing the pointsize after printing and it seem that they will be drawn in a better resoultion with the second way pointsize=12 and cex.axis=2 bmp(filename = Rplot%03d.bmp, width = 480, height = 480, pointsize = 24, bg = white, res = NA) axis(1, 1:7, LETTERS[1:7], cex.axis=1) bmp(filename = Rplot%03d.bmp, width = 480, height = 480, pointsize = 12, bg = white, res = NA) axis(1, 1:7, LETTERS[1:7], cex.axis=2) with regards Knut Krueger __ 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
Re: [R] retrieving large columns using RODBC
On Mon, 15 Aug 2005, bogdan romocea wrote: This appears to be an SQL issue. Look for a way to speed up your queries in Postgresql. I presume you haven't created an index on 'index', which means that every time you run your SELECT, Postgresql is forced to do a full table scan (not good). If the index doesn't solve the problem, look for some SQL help. If that were the case the fact that sqlQuery is not being used properly (it can do the query and return the results in blocks) is likely to be the problem. But then we do ask people to read the help page before posting. -Original Message- From: Tamas K Papp [mailto:[EMAIL PROTECTED] Sent: Saturday, August 13, 2005 4:03 AM To: R-help mailing list Subject: [R] retrieving large columns using RODBC Hi, I have a large table in Postgresql (result of an MCMC simulation, with 1 million rows) and I would like to retrive colums (correspond to variables) using RODBC. I have a column called index which is used to order rows. Unfortunately, sqlQuery can't return all the values from a column at once (RODBC complains about lack of memory). So I am using the following code: getcolumns - function(channel, tablename, colnames, totalrows, ordered=TRUE,chunksize=1e5) { r - matrix(double(0),totalrows,length(colnames)) for (i in 1:ceiling(totalrows/chunksize)) { cat(.) r[((i-1)*chunksize+1):(i*chunksize)] - as.matrix( sqlQuery(channel, paste(SELECT, paste(colnames,collapse=, ), FROM, tablename, WHERE index =, i*chunksize, AND index , (i-1)*chunksize, if (ordered) ORDER BY index; else ;))) } cat(\n) drop(r) # convert to vector if needed } to retrieve it in chunks. However, this is very slow -- takes about 15 minutes on my machine. Is there a way to speed it up? I am running Linux on a powerbook, RODBC version 1.1-4, R 2.1.1. The machine has only 512 Mb of RAM. Thanks, Tamas __ 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 __ 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 -- 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
[R] Testing.
Please ignore this message; I apologise for the annoyance. cheers, Rolf __ 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
Re: [R] Re-sort list of vectors
Thanks a lot! But unfortunately I will not know the dimensions of both lists. And further, the lists may be (partly) disjoint as: x - list(1=c(a=1, b=2, c=3), 2=c(d=4, b=5, e=6)). And last but not least I'm really have to have access to the names of the named list items. The problem I dealt with is in unlist() merging the names together, as you can see in your example given: V1, V2 and V3. Because off interpreting the names later as identifiers in db queries I'm really interested in getting something like list(a=c(1=1), b=c(1=2, 2=5), c=c(1=3), d=c(1=4), e=c(1=6)) for the above input. By giving the result this way I'm able to extract both names from two sets as well as the according value between both items. One point could be to build a matrix but this matrix would have many NA's. So I prefer Lists of Lists. Any ideas? cheers Jan -Ursprüngliche Nachricht- Von: Liaw, Andy [mailto:[EMAIL PROTECTED] Gesendet: Montag, 15. August 2005 17:31 An: Jan Hummel; r-help@stat.math.ethz.ch Betreff: RE: [R] Re-sort list of vectors If all vectors in the list have the same length, why not use a matrix? Then you'd just transpose the matrix if you need to. If you really have to have it as a list, here's one possibility: x - list(1=c(a=1, b=2, c=3), 2=c(a=4, b=5, c=6)) x $1 a b c 1 2 3 $2 a b c 4 5 6 as.list(as.data.frame(t(matrix(unlist(x), nrow=3 $V1 [1] 1 4 $V2 [1] 2 5 $V3 [1] 3 6 Andy From: Jan Hummel Hi. Can anyone suggest a simple way to re-sort in R a list of vectors of the following form? input $1 a b c 1 2 3 $2 a b c 4 5 6 Output should be something like: a 1 1 2 4 b 1 2 2 5 c 1 3 2 6 I've been futzing with mapply(), outer(), split(), rbind() and so on but haven't found an elegant solution. Thanks, Jan. P.S. E-mailed CCs of posted replies appreciated. __ 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 __ 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
Re: [R] PCA problem in R
You are wrong. No covariance matrix is computed. Please don't speculate -- read the Help file which clearly states: The calculation is done by a singular value decomposition of the (centered and possibly scaled) data matrix, not by using eigen on the covariance matrix. This is generally the preferred method for numerical accuracy. -- Bert Gunter I speculate that the underlying function transposes the input data matrix and computes the the TxT [rather than SxS] covariance matrix and solves for the eigenvalues/vectors. It then uses a linear transformation to get the results for the original input data matrix. Computationally, the above is much faster and uses less memory. __ 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 __ 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
Re: [R] PCA problem in R
From: Dennis Shea [SNIP] On Sat, 13 Aug 2005, Alan Zhao wrote: When I have more variables than units, say a 195*10896 matrix which has 10896 variables and 195 samples. prcomp will give only 195 principal components. I checked in the help, but there is no explanation that why this happen. [SNIP] Sincerely, Zheng Zhao Aug-14-2005 __ Just yesterday I subscribed to r-help because I am planning on learning the basics of R ... today. :-) Thus, I am not sure about the history of this question. The above situation, more variables than samples, is commonly encounterd in the climate studies. Consider annual mean temperatures for 195 years on a coarse 72 [lat] x 144 [lon] grid [72*144=10368 spatial variables]. Let S be the number of grid points and T be the number of years. I think there is a theorem (?Eckart-Young?) which states that the maximum number of unique eigenvalues is min(S,T). In your case 195 eigenvalues is correct. I speculate that the underlying function transposes the input data matrix and computes the the TxT [rather than SxS] covariance matrix and solves for the eigenvalues/vectors. It then uses a linear transformation to get the results for the original input data matrix. Computationally, the above is much faster and uses less memory. It is usually a good idea to consult the help page before speculating. ?prcomp has, in its `Detail' section: The calculation is done by a singular value decomposition of the (centered and possibly scaled) data matrix, not by using eigen on the covariance matrix. This is generally the preferred method for numerical accuracy. Andy __ 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 __ 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
Re: [R] Re-sort list of vectors
You could try using one of the sparse representations of matrices in the SparseM or Matrix packages. Both packages have vignettes. Andy From: Jan Hummel Thanks a lot! But unfortunately I will not know the dimensions of both lists. And further, the lists may be (partly) disjoint as: x - list(1=c(a=1, b=2, c=3), 2=c(d=4, b=5, e=6)). And last but not least I'm really have to have access to the names of the named list items. The problem I dealt with is in unlist() merging the names together, as you can see in your example given: V1, V2 and V3. Because off interpreting the names later as identifiers in db queries I'm really interested in getting something like list(a=c(1=1), b=c(1=2, 2=5), c=c(1=3), d=c(1=4), e=c(1=6)) for the above input. By giving the result this way I'm able to extract both names from two sets as well as the according value between both items. One point could be to build a matrix but this matrix would have many NA's. So I prefer Lists of Lists. Any ideas? cheers Jan -Ursprüngliche Nachricht- Von: Liaw, Andy [mailto:[EMAIL PROTECTED] Gesendet: Montag, 15. August 2005 17:31 An: Jan Hummel; r-help@stat.math.ethz.ch Betreff: RE: [R] Re-sort list of vectors If all vectors in the list have the same length, why not use a matrix? Then you'd just transpose the matrix if you need to. If you really have to have it as a list, here's one possibility: x - list(1=c(a=1, b=2, c=3), 2=c(a=4, b=5, c=6)) x $1 a b c 1 2 3 $2 a b c 4 5 6 as.list(as.data.frame(t(matrix(unlist(x), nrow=3 $V1 [1] 1 4 $V2 [1] 2 5 $V3 [1] 3 6 Andy From: Jan Hummel Hi. Can anyone suggest a simple way to re-sort in R a list of vectors of the following form? input $1 a b c 1 2 3 $2 a b c 4 5 6 Output should be something like: a 1 1 2 4 b 1 2 2 5 c 1 3 2 6 I've been futzing with mapply(), outer(), split(), rbind() and so on but haven't found an elegant solution. Thanks, Jan. P.S. E-mailed CCs of posted replies appreciated. __ 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 __ 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 __ 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
[R] paste / system mystery
Dear R wizards: under R-2.1.0: eargs - 3:5; line - paste(c(echo A B, eargs)); cat(executing from R: ', line, '\n); system(line); Oddly, only A and B are echoed, not the eargs. I had hoped that line would be one string at this point, and for printing this seems to be true. However, unlist(line) still gives me the 4 components. It almost seems like the objects were not really pasted, but kept separate [perhaps to conserve memory]---which works internally, but not externally. Is this my poor understanding of R, an R feature, or an R bug? help appreciated. /iaw --- ivo welch __ 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
Re: [R] Re-sort list of vectors
Not that I like loops, but here is a quick and dirty way of doing it: Result - list() for (i in names(x)){ for (j in names(x[[i]])){ Result[[j]][[i]] - x[[i]][[j]] } } On 8/15/05, Liaw, Andy [EMAIL PROTECTED] wrote: You could try using one of the sparse representations of matrices in the SparseM or Matrix packages. Both packages have vignettes. Andy From: Jan Hummel Thanks a lot! But unfortunately I will not know the dimensions of both lists. And further, the lists may be (partly) disjoint as: x - list(1=c(a=1, b=2, c=3), 2=c(d=4, b=5, e=6)). And last but not least I'm really have to have access to the names of the named list items. The problem I dealt with is in unlist() merging the names together, as you can see in your example given: V1, V2 and V3. Because off interpreting the names later as identifiers in db queries I'm really interested in getting something like list(a=c(1=1), b=c(1=2, 2=5), c=c(1=3), d=c(1=4), e=c(1=6)) for the above input. By giving the result this way I'm able to extract both names from two sets as well as the according value between both items. One point could be to build a matrix but this matrix would have many NA's. So I prefer Lists of Lists. Any ideas? cheers Jan -Ursprüngliche Nachricht- Von: Liaw, Andy [mailto:[EMAIL PROTECTED] Gesendet: Montag, 15. August 2005 17:31 An: Jan Hummel; r-help@stat.math.ethz.ch Betreff: RE: [R] Re-sort list of vectors If all vectors in the list have the same length, why not use a matrix? Then you'd just transpose the matrix if you need to. If you really have to have it as a list, here's one possibility: x - list(1=c(a=1, b=2, c=3), 2=c(a=4, b=5, c=6)) x $1 a b c 1 2 3 $2 a b c 4 5 6 as.list(as.data.frame(t(matrix(unlist(x), nrow=3 $V1 [1] 1 4 $V2 [1] 2 5 $V3 [1] 3 6 Andy From: Jan Hummel Hi. Can anyone suggest a simple way to re-sort in R a list of vectors of the following form? input $1 a b c 1 2 3 $2 a b c 4 5 6 Output should be something like: a 1 1 2 4 b 1 2 2 5 c 1 3 2 6 I've been futzing with mapply(), outer(), split(), rbind() and so on but haven't found an elegant solution. Thanks, Jan. P.S. E-mailed CCs of posted replies appreciated. __ 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 __ 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 __ 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 -- Jim Holtman Convergys +1 513 723 2929 What the problem you are trying to solve? __ 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
Re: [R] PCA problem in R
On Mon, 15 Aug 2005, Dennis Shea wrote: [SNIP] On Sat, 13 Aug 2005, Alan Zhao wrote: When I have more variables than units, say a 195*10896 matrix which has 10896 variables and 195 samples. prcomp will give only 195 principal components. I checked in the help, but there is no explanation that why this happen. [SNIP] Sincerely, Zheng Zhao Aug-14-2005 __ Just yesterday I subscribed to r-help because I am planning on learning the basics of R ... today. :-) Thus, I am not sure about the history of this question. The above situation, more variables than samples, is commonly encounterd in the climate studies. Consider annual mean temperatures for 195 years on a coarse 72 [lat] x 144 [lon] grid [72*144=10368 spatial variables]. Which are variables and which are samples here? In standard statistical parlance you have 195 variables at 10368 samples. In some fields there are the concepts of R-mode and Q-mode PCA, and you seem to be in Q-mode, which is why you have a transpose. Let S be the number of grid points and T be the number of years. I think there is a theorem (?Eckart-Young?) which states that the maximum number of unique eigenvalues is min(S,T). In your case 195 eigenvalues is correct. Eigenvalues of what? Eckart-Young is about the SVD, see e.g. http://voteview.com/ideal_point_Eckart_Young_Theorem.htm as Googling easily shows. (It is used to prove some of the approximation properties of PCA, e.g. in http://www.stats.ox.ac.uk/~ripley/MultAnal_MT2004/PCA.pdf) I speculate that the underlying function transposes the input data matrix and computes the the TxT [rather than SxS] covariance matrix and solves for the eigenvalues/vectors. It then uses a linear transformation to get the results for the original input data matrix. Computationally, the above is much faster and uses less memory. You speculate incorrectly, even in your Q-mode view of the world. The real point is that is solves a different problem, which is what my answer to the original post was about. PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html It really would be a good idea to do the homework it suggests. -- 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
Re: [R] paste / system mystery
On Mon, 15 Aug 2005 [EMAIL PROTECTED] wrote: Dear R wizards: under R-2.1.0: eargs - 3:5; line - paste(c(echo A B, eargs)); cat(executing from R: ', line, '\n); system(line); Oddly, only A and B are echoed, not the eargs. I had hoped that line would be one string at this point, and for printing this seems to be true. However, unlist(line) still gives me the 4 components. It almost seems like the objects were not really pasted, but kept separate [perhaps to conserve memory]---which works internally, but not externally. Is this my poor understanding of R, an R feature, or an R bug? It's your understanding. Look at the `collapse' argument to paste(). -thomas __ 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
Re: [R] paste / system mystery
On 8/15/05, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Dear R wizards: under R-2.1.0: eargs - 3:5; line - paste(c(echo A B, eargs)); cat(executing from R: ', line, '\n); system(line); Oddly, only A and B are echoed, not the eargs. I had hoped that line would be one string at this point, and for printing this seems to be true. However, unlist(line) still gives me the 4 components. It almost seems like the objects were not really pasted, but kept separate [perhaps to conserve memory]---which works internally, but not externally. Is this my poor understanding of R, an R feature, or an R bug? Poor understanding but the mistake is a common one. If you want to form a character vector of length 1 you must use the collapse argument to paste(). Try eargs - 3:5 paste(echo A B, paste(eargs, collapse = )) [1] echo A B 3 4 5 __ 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
Re: [R] paste / system mystery
[EMAIL PROTECTED] wrote: Dear R wizards: under R-2.1.0: eargs - 3:5; line - paste(c(echo A B, eargs)); cat(executing from R: ', line, '\n); system(line); Oddly, only A and B are echoed, not the eargs. I had hoped that line would be one string at this point, and for printing this seems to be true. However, unlist(line) still gives me the 4 components. It almost seems like the objects were not really pasted, but kept separate [perhaps to conserve memory]---which works internally, but not externally. Is this my poor understanding of R, an R feature, or an R bug? Feature: The arguments of paste() get pasted, and you have just specified one argument which is a character *vector*. You want to say that the elements of the vector should be pasted as follows: line - paste(c(echo A B, eargs), collapse = ) Uwe Ligges help appreciated. /iaw --- ivo welch __ 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 __ 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
Re: [R] Compilation failures: mgcv, spatstat, Matrix, cluster
On 8/13/05, Paul Roebuck [EMAIL PROTECTED] wrote: On Sat, 13 Aug 2005, Michael Kubovy wrote: With Version 2.1.1 (2005-06-20) on Power Mac G5 running Mac OS X 10.4.2 (8C46): Some compilations work (e.g., MatchIt, RGraphics, Zelig), and some don't, e.g., mgcv, spatstat, and the following (Matrix, cluster): trying URL 'http://www.ibiblio.org/pub/languages/R/CRAN/src/contrib/ Matrix_0.98-3.tar.gz' Content type 'application/x-tar' length 626712 bytes opened URL == downloaded 612Kb * Installing *source* package 'Matrix' ... ** libs The downloaded packages are in /private/tmp/RtmpPddsAE/downloaded_packages gcc-3.3 -no-cpp-precomp -I/Library/Frameworks/R.framework/Resources/ include -I/usr/local/include -I./Metis -fno-common -g -O2 -c HBMM.c -o HBMM.o In file included from HBMM.c:2: iohb.h:6:19: malloc.h: No such file or directory make: *** [HBMM.o] Error 1 ERROR: compilation failed for package 'Matrix' Didn't check package for actually functioning correctly, but the following changes will allow compilation on OS X 10.3. In ANSI C, the standard memory allocation routines are declared in stdlib.h; malloc.h is obsolete for that purpose and isn't guaranteed to exist. Matrix/src/mmio.c: Add #include stdlib.h Remove #include malloc.h Matrix/src/iohb.h: Remove #include malloc.h Thanks for the suggestion, Paul. I wasn't quite as sloppy as it may seem. I recently introduced the iohb.[hc] and mmio.[hc] files from NIST into the Matrix package but I didn't check them thoroughly before doing so. I should have. Those are not the only antiquated C constructs in those files. The author of iohb.c also assumes that he can pass a string constant to a function that modifies the contents of that argument and, of course, gcc will produce code that segfaults at that point if you do not use -fwriteable-strings and we don't want to do that. __ 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
Re: [R] How to insert a certain model in SVM regarding to fixed kernels
Dear David, Dear Gabor , Dear All, Many thanks for your reply and informative emails. Actually I think it is difficult to define for example a regression model within a SVM framework theoretically and experimentaly. What we have to do is that we work on input data to construct model befor entering data into SVM. This procedure ( building a certain model) can be viewed as a preprocessing of data and or model building. Doesn't it? Parametric models are basically rejected, because SVM learns only nonparametric ones. I would be very appreciated again if I have any correction or guidance. Have a fun, Amir [EMAIL PROTECTED] wrote: On 8/12/05, Gabor Grothendieck wrote: David, Please correct me if I am wrong but I think svm partially works with dyn although I don't remember what the specific limitations were. Its possible that what works already is enough for Amir. For example, library(e1071) library(dyn) set.seed(1) y - ts(rnorm(100)) y.svm - dyn$svm(y ~ lag(y)) The above statement should have been y.svm - dyn$svm(y ~ lag(y,-1)) since we want to bring the previous value of y forward so that it is being used to predict y (rather than predicting y by bringing the future value of y backward). In R positive values for the lag move the series backward and negative values move it forward. yp - predict(y.svm) ts.plot(y, yp, col = 1:2) On 8/12/05, David Meyer wrote: Amir, Suppose that we want to regress for example a certain autoregressive model using SVM. We have our data and also some fixed kernels in libSVM behinde e1071 in front. The question: Where can we insert our certain autoregressive model ? During creating data frame ? Yes, I think. Or perhaps we can make a relationship between our variables ended to desired autoregressive model ? Gabor Grothendieck's `dyn` package provides support for the use of general regression functions for time series analysis, and we are currently struggling to integrate the e1071 interface into that framework (but nothing is ready so far). Is it that kind of support you have been looking for? Cheers, David Thanks a lot for your help. Amir Safari __ Do You Yahoo!? http://mail.yahoo.com -- Dr. David Meyer Department of Information Systems and Operations Vienna University of Economics and Business Administration Augasse 2-6, A-1090 Wien, Austria, Europe Fax: +43-1-313 36x746 Tel: +43-1-313 36x4393 HP: http://wi.wu-wien.ac.at/~meyer/ __ 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 __ [[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
Re: [R] monte carlo simulations/lmer
On 8/13/05, Eduardo Leoni [EMAIL PROTECTED] wrote: Hi - I am doing some monte carlo simulations comparing bayesian (using Plummer's jags) and maximum likelihood (using lmer from package lme4 by Bates et al). I would like to know if there is a way I can flag nonconvergence and exceptions. Currently the simulations just stop and the output reads things like: Error in optim(.Call(lmer_coef, x, 2, PACKAGE = Matrix), fn, gr, method = L-BFGS-B, : L-BFGS-B needs finite values of 'fn' In addition: Warning message: Leading minor of size 1 of downdated X'X is indefinite Error in .local(object, ...) : Leading 2 minor of Omega[[1]] not positive definite In addition: Warning messages: 1: optim or nlminb returned message ERROR: ABNORMAL_TERMINATION_IN_LNSRCH in: LMEoptimize-(`*tmp*`, value = list(maxIter = 200, msMaxIter = 200, 2: optim or nlminb returned message ERROR: ABNORMAL_TERMINATION_IN_LNSRCH in: LMEoptimize-(`*tmp*`, value = list(maxIter = 200, msMaxIter = 200, As Rolf Turner indicated, you can wrap the call to lmer in try() to prevent breaking the loop on convergence failure. I'm not sure exactly what Bayesian analysis you are doing but you may want to look at the function mcmcsamp in versions 0.98-1and later of the Matrix package. It can take a fitted lmer object and create an MCMC sample from the posterior distribution of the parameters assuming a locally uniform prior on the fixed-effects parameters and the non-informative prior described by Box and Tiao for the variance-covariance matrices. __ 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
[R] randomForest Error passing string argument
I'm attempting to pass a string argument into the function randomForest but I get an error: state - paste(list(fruit ~, apples+oranges+blueberries, data=fruits.data, mtry=2, do.trace=100, na.action=na.omit, keep.forest=TRUE), sep= , collapse=) model.rf - randomForest(state) Error in if (n==0) stop (data(x) has 0 rows) argument is of length zero. -Thanks in advance, __ 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
[R] How to get a list work in RData file
Dear R-Helper, I want to know how I get a list work which I saved in RData file. For example, test.xy - function(x,y) { +xy - x+y +xy + } xyadd - test.xy(x=2, y=3) xyadd [1] 5 x1 - c(2,43,60,8) y1 - c(91,7,5,30) xyadd1 - test.xy(x=x1, y=y1) xyadd1 [1] 93 50 65 38 save(list = ls(all=TRUE), file = testxy.RData) rm(list=ls(all=TRUE)) load(C:/R/useR/testxy.RData) ls() [1] test.xy x1 xyadd xyadd1 y1 ls.str(pat=xyadd) xyadd : num 5 xyadd1 : num [1:4] 93 50 65 38 When I run, I know the result like above xyadd [1] 5 xyadd1 [1] 93 50 65 38 what I want to know, is there any function to make the result like: xyadd test.xy(x=2, y=3) and xyadd1 test.xy(x=x1, y=y1) Best, Xiyan Lon __ 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
[R] How to repeat code snippet for several variables in a data frame?
Dear all, I have a data frame containing the results of an experiment. Like this: a-seq(1,4,by=1) b-seq(1,2,by=1) test-expand.grid(b,a,a) colnames(test)-c(replicates,bins, groups) test$abc - rnorm(32) test$def - rnorm(32) test$ghi - rnorm(32) test The following code snippet aggregates the data for one variable and then draws a plot: tmp - aggregate(test$abc, list( test$bins, test$groups), mean) colnames(tmp) - c(bins, groups, abc) tmp #pltName - paste(line_datGrassChem_, abc, .eps, sep=) #postscript(pltName) labs - c(-15/-9,-9/-6,-6/-3,-3/0) sps - trellis.par.get(superpose.symbol) sps$pch - 1:4 trellis.par.set(superpose.symbol, sps) xyplot( abc ~ bins, data = tmp, groups = groups, type = list(p, l), scales = list(x = list(labels=labs)), layout = c(1,1), key = list(columns = 4, text = list(paste(unique(tmp$groups))), points = Rows(sps, 1:4) ) ) #dev.off() How can I wrap R code around this code snippet, such that I can repeat the same code snippet for all other variables in the data frame (i.e. def, ghi, etc.). Thanks for your suggestions! Sander. -- Dr Sander P. Oom Animal, Plant and Environmental Sciences, University of the Witwatersrand Private Bag 3, Wits 2050, South Africa Tel (work) +27 (0)11 717 64 04 Tel (home) +27 (0)18 297 44 51 Fax +27 (0)18 299 24 64 Email [EMAIL PROTECTED] Web www.oomvanlieshout.net/sander __ 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
Re: [R] Manually Calculating Odds from POLR Model
John, Thank you, the document was very helpful. I can now calculate the same values generated by predict() when I am using purely numeric input data. Another small question arises when I look at the example using 'housing' in the polr() documentation page: Running the example produces the following coefficients... Coefficients: InflMedium InflHigh TypeApartmentTypeAtrium TypeTerrace ContHigh 0.5663924 1.2888218-0.5723552-0.3661912-1.0910195 0.3602834 Now, if I am trying to perform a prediction and the value for INFL comes in as 'Medium' what is done? And, what is done for 'low'? That seems to be the last missing piece in my understanding of how to convert the model values into predictions. Thank you, Tate From: John Fox [EMAIL PROTECTED] To: 'Tate Avery' [EMAIL PROTECTED] CC: r-help@stat.math.ethz.ch Subject: RE: [R] Manually Calculating Odds from POLR Model Date: Fri, 12 Aug 2005 19:22:23 -0400 Dear Tate, If I understand correctly what you're asking, the formulas are on p. 21 of the paper at http://socserv.socsci.mcmaster.ca/jfox/Papers/logit-effect-displays.pdf. But why do you want to do this when you can get the fitted probabilities from predict()? I hope this helps. John John Fox Department of Sociology McMaster University Hamilton, Ontario Canada L8S 4M4 905-525-9140x23604 http://socserv.mcmaster.ca/jfox -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tate Avery Sent: Friday, August 12, 2005 2:50 PM To: r-help@stat.math.ethz.ch Subject: [R] Manually Calculating Odds from POLR Model Hello, I am using polr(...) to generate a model. The summary shows the coefficients and the intercepts. For example: coefficient for x1 = c1 coefficient for x2 = c2 intercept A|B = i1 intercept B|C = i2 I can then run predict(..., type=p) with the model and see the odds for each factor. For example: ABC 10.3 0.5 0.2 20.4 0.1 0.5 What I really want to be able to do is take the 2 coefficients, the 2 intercepts, the x1 x2 values and manually calculate the probabilities generated by predict(). I have been searching quite extensively for the underlying calculations that transform the polr output and the input variables into the final output odds. I have tried a number of dead-end roads so far. So, if anyone has any information on how to do this or where I can find out, I would be extremely grateful. Thank you for your time, Tate Avery __ 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 __ 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
[R] R CMD check failure on minimal code
I have a peculiar problem that I'm sure is a simple one, but I can't figure out what my mistake is. Can someone enlighten me? I have a simple file, class.R: ## setClass(abc,representation(a = character, b = ANY)) I have a package directory ExpressCGH1 made with package.skeleton. The package happily builds and installs, but R CMD check fails with (ignoring the documenation warnings, etc.): version _ platform powerpc-apple-darwin7.9.0 arch powerpc os darwin7.9.0 system powerpc, darwin7.9.0 status Patched major2 minor1.1 year 2005 month08 day 12 language R %%% R CMD check -l '/User s/sdavis/Library/R/library' ExpressCGH1 * checking for working latex ... OK * using log directory '/Users/sdavis/Work/R-Programs/packages/devel/ExpressCGH/E xpressCGH1.Rcheck' * using R version 2.1.1, 2005-08-12 * checking for file 'ExpressCGH1/DESCRIPTION' ... OK * checking extension type ... Package * this is package 'ExpressCGH1' version '1.0' * checking if this is a source package ... OK * Installing *source* package 'ExpressCGH1' ... ** libs WARNING: no source files found chmod: /Users/sdavis/Library/R/library/ExpressCGH1/libs/*: No such file or direc tory ** R ** help Building/Updating help pages for package 'ExpressCGH1' Formats: text html latex example convertDNAcopyOutput texthtmllatex example missing link(s): ~~fun~~ ** building package indices ... * DONE (ExpressCGH1) * checking package directory ... OK * checking for portable file names ... OK * checking for sufficient/correct file permissions ... OK * checking DESCRIPTION meta-information ... OK * checking package dependencies ... OK * checking index information ... OK * checking package subdirectories ... WARNING Subdirectory 'src' contains no source files. * checking R files for syntax errors ... OK * checking R files for library.dynam ... OK * checking S3 generic/method consistency ... WARNING Error: unable to load R code in package 'ExpressCGH1' Call sequence: 2: stop(gettextf(unable to load R code in package '%s', libraryPkgName(package )), call. = FALSE, domain = NA) 1: library(package, lib.loc = lib.loc, character.only = TRUE, verbose = FALSE) Execution halted See section 'Generic functions and methods' of the 'Writing R Extensions' manual. * checking replacement functions ... WARNING Error: unable to load R code in package 'ExpressCGH1' Call sequence: 2: stop(gettextf(unable to load R code in package '%s', libraryPkgName(package )), call. = FALSE, domain = NA) 1: library(package, lib.loc = lib.loc, character.only = TRUE, verbose = FALSE) Execution halted In R, the argument of a replacement function which corresponds to the right hand side must be named 'value'. * checking foreign function calls ... WARNING Error: unable to load R code in package 'ExpressCGH1' Call sequence: 2: stop(gettextf(unable to load R code in package '%s', libraryPkgName(package )), call. = FALSE, domain = NA) 1: library(package, lib.loc = lib.loc, character.only = TRUE, verbose = FALSE) Execution halted See section 'System and foreign language interfaces' of the 'Writing R Extensions' manual. * checking Rd files ... WARNING Rd files with likely Rd problems: Unaccounted top-level text in file '/Users/sdavis/Work/R-Programs/packages/devel /ExpressCGH/ExpressCGH1/man/convertDNAcopyOutput.Rd': Following section 'note': \n\n ~Make other sections like Warning with \\section{Warning }{} ~\n\n Rd files with non-standard keywords: /Users/sdavis/Work/R-Programs/packages/devel/ExpressCGH/ExpressCGH1/man/conv er tDNAcopyOutput.Rd: ~kwd1 ~kwd2 Each '\keyword' entry should specify one of the standard keywords (as listed in file 'KEYWORDS.db' in the 'doc' subdirectory of the R home directory). See chapter 'Writing R documentation files' in manual 'Writing R Extensions'. * checking for missing documentation entries ... ERROR Error: unable to load R code in package 'ExpressCGH1' __ 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
Re: [R] How to get a list work in RData file
On Mon, 15 Aug 2005, Xiyan Lon wrote: Dear R-Helper, (There are quite a few of us.) I want to know how I get a list work which I saved in RData file. For example, I don't understand that at all, but it looks as if you want to save an unevaluated call, in which case see ?quote and use something like xyadd - quote(test.xy(x=2, y=3)) load and saving has nothing to do with this: it doesn't change the meaning of objects in the workspace. test.xy - function(x,y) { +xy - x+y +xy + } xyadd - test.xy(x=2, y=3) xyadd [1] 5 x1 - c(2,43,60,8) y1 - c(91,7,5,30) xyadd1 - test.xy(x=x1, y=y1) xyadd1 [1] 93 50 65 38 save(list = ls(all=TRUE), file = testxy.RData) rm(list=ls(all=TRUE)) load(C:/R/useR/testxy.RData) ls() [1] test.xy x1 xyadd xyadd1 y1 ls.str(pat=xyadd) xyadd : num 5 xyadd1 : num [1:4] 93 50 65 38 When I run, I know the result like above xyadd [1] 5 xyadd1 [1] 93 50 65 38 what I want to know, is there any function to make the result like: xyadd test.xy(x=2, y=3) and xyadd1 test.xy(x=x1, y=y1) -- 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
Re: [R] R CMD check failure on minimal code
Did you remember to declare a dependency on package 'methods'? I suspect not. Please see `Writing R Extensions'. setClass is not part of base R, and those checks are being run with base R only. I expect your package will not load when R is run with no default packages. (Quite a few people run R without package 'methods' for speed, especially on startup -- it takes about half the startup time.) On Mon, 15 Aug 2005, Sean Davis wrote: I have a peculiar problem that I'm sure is a simple one, but I can't figure out what my mistake is. Can someone enlighten me? I have a simple file, class.R: ## setClass(abc,representation(a = character, b = ANY)) I have a package directory ExpressCGH1 made with package.skeleton. The package happily builds and installs, but R CMD check fails with (ignoring the documenation warnings, etc.): version _ platform powerpc-apple-darwin7.9.0 arch powerpc os darwin7.9.0 system powerpc, darwin7.9.0 status Patched major2 minor1.1 year 2005 month08 day 12 language R %%% R CMD check -l '/User s/sdavis/Library/R/library' ExpressCGH1 * checking for working latex ... OK * using log directory '/Users/sdavis/Work/R-Programs/packages/devel/ExpressCGH/E xpressCGH1.Rcheck' * using R version 2.1.1, 2005-08-12 * checking for file 'ExpressCGH1/DESCRIPTION' ... OK * checking extension type ... Package * this is package 'ExpressCGH1' version '1.0' * checking if this is a source package ... OK * Installing *source* package 'ExpressCGH1' ... ** libs WARNING: no source files found chmod: /Users/sdavis/Library/R/library/ExpressCGH1/libs/*: No such file or direc tory ** R ** help Building/Updating help pages for package 'ExpressCGH1' Formats: text html latex example convertDNAcopyOutput texthtmllatex example missing link(s): ~~fun~~ ** building package indices ... * DONE (ExpressCGH1) * checking package directory ... OK * checking for portable file names ... OK * checking for sufficient/correct file permissions ... OK * checking DESCRIPTION meta-information ... OK * checking package dependencies ... OK * checking index information ... OK * checking package subdirectories ... WARNING Subdirectory 'src' contains no source files. * checking R files for syntax errors ... OK * checking R files for library.dynam ... OK * checking S3 generic/method consistency ... WARNING Error: unable to load R code in package 'ExpressCGH1' Call sequence: 2: stop(gettextf(unable to load R code in package '%s', libraryPkgName(package )), call. = FALSE, domain = NA) 1: library(package, lib.loc = lib.loc, character.only = TRUE, verbose = FALSE) Execution halted See section 'Generic functions and methods' of the 'Writing R Extensions' manual. * checking replacement functions ... WARNING Error: unable to load R code in package 'ExpressCGH1' Call sequence: 2: stop(gettextf(unable to load R code in package '%s', libraryPkgName(package )), call. = FALSE, domain = NA) 1: library(package, lib.loc = lib.loc, character.only = TRUE, verbose = FALSE) Execution halted In R, the argument of a replacement function which corresponds to the right hand side must be named 'value'. * checking foreign function calls ... WARNING Error: unable to load R code in package 'ExpressCGH1' Call sequence: 2: stop(gettextf(unable to load R code in package '%s', libraryPkgName(package )), call. = FALSE, domain = NA) 1: library(package, lib.loc = lib.loc, character.only = TRUE, verbose = FALSE) Execution halted See section 'System and foreign language interfaces' of the 'Writing R Extensions' manual. * checking Rd files ... WARNING Rd files with likely Rd problems: Unaccounted top-level text in file '/Users/sdavis/Work/R-Programs/packages/devel /ExpressCGH/ExpressCGH1/man/convertDNAcopyOutput.Rd': Following section 'note': \n\n ~Make other sections like Warning with \\section{Warning }{} ~\n\n Rd files with non-standard keywords: /Users/sdavis/Work/R-Programs/packages/devel/ExpressCGH/ExpressCGH1/man/conv er tDNAcopyOutput.Rd: ~kwd1 ~kwd2 Each '\keyword' entry should specify one of the standard keywords (as listed in file 'KEYWORDS.db' in the 'doc' subdirectory of the R home directory). See chapter 'Writing R documentation files' in manual 'Writing R Extensions'. * checking for missing documentation entries ... ERROR Error: unable to load R code in package 'ExpressCGH1' __ 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 -- 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
Re: [R] R CMD check failure on minimal code
On 8/15/05, Sean Davis [EMAIL PROTECTED] wrote: I have a peculiar problem that I'm sure is a simple one, but I can't figure out what my mistake is. Can someone enlighten me? I have a simple file, class.R: ## setClass(abc,representation(a = character, b = ANY)) I have a package directory ExpressCGH1 made with package.skeleton. The package happily builds and installs, but R CMD check fails with (ignoring the documenation warnings, etc.): Can you declare a slot to have class ANY? You can use class ANY in a method signature but I don't think you can use it for a slot. Try to see if you can attach the package in R. That may give more informative errors. version _ platform powerpc-apple-darwin7.9.0 arch powerpc os darwin7.9.0 system powerpc, darwin7.9.0 status Patched major2 minor1.1 year 2005 month08 day 12 language R %%% R CMD check -l '/User s/sdavis/Library/R/library' ExpressCGH1 * checking for working latex ... OK * using log directory '/Users/sdavis/Work/R-Programs/packages/devel/ExpressCGH/E xpressCGH1.Rcheck' * using R version 2.1.1, 2005-08-12 * checking for file 'ExpressCGH1/DESCRIPTION' ... OK * checking extension type ... Package * this is package 'ExpressCGH1' version '1.0' * checking if this is a source package ... OK * Installing *source* package 'ExpressCGH1' ... ** libs WARNING: no source files found chmod: /Users/sdavis/Library/R/library/ExpressCGH1/libs/*: No such file or direc tory ** R ** help Building/Updating help pages for package 'ExpressCGH1' Formats: text html latex example convertDNAcopyOutput texthtmllatex example missing link(s): ~~fun~~ ** building package indices ... * DONE (ExpressCGH1) * checking package directory ... OK * checking for portable file names ... OK * checking for sufficient/correct file permissions ... OK * checking DESCRIPTION meta-information ... OK * checking package dependencies ... OK * checking index information ... OK * checking package subdirectories ... WARNING Subdirectory 'src' contains no source files. * checking R files for syntax errors ... OK * checking R files for library.dynam ... OK * checking S3 generic/method consistency ... WARNING Error: unable to load R code in package 'ExpressCGH1' Call sequence: 2: stop(gettextf(unable to load R code in package '%s', libraryPkgName(package )), call. = FALSE, domain = NA) 1: library(package, lib.loc = lib.loc, character.only = TRUE, verbose = FALSE) Execution halted See section 'Generic functions and methods' of the 'Writing R Extensions' manual. * checking replacement functions ... WARNING Error: unable to load R code in package 'ExpressCGH1' Call sequence: 2: stop(gettextf(unable to load R code in package '%s', libraryPkgName(package )), call. = FALSE, domain = NA) 1: library(package, lib.loc = lib.loc, character.only = TRUE, verbose = FALSE) Execution halted In R, the argument of a replacement function which corresponds to the right hand side must be named 'value'. * checking foreign function calls ... WARNING Error: unable to load R code in package 'ExpressCGH1' Call sequence: 2: stop(gettextf(unable to load R code in package '%s', libraryPkgName(package )), call. = FALSE, domain = NA) 1: library(package, lib.loc = lib.loc, character.only = TRUE, verbose = FALSE) Execution halted See section 'System and foreign language interfaces' of the 'Writing R Extensions' manual. * checking Rd files ... WARNING Rd files with likely Rd problems: Unaccounted top-level text in file '/Users/sdavis/Work/R-Programs/packages/devel /ExpressCGH/ExpressCGH1/man/convertDNAcopyOutput.Rd': Following section 'note': \n\n ~Make other sections like Warning with \\section{Warning }{} ~\n\n Rd files with non-standard keywords: /Users/sdavis/Work/R-Programs/packages/devel/ExpressCGH/ExpressCGH1/man/conv er tDNAcopyOutput.Rd: ~kwd1 ~kwd2 Each '\keyword' entry should specify one of the standard keywords (as listed in file 'KEYWORDS.db' in the 'doc' subdirectory of the R home directory). See chapter 'Writing R documentation files' in manual 'Writing R Extensions'. * checking for missing documentation entries ... ERROR Error: unable to load R code in package 'ExpressCGH1' __ 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 __ 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
[R] Anything like dir.choose (similar to file.choose) in R?
Does R have a dir.choose function? I can use file.choose like this as a kludge to get something like a dir.choose, but a real dir.choose would be better: cat(Select one of files in directory to process:\n) filename - gsub(, /, file.choose()) basepath - dirname(filename) Windows provides a lower-level SHBrowseForFolder function to create such a dialog (see links below). Do other platforms have similar functionality at a lower level? (Hoping this would be an easy addition to R.) SHBrowseForFolder Function http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/shbrowseforfolder.asp Using the Shell API function SHBrowseForFolder() http://community.borland.com/article/0,1410,17008,00.html efg -- Earl F. Glynn Bioinformatics Stowers Institute for Medical Research __ 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
[R] queer data set
I have a dataset that is basically structureless. Its dimension varies from row to row and sep(s) are a mixture of tab and semi colon (;) and example is HEADER1 HEADER2 HEADER3 HEADER3 A1 B1 C1 X11;X12;X13 A2 B2 C2 X21;X22;X23;X24;X25 A3 B3 C3 A4 B4 C4 X41;X42;X43 A5 B5 C5 X51 etc., say. Note that a blank under HEADER3 corresponds to non occurance and all semi colon (;) delimited variables are under HEADER3. These values run into tens of thousands. I want to give some order to this queer matrix to something like: HEADER1 HEADER2 HEADER3 HEADER3 A1 B1 C1 X11 A1 B1 C1 X12 A1 B1 C1 X13 A1 B1 C1 X14 A2 B2 C2 X21 A2 B2 C2 X22 A2 B2 C2 X23 A2 B2 C2 X24 A2 B2 C2 X25 A2 B2 C2 X26 A3 B3 C3 NA A4 B4 C4 X41 A4 B4 C4 X42 A4 B4 C4 X43 Is there a brilliant R-way of doing such task? Goodday. Stephen. - Original Message - From: Prof Brian Ripley [EMAIL PROTECTED] Date: Monday, August 15, 2005 11:13 pm Subject: Re: [R] How to get a list work in RData file On Mon, 15 Aug 2005, Xiyan Lon wrote: Dear R-Helper, (There are quite a few of us.) I want to know how I get a list work which I saved in RData file. For example, I don't understand that at all, but it looks as if you want to save an unevaluated call, in which case see ?quote and use something like xyadd - quote(test.xy(x=2, y=3)) load and saving has nothing to do with this: it doesn't change the meaning of objects in the workspace. test.xy - function(x,y) { +xy - x+y +xy + } xyadd - test.xy(x=2, y=3) xyadd [1] 5 x1 - c(2,43,60,8) y1 - c(91,7,5,30) xyadd1 - test.xy(x=x1, y=y1) xyadd1 [1] 93 50 65 38 save(list = ls(all=TRUE), file = testxy.RData) rm(list=ls(all=TRUE)) load(C:/R/useR/testxy.RData) ls() [1] test.xy x1 xyadd xyadd1 y1 ls.str(pat=xyadd) xyadd : num 5 xyadd1 : num [1:4] 93 50 65 38 When I run, I know the result like above xyadd [1] 5 xyadd1 [1] 93 50 65 38 what I want to know, is there any function to make the result like: xyadd test.xy(x=2, y=3) and xyadd1 test.xy(x=x1, y=y1) -- 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 __ 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
Re: [R] Manually Calculating Odds from POLR Model
Dear Tate, Your question pertains generally to the treatment of factors in model formulas and is not particular to polr(). For a brief explanation, see Section 11.1, Defining statistical models; formulae, and in particular Section 11.1.1 on Contrasts in the manual An Introduction to R, which is distributed with R. More detailed explanations are in texts such as Venables and Ripley, Modern Applied Statistics With S, and my own, An R and S-PLUS Companion to Applied Regression. I hope this helps, John John Fox Department of Sociology McMaster University Hamilton, Ontario Canada L8S 4M4 905-525-9140x23604 http://socserv.mcmaster.ca/jfox -Original Message- From: Tate Avery [mailto:[EMAIL PROTECTED] Sent: Monday, August 15, 2005 3:58 PM To: [EMAIL PROTECTED] Cc: r-help@stat.math.ethz.ch Subject: RE: [R] Manually Calculating Odds from POLR Model John, Thank you, the document was very helpful. I can now calculate the same values generated by predict() when I am using purely numeric input data. Another small question arises when I look at the example using 'housing' in the polr() documentation page: Running the example produces the following coefficients... Coefficients: InflMedium InflHigh TypeApartmentTypeAtrium TypeTerrace ContHigh 0.5663924 1.2888218-0.5723552-0.3661912 -1.0910195 0.3602834 Now, if I am trying to perform a prediction and the value for INFL comes in as 'Medium' what is done? And, what is done for 'low'? That seems to be the last missing piece in my understanding of how to convert the model values into predictions. Thank you, Tate From: John Fox [EMAIL PROTECTED] To: 'Tate Avery' [EMAIL PROTECTED] CC: r-help@stat.math.ethz.ch Subject: RE: [R] Manually Calculating Odds from POLR Model Date: Fri, 12 Aug 2005 19:22:23 -0400 Dear Tate, If I understand correctly what you're asking, the formulas are on p. 21 of the paper at http://socserv.socsci.mcmaster.ca/jfox/Papers/logit-effect-d isplays.pdf. But why do you want to do this when you can get the fitted probabilities from predict()? I hope this helps. John John Fox Department of Sociology McMaster University Hamilton, Ontario Canada L8S 4M4 905-525-9140x23604 http://socserv.mcmaster.ca/jfox -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tate Avery Sent: Friday, August 12, 2005 2:50 PM To: r-help@stat.math.ethz.ch Subject: [R] Manually Calculating Odds from POLR Model Hello, I am using polr(...) to generate a model. The summary shows the coefficients and the intercepts. For example: coefficient for x1 = c1 coefficient for x2 = c2 intercept A|B = i1 intercept B|C = i2 I can then run predict(..., type=p) with the model and see the odds for each factor. For example: ABC 10.3 0.5 0.2 20.4 0.1 0.5 What I really want to be able to do is take the 2 coefficients, the 2 intercepts, the x1 x2 values and manually calculate the probabilities generated by predict(). I have been searching quite extensively for the underlying calculations that transform the polr output and the input variables into the final output odds. I have tried a number of dead-end roads so far. So, if anyone has any information on how to do this or where I can find out, I would be extremely grateful. Thank you for your time, Tate Avery __ 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 __ 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
Re: [R] queer data set
Here's one way of working with the data you gave: x - read.table(file(clipboard), fill=T, header=T) x HEADER1 HEADER2 HEADER3 HEADER3.1 1 A1 B1 C1 X11;X12;X13 2 A2 B2 C2 X21;X22;X23;X24;X25 3 A3 B3 C3 4 A4 B4 C4 X41;X42;X43 5 A5 B5 C5 X51 apply(x, 1, function(x) strsplit(x[4], ;)[[1]]) $1 [1] X11 X12 X13 $2 [1] X21 X22 X23 X24 X25 $3 character(0) $4 [1] X41 X42 X43 $5 [1] X51 do.call(rbind, apply(x, 1, function(x) { +y - strsplit(x[4], ;)[[1]] +x3 - matrix(x[1:3], ncol=3, nrow=max(1,length(y)), byrow=T) +return(cbind(x3, if (length(y)) y else NA)) + })) [,1] [,2] [,3] [,4] [1,] A1 B1 C1 X11 [2,] A1 B1 C1 X12 [3,] A1 B1 C1 X13 [4,] A2 B2 C2 X21 [5,] A2 B2 C2 X22 [6,] A2 B2 C2 X23 [7,] A2 B2 C2 X24 [8,] A2 B2 C2 X25 [9,] A3 B3 C3 NA [10,] A4 B4 C4 X41 [11,] A4 B4 C4 X42 [12,] A4 B4 C4 X43 [13,] A5 B5 C5 X51 This of course is a matrix; you can convert it back to a dataframe using as.data.frame() if you desire. Use either NA (with quotes) or NA (without quotes) to control whether you get just the string NA or an actual character NA value in column 4. If you're processing a huge amount of data, you can probably do better by rewriting the above code to avoid implicit coercions of data types. hope this helps, Tony Plate S.O. Nyangoma wrote: I have a dataset that is basically structureless. Its dimension varies from row to row and sep(s) are a mixture of tab and semi colon (;) and example is HEADER1 HEADER2 HEADER3 HEADER3 A1 B1 C1 X11;X12;X13 A2 B2 C2 X21;X22;X23;X24;X25 A3 B3 C3 A4 B4 C4 X41;X42;X43 A5 B5 C5 X51 etc., say. Note that a blank under HEADER3 corresponds to non occurance and all semi colon (;) delimited variables are under HEADER3. These values run into tens of thousands. I want to give some order to this queer matrix to something like: HEADER1 HEADER2 HEADER3 HEADER3 A1 B1 C1 X11 A1 B1 C1 X12 A1 B1 C1 X13 A1 B1 C1 X14 A2 B2 C2 X21 A2 B2 C2 X22 A2 B2 C2 X23 A2 B2 C2 X24 A2 B2 C2 X25 A2 B2 C2 X26 A3 B3 C3 NA A4 B4 C4 X41 A4 B4 C4 X42 A4 B4 C4 X43 Is there a brilliant R-way of doing such task? Goodday. Stephen. - Original Message - From: Prof Brian Ripley [EMAIL PROTECTED] Date: Monday, August 15, 2005 11:13 pm Subject: Re: [R] How to get a list work in RData file On Mon, 15 Aug 2005, Xiyan Lon wrote: Dear R-Helper, (There are quite a few of us.) I want to know how I get a list work which I saved in RData file. For example, I don't understand that at all, but it looks as if you want to save an unevaluated call, in which case see ?quote and use something like xyadd - quote(test.xy(x=2, y=3)) load and saving has nothing to do with this: it doesn't change the meaning of objects in the workspace. test.xy - function(x,y) { +xy - x+y +xy + } xyadd - test.xy(x=2, y=3) xyadd [1] 5 x1 - c(2,43,60,8) y1 - c(91,7,5,30) xyadd1 - test.xy(x=x1, y=y1) xyadd1 [1] 93 50 65 38 save(list = ls(all=TRUE), file = testxy.RData) rm(list=ls(all=TRUE)) load(C:/R/useR/testxy.RData) ls() [1] test.xy x1 xyadd xyadd1 y1 ls.str(pat=xyadd) xyadd : num 5 xyadd1 : num [1:4] 93 50 65 38 When I run, I know the result like above xyadd [1] 5 xyadd1 [1] 93 50 65 38 what I want to know, is there any function to make the result like: xyadd test.xy(x=2, y=3) and xyadd1 test.xy(x=x1, y=y1) -- 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 __ 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 __ 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
Re: [R] How to get a list work in RData file
Dear Prof. Brian, Why I need to know, because I lost my work and code which I used in my project. Lucky I always save my work which RData file. But I forgot which list, function, initial, etc I used. Xiyan Lon Prof Brian Ripley wrote: On Mon, 15 Aug 2005, Xiyan Lon wrote: Dear R-Helper, (There are quite a few of us.) I want to know how I get a list work which I saved in RData file. For example, I don't understand that at all, but it looks as if you want to save an unevaluated call, in which case see ?quote and use something like xyadd - quote(test.xy(x=2, y=3)) load and saving has nothing to do with this: it doesn't change the meaning of objects in the workspace. test.xy - function(x,y) { +xy - x+y +xy + } xyadd - test.xy(x=2, y=3) xyadd [1] 5 x1 - c(2,43,60,8) y1 - c(91,7,5,30) xyadd1 - test.xy(x=x1, y=y1) xyadd1 [1] 93 50 65 38 save(list = ls(all=TRUE), file = testxy.RData) rm(list=ls(all=TRUE)) load(C:/R/useR/testxy.RData) ls() [1] test.xy x1 xyadd xyadd1 y1 ls.str(pat=xyadd) xyadd : num 5 xyadd1 : num [1:4] 93 50 65 38 When I run, I know the result like above xyadd [1] 5 xyadd1 [1] 93 50 65 38 what I want to know, is there any function to make the result like: xyadd test.xy(x=2, y=3) and xyadd1 test.xy(x=x1, y=y1) __ 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
Re: [R] queer data set
On 15-Aug-05 S.O. Nyangoma wrote: I have a dataset that is basically structureless. Its dimension varies from row to row and sep(s) are a mixture of tab and semi colon (;) an example is HEADER1 HEADER2 HEADER3 HEADER3 A1 B1 C1 X11;X12;X13 A2 B2 C2 X21;X22;X23;X24;X25 A3 B3 C3 A4 B4 C4 X41;X42;X43 A5 B5 C5 X51 etc., say. Note that a blank under HEADER3 corresponds to non occurance and all semi colon (;) delimited variables are under HEADER3. These values run into tens of thousands. I want to give some order to this queer matrix to something like: HEADER1 HEADER2 HEADER3 HEADER3 A1 B1 C1 X11 A1 B1 C1 X12 A1 B1 C1 X13 A1 B1 C1 X14 A2 B2 C2 X21 A2 B2 C2 X22 A2 B2 C2 X23 A2 B2 C2 X24 A2 B2 C2 X25 A2 B2 C2 X26 A3 B3 C3 NA A4 B4 C4 X41 A4 B4 C4 X42 A4 B4 C4 X43 Is there a brilliant R-way of doing such task? Goodday. Stephen. I don't know about a brilliant R trick (though I'm sure others do). But (on my usual hobby-horse) if you have 'awk' available (and don't mind using it) then it will do the job: First create an 'awk' program file as follows: {for(i in A) delete A[i]} {if($4==){A[1]=NA} else {split($4,A,;)}} {B = $1 \t $2 \t $3} {for(i in A) print B \t A[i]} and call this say split.awk Then run awk -f split.awk and feed it the lines of your primary dataset as above. Here's a cutpaste from my Linux session, where the first block of lines after awk -f split.awk are the lines being input to the program, starting with the header, followed by the output of the program starting with the header again: awk -f split.awk HEADER1 HEADER2 HEADER3 HEADER3 A1 B1 C1 X11;X12;X13 A2 B2 C2 X21;X22;X23;X24;X25 A3 B3 C3 A4 B4 C4 X41;X42;X43 A5 B5 C5 X51 HEADER1 HEADER2 HEADER3 HEADER3 A1 B1 C1 X11 A1 B1 C1 X12 A1 B1 C1 X13 A2 B2 C2 X24 A2 B2 C2 X25 A2 B2 C2 X21 A2 B2 C2 X22 A2 B2 C2 X23 A3 B3 C3 NA A4 B4 C4 X41 A4 B4 C4 X42 A4 B4 C4 X43 A5 B5 C5 X51 In unixoid systems, with a large file of such lines, the command would be cat yourdatafile | awk -f split.awk and then you would only see the output, not the input as shown above, and you can of course redirect it into a new file with cat yourdatafile | awk -f split.awk newdatafile Note, however, that the order of the lines output for the third line of input (the one with X21;X22;X23;X24;X25) is not the same as the order of the X21;X22;X23;X24;X25 though they are all there. This is a feature of the way 'awk' handles arrays (which are associative arrays indexed by values, not by position). This may not matter for your application; but if it does matter then I'm not sure how to force the correct order. Hoping this helps, Ted. E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 094 0861 Date: 16-Aug-05 Time: 00:45:49 -- XFMail -- __ 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
Re: [R] Anything like dir.choose (similar to file.choose) in R?
If you can use the `tcltk' package, Prof. John Fox had pointed this out to me before: dir - tclvalue(tkchooseDirectory()) Andy From: Earl F. Glynn Does R have a dir.choose function? I can use file.choose like this as a kludge to get something like a dir.choose, but a real dir.choose would be better: cat(Select one of files in directory to process:\n) filename - gsub(, /, file.choose()) basepath - dirname(filename) Windows provides a lower-level SHBrowseForFolder function to create such a dialog (see links below). Do other platforms have similar functionality at a lower level? (Hoping this would be an easy addition to R.) SHBrowseForFolder Function http://msdn.microsoft.com/library/default.asp?url=/library/en- us/shellcc/platform/shell/reference/functions/shbrowseforfolder.asp Using the Shell API function SHBrowseForFolder() http://community.borland.com/article/0,1410,17008,00.html efg -- Earl F. Glynn Bioinformatics Stowers Institute for Medical Research __ 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 __ 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
[R] Overall Legend
Hello. I am using R version 2.1.1 on Windows 2000. I am using a par(mfrow=c(2,2)) statement to produce 4 plots on one screen. I want a single horizontal legend to appear at the top of the four plots. My code is something like this: par(mfrow=c(2,2)) plot(x,y1) lines(x,y2) lines(x,y3) plot(x,z1) lines(x,z2) lines(x,z3) plot(x,t1) lines(x,t2) lines(x,t3) plot(x,w1) lines(x,w2) lines(x,w3) Instead of the statement: legend(x=right, c(Bias Squared,Variance,Mean Squared Error), lty=c(2,1,3), col=c(green,blue,red), lwd=2,cex=0.5,inset = 0.05) appearing within each plot, I would like it to appear at the top of the graph because it applies to all four plots. Any help would be appreciated. Thank you. -Juned [[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
Re: [R] How to get a list work in RData file
If you want to keep track of the function call that produced an object, usually you need to do that inside the function that's being called, e.g., test.xy - function(x,y) { + xy - x+y + attr(xy, Call) - match.call() + xy + } xyadd - test.xy(x=2, y=3) xyadd [1] 5 attr(,Call) test.xy(x = 2, y = 3) str(xyadd) atomic [1:1] 5 - attr(*, Call)= language test.xy(x = 2, y = 3) Andy From: Xiyan Lon Dear R-Helper, I want to know how I get a list work which I saved in RData file. For example, test.xy - function(x,y) { +xy - x+y +xy + } xyadd - test.xy(x=2, y=3) xyadd [1] 5 x1 - c(2,43,60,8) y1 - c(91,7,5,30) xyadd1 - test.xy(x=x1, y=y1) xyadd1 [1] 93 50 65 38 save(list = ls(all=TRUE), file = testxy.RData) rm(list=ls(all=TRUE)) load(C:/R/useR/testxy.RData) ls() [1] test.xy x1 xyadd xyadd1 y1 ls.str(pat=xyadd) xyadd : num 5 xyadd1 : num [1:4] 93 50 65 38 When I run, I know the result like above xyadd [1] 5 xyadd1 [1] 93 50 65 38 what I want to know, is there any function to make the result like: xyadd test.xy(x=2, y=3) and xyadd1 test.xy(x=x1, y=y1) Best, Xiyan Lon __ 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 __ 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
Re: [R] randomForest Error passing string argument
If all you need the formula interface for is auto deletion of NAs, I'd suggest doing something like: varlist - c(fruit, apples, oranges, blueberries) fruits.nona - na.omit(fruits.data[varlist]) model.rf - randomForest(fruits.data[-1], fruits.data[[1]], ...) If you want to know the call that produced model.rf, you can look at model.rf$Call. I hope that sort of answers your question. Andy From: mmv I'm attempting to pass a string argument into the function randomForest but I get an error: state - paste(list(fruit ~, apples+oranges+blueberries, data=fruits.data, mtry=2, do.trace=100, na.action=na.omit, keep.forest=TRUE), sep= , collapse=) model.rf - randomForest(state) Error in if (n==0) stop (data(x) has 0 rows) argument is of length zero. -Thanks in advance, __ 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 __ 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
[R] return unique values from date/time class object
Background: OS: Linux Mandrake 10.1 release: R 2.1.1 editor: GNU Emacs 21.3.2 front-end: ESS 5.2.3 - Thanks to Brian Ripley (I've upgraded from source, thanks for the reminder) and Petr Pikal for their suggestions, but I have not made clear the form of my data: Browse[1] ceduna[1:10,] LSD AVIATION_ID WND_DIR WND_SPD_MPS 1 1/01/2001 10:30:00YCDU 230 4.6 2 1/01/2001 11:00:00YCDU 210 4.1 3 1/01/2001 11:30:00YCDU 230 6.7 4 1/01/2001 12:00:00YCDU 230 7.7 5 1/01/2001 12:30:00YCDU 220 8.2 6 1/01/2001 13:00:00YCDU 210 7.2 7 1/01/2001 13:30:00YCDU 210 7.2 8 1/01/2001 14:00:00YCDU 200 6.7 9 1/01/2001 14:30:00YCDU 190 7.7 10 1/01/2001 15:00:00YCDU 200 8.2 Browse[1] class(ceduna) [1] data.frame Browse[1] x - as.character(ceduna$LSD) Browse[1] new.time - strptime(x, %d/%m/%Y %H:%M:%S) Browse[1] class(new.time) [1] POSIXt POSIXlt Browse[1] unique(new.time) Error in unique.default(new.time) : unique() applies only to vectors Browse[1] tt - new.time[!duplicated(unclass(new.time))] Error in duplicated.default(unclass(new.time)) : duplicated() applies only to vectors Browse[1] I'm obviously doing something silly with the data classes, but what? Best fishes Sam Sam McClatchie, Biological oceanography South Australian Aquatic Sciences Centre PO Box 120, Henley Beach 5022 Adelaide, South Australia email [EMAIL PROTECTED] Cellular: 0431 304 497 Telephone: (61-8) 8207 5448 FAX: (61-8) 8207 5481 Research home page http://www.members.iinet.net.au/~s.mcclatchie/ /\ ...xX(° °)Xx / \\ (((° (((° ...xX(°O°)Xx __ 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
[R] Conditional Matrices
This seems like a simple problem but I can't figure it out: I have two identical DIMENSION matrices. Both contain only binary values NOT identical between matrices. What I want to do: If in cell (1,1) the value in the first matrix (x) equals 1, then I keep the value in cell (1,1) in the second matrix (y). If in cell (1,1) the value in the first matrix (x) equals 0, then I change the value in cell (1,1) in the second matrix (y)to missing (NA). Repeat for every pair of cells (coordinates of the paired cells always match). Please help. I __ 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
[R] data manipulation help
Hellow everybody, I have a dataframe with 468 individuals (rows) that I captured at least once during 28 visits (columns), it looks like: mortality[1:10,] X18.10.2004 X20.10.2004 X22.10.2004 X24.10.2004 X26.10.2004 X28.10.2004 X30.10.2004 X01.11.2004 X03.11.2004 X07.11.2004 11 0 0 0 1 1 1 0 0 0 21 0 0 0 0 0 0 0 0 0 31 1 1 0 0 0 1 0 0 1 41 0 0 0 0 0 0 0 0 0 51 1 1 1 0 0 1 1 0 0 61 1 1 1 0 0 0 1 0 0 71 0 1 0 1 0 1 1 0 0 81 1 1 0 1 0 1 1 1 1 91 0 0 1 1 0 0 0 1 0 10 1 0 1 0 1 0 0 0 0 0 so I can know how many times every individual was captured, 0= not capture, 1=capture. persistence-apply(mortacap2,1,sum) I also want to know when was the first and the last capture for every individual, if I use: which(mortacap2[1,]==1) X18.10.2004 X26.10.2004 X28.10.2004 X30.10.2004 1 5 6 7 I can estimate manually row by row, but I dont get how to estimate the first and the last capture, to all individuals in the database at the same time. I tried d-numeric(368) for (i in 1:368) {d[i]-which(mortacap2[1:368,]==1} but it didnt work. Any help would be appreciated. Thanks in advance!! Roberto Munguia Steyer Departamento Biologia Evolutiva Instituto de Ecologia, A.C. Xalapa, Veracruz. MEXICO Windows XP R 2.10 [[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
[R] Image from bytes streams
Hello! I'm trying to get an array of bytes from graphic images generated by R. Here, you can see my Java code: -- Process p = Runtime.getRuntime().exec(C:/Arquivos de programas/R/rw1090/bin/Rterm.exe --no-save); DataOutputStream output = new DataOutputStream(new BufferedOutputStream(p.getOutputStream())); DataInputStream input = new DataInputStream(new BufferedInputStream(p.getInputStream())); // output.writeBytes(pie(c(50,30,20))); //Pie graphic output.writeBytes(plot(1,1)); // Plot graphic output.flush(); input.readFully(new byte[200]); // Here I read the image bytes. -- That's the problem: when I use Pie graphic, I got some bytes. However, when I use the Plot graphic, I got the same bytes! So, I suppose that my program does not read the bytes from the generated graphic from R. Is it possible to get the bytes from the generated graphic? How can I get these bytes? Sorry about my english. I'm brazilian! :) -- Márcio de Medeiros Ribeiro Graduando em Ciência da Computação Departamento de Tecnologia da Informação - TCI Universidade Federal de Alagoas - UFAL Maceió - Alagoas - Brasil Projeto ArCo - Arcabouço de Comunidades Contato: +55 82 354-3358/9997-6794 __ 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
[R] merge warning is.na(out$h)
Hi, Does anyone know how to interpret this merge warning and whether it's critical to fix? The merge seemed to work fine, but I am concerned. data3-merge(data1, data2, by=ID, all=TRUE) Warning messages: 1: is.na() applied to non-(list or vector) in: is.na(out$h) Error in cat(list(...), file, sep, fill, labels, append) : argument 2 not yet handled by cat When I remove all=TRUE or just include all.y=TRUE, I don't get the warning; however, I get the warning when I include all.x=TRUE. Thanks, Brent Fulton This email message is for the sole use of the intended recip...{{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