Re: [R] Variable name as string
On 10/17/2010 05:41 AM, Jan private wrote: Also, as a non-professional, I would like to know whether the function is valid for all coefficients of lm(), e.g. coeff.test(lm(N ~ D + H), H, H, 70). I am aware that Verzani gives a different formula for testing the intercept. In a word, no, it isn't. Your SE formula only holds when var is the only predictor. It would be more general to extract the SE from coefficients(summary(lm.result)) (which also avoids having to pass var as an argument). -- Peter Dalgaard Center for Statistics, Copenhagen Business School Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Variable name as string
So here is the next version. Why does the intercept needs lower.tail=TRUE to give the same result as summary() for value=0? # See Verzani, simpleR (pdf), p. 80 coeff.test - function(lm.result, idx, value) { # idx = 1 is the intercept, idx1 the other coefficients # null hypothesis: coeff = value # alternative hypothesis: coeff != value coeff - coefficients(lm.result)[idx] SE - coefficients(summary(lm.result))[idx,Std. Error] n - df.residual(lm.result) t - (coeff - value )/SE if (idx == 1) { 2 * pt(t,n,lower.tail=TRUE) # times two because problem is two-sided } else { 2 * pt(t,n,lower.tail=FALSE) } } __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Vector multiplication
Is there any operator in R, which will multiply each possible combination of the elements of 2 vectors? Suppose I have 2 vectors (1,2) and (1,2,3). If I multiply those 2, I should get:(1,2,3,2,4,6) Thanks, [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Help on choosing the appropriate analysis method
Dear R-help, I'd like ask for your opinion on choosing the right strategy for a particular dataset. We conducted 24-hour electric field measurements on 90 subjects. They are grouped by job (2 categories) and location (3 categories). There are four exposure metrics assigned to each subject. An excerpt from the data: n job locationM OA UE all 0 job1dist_2000.297 0.072 0.171 0.297 1 job1dist_2000.083 0.529 0.066 0.529 2 job1dist_2000.105 0.145 1.072 1.072 3 job1dist_2000.096 0.431 0.099 0.431 4 job1dist_2000.137 0.077 0.092 0.137 5 job1dist_20 NA 0.296 0.107 0.296 6 job1dist_200NA 1.595 0.293 1.595 7 job1dist_20 NA 0.085 0.076 0.085 8 job1dist_20 NA 2.120 0.319 2.120 9 job1dist_20 NA 0.881 NA 0.881 10 job1dist_0 NA 0.221 NA 0.221 80 job2dist_20 0.800 0.342 1.482 1.482 81 job2dist_20 NA 0.521 0.050 0.521 82 job2dist_200NA 0.497 0.502 0.502 83 job2dist_200NA 2.777 NA 2.777 84 job2dist_20 NA 0.127 0.050 0.127 85 job2dist_200NA 2.508 0.423 2.508 86 job2dist_2000.216 0.350 2.782 2.782 87 job2dist_200NA 2.777 1.996 2.777 88 job2dist_2002.348 0.890 2.777 2.777 89 job2dist_200NA 0.488 NA 0.488 I'd like to know whether the differences between the group means are significant. Is a pairwise t-test (for location, and a simple t-test for job) appropriate in this case? data = read.table(data.txt, header=T, nrows=90) attach(data) res1 = pairwise.t.test(all, location, p.adj=bonf) print(res1) res2 = pairwise.t.test(M, location, p.adj=bonf) print(res2) res3 = pairwise.t.test(OA, location, p.adj=bonf) print(res3) res4 = pairwise.t.test(UE, location, p.adj=bonf) print(res4) res1 = t.test(all~job) print(res1) res2 = t.test(M~job) print(res2) res3 = t.test(OA~job) print(res3) res4 = t.test(UE~job) print(res4) I'd also like to compare the four exposure metrics - how to do that? One potential problem is that the distribution is not normal for any of the exposure metrics: it's close to lognormal. (In fact, it's even worse than that: the measuring instrument has a relatively high lower detection limit, and all off-scale low points are marked as the det. limit. In other words, non-detects are censored.) Doesn't this make t-tests useless? Thank you in advance: Péter Juhász __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] yum install - not working for installing R on Linux
I am trying to install R on Linux (Redhat 4). But 'yum' does not seem to work... thanks for your help/hints/suggestions in advance! $ sudo cat /proc/version Linux version 2.6.34.6-54.24.amzn1.i686 (mockbu...@build-31003.build) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-48)) #1 SMP Fri Sep 17 23:13:59 UTC 2010 $ sudo yum install http://cran.cnr.berkeley.edu/bin/linux/redhat/el4/i386/R-core-2.10.0-2.el4.i386.rpm Loaded plugins: fastestmirror, security Loading mirror speeds from cached hostfile Setting up Install Process R-core-2.10.0-2.el4.i386.rpm | 23 MB 00:54 Examining /var/tmp/yum-root-3gwXzS/R-core-2.10.0-2.el4.i386.rpm: R-core-2.10.0-2.el4.i386 Marking /var/tmp/yum-root-3gwXzS/R-core-2.10.0-2.el4.i386.rpm to be installed Resolving Dependencies -- Running transaction check --- Package R-core.i386 0:2.10.0-2.el4 set to be updated -- Processing Dependency: firefox for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: ggv for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libg2c.so.0 for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libreadline.so.4 for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libtcl8.4.so for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libtk8.4.so for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: perl(File::Copy::Recursive) for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: tetex-latex for package: R-core-2.10.0-2.el4.i386 -- Running transaction check --- Package R-core.i386 0:2.10.0-2.el4 set to be updated -- Processing Dependency: firefox for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: ggv for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libg2c.so.0 for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libreadline.so.4 for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libtcl8.4.so for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libtk8.4.so for package: R-core-2.10.0-2.el4.i386 --- Package perl-File-Copy-Recursive.noarch 0:0.38-4.4.amzn1 set to be updated --- Package tetex-latex.i386 0:3.0-33.8.6.amzn1 set to be updated -- Processing Dependency: tetex-dvips = 3.0 for package: tetex-latex-3.0-33.8.6.amzn1.i386 -- Processing Dependency: tetex = 3.0 for package: tetex-latex-3.0-33.8.6.amzn1.i386 -- Processing Dependency: netpbm-progs for package: tetex-latex-3.0-33.8.6.amzn1.i386 -- Running transaction check --- Package R-core.i386 0:2.10.0-2.el4 set to be updated -- Processing Dependency: firefox for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: ggv for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libg2c.so.0 for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libreadline.so.4 for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libtcl8.4.so for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libtk8.4.so for package: R-core-2.10.0-2.el4.i386 --- Package netpbm-progs.i386 0:10.35.58-8.4.amzn1 set to be updated -- Processing Dependency: netpbm = 10.35.58-8.4.amzn1 for package: netpbm-progs-10.35.58-8.4.amzn1.i386 -- Processing Dependency: ghostscript for package: netpbm-progs-10.35.58-8.4.amzn1.i386 -- Processing Dependency: libnetpbm.so.10 for package: netpbm-progs-10.35.58-8.4.amzn1.i386 --- Package tetex.i386 0:3.0-33.8.6.amzn1 set to be updated -- Processing Dependency: tetex-fonts = 3.0 for package: tetex-3.0-33.8.6.amzn1.i386 -- Processing Dependency: dialog for package: tetex-3.0-33.8.6.amzn1.i386 --- Package tetex-dvips.i386 0:3.0-33.8.6.amzn1 set to be updated -- Processing Dependency: psutils for package: tetex-dvips-3.0-33.8.6.amzn1.i386 -- Running transaction check --- Package R-core.i386 0:2.10.0-2.el4 set to be updated -- Processing Dependency: firefox for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: ggv for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libg2c.so.0 for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libreadline.so.4 for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libtcl8.4.so for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libtk8.4.so for package: R-core-2.10.0-2.el4.i386 --- Package dialog.i386 0:1.1-9.20080819.1.2.amzn1 set to be updated --- Package ghostscript.i386 0:8.15.2-9.11.11.amzn1 set to be updated -- Processing Dependency: ghostscript-fonts for package: ghostscript-8.15.2-9.11.11.amzn1.i386 --- Package netpbm.i386 0:10.35.58-8.4.amzn1 set to be updated --- Package psutils.i386 0:1.17-34.2.amzn1 set to be updated --- Package tetex-fonts.i386 0:3.0-33.8.6.amzn1 set to be updated -- Running transaction check --- Package R-core.i386 0:2.10.0-2.el4 set to be updated -- Processing Dependency: firefox for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: ggv for package: R-core-2.10.0-2.el4.i386 --
Re: [R] Vector multiplication
?outer outer(1:2, 1:3, *) [,1] [,2] [,3] [1,]123 [2,]246 On Sun, Oct 17, 2010 at 3:25 AM, Ron Michael ron_michae...@yahoo.com wrote: Is there any operator in R, which will multiply each possible combination of the elements of 2 vectors? Suppose I have 2 vectors (1,2) and (1,2,3). If I multiply those 2, I should get:(1,2,3,2,4,6) Thanks, [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Vector multiplication
Ron Michael wrote: Is there any operator in R, which will multiply each possible combination of the elements of 2 vectors? Suppose I have 2 vectors (1,2) and (1,2,3). If I multiply those 2, I should get:(1,2,3,2,4,6) See ?outer. For example, as.vector(outer(1:3, 1:2)) (but the results are more useful without as.vector()). Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Variable name as string
On 10/17/2010 11:25 AM, Jan private wrote: So here is the next version. Why does the intercept needs lower.tail=TRUE to give the same result as summary() for value=0? It doesn't. Or rather: For all coefficients, lower/upper tail depends on the _sign_ of t, so presumably you have a negative intercept in this particular data set. The more traditional way is 2*pt(-abs(t), n). # See Verzani, simpleR (pdf), p. 80 coeff.test - function(lm.result, idx, value) { # idx = 1 is the intercept, idx1 the other coefficients # null hypothesis: coeff = value # alternative hypothesis: coeff != value coeff - coefficients(lm.result)[idx] SE - coefficients(summary(lm.result))[idx,Std. Error] n - df.residual(lm.result) t - (coeff - value )/SE if (idx == 1) { 2 * pt(t,n,lower.tail=TRUE) # times two because problem is two-sided } else { 2 * pt(t,n,lower.tail=FALSE) } } -- Peter Dalgaard Center for Statistics, Copenhagen Business School Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] lattice xyplot - formatting of multiple Y variables when using subgroups
Hi all, Using xyplot I want to print to Y variables (y1, y2) versus X, conditional on the group. How can I obtain a line (type=l) for one relationship (ie. y1 ~ x) and points (type=p) for the other (y2 ~ x) ? library(lattice) # create some sample data df-data.frame(group=as.factor(c(rep(a,4), rep(b,4))), # grouping variable for conditional plots x=c(1:4,1:4), # x variable y1=rnorm(4,0,1), # y1 y2=rnorm(4,0,1)) # y2 # Basically I want this plot, but then for y1~x points and for y2~x lines. xyplot(y1+y2 ~ x|group, data=df) # This works, but then I get the same plot in the two grouping windows because conditioning is lost in the panel function. xyplot(y1+y2 ~ x|group, data=df, type=l, panel=function(...){panel.xyplot(df$x,df$y1); panel.xyplot(df$x,df$y1, type=l)}) Thanks for your help. Coen [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] yum install - not working for installing R on Linux
On Oct 17, 2010, at 4:00 AM, noclue_ wrote: I am trying to install R on Linux (Redhat 4). But 'yum' does not seem to work... thanks for your help/hints/suggestions in advance! $ sudo cat /proc/version Linux version 2.6.34.6-54.24.amzn1.i686 (mockbu...@build-31003.build) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-48)) #1 SMP Fri Sep 17 23:13:59 UTC 2010 $ sudo yum install http://cran.cnr.berkeley.edu/bin/linux/redhat/el4/i386/R-core-2.10.0-2.el4.i386.rpm Loaded plugins: fastestmirror, security Loading mirror speeds from cached hostfile Setting up Install Process R-core-2.10.0-2.el4.i386.rpm | 23 MB 00:54 Examining /var/tmp/yum-root-3gwXzS/R-core-2.10.0-2.el4.i386.rpm: R-core-2.10.0-2.el4.i386 Marking /var/tmp/yum-root-3gwXzS/R-core-2.10.0-2.el4.i386.rpm to be installed Resolving Dependencies -- Running transaction check --- Package R-core.i386 0:2.10.0-2.el4 set to be updated -- Processing Dependency: firefox for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: ggv for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libg2c.so.0 for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libreadline.so.4 for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libtcl8.4.so for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libtk8.4.so for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: perl(File::Copy::Recursive) for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: tetex-latex for package: R-core-2.10.0-2.el4.i386 -- Running transaction check --- Package R-core.i386 0:2.10.0-2.el4 set to be updated -- Processing Dependency: firefox for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: ggv for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libg2c.so.0 for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libreadline.so.4 for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libtcl8.4.so for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libtk8.4.so for package: R-core-2.10.0-2.el4.i386 --- Package perl-File-Copy-Recursive.noarch 0:0.38-4.4.amzn1 set to be updated --- Package tetex-latex.i386 0:3.0-33.8.6.amzn1 set to be updated -- Processing Dependency: tetex-dvips = 3.0 for package: tetex-latex-3.0-33.8.6.amzn1.i386 -- Processing Dependency: tetex = 3.0 for package: tetex-latex-3.0-33.8.6.amzn1.i386 -- Processing Dependency: netpbm-progs for package: tetex-latex-3.0-33.8.6.amzn1.i386 -- Running transaction check --- Package R-core.i386 0:2.10.0-2.el4 set to be updated -- Processing Dependency: firefox for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: ggv for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libg2c.so.0 for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libreadline.so.4 for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libtcl8.4.so for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libtk8.4.so for package: R-core-2.10.0-2.el4.i386 --- Package netpbm-progs.i386 0:10.35.58-8.4.amzn1 set to be updated -- Processing Dependency: netpbm = 10.35.58-8.4.amzn1 for package: netpbm-progs-10.35.58-8.4.amzn1.i386 -- Processing Dependency: ghostscript for package: netpbm-progs-10.35.58-8.4.amzn1.i386 -- Processing Dependency: libnetpbm.so.10 for package: netpbm-progs-10.35.58-8.4.amzn1.i386 --- Package tetex.i386 0:3.0-33.8.6.amzn1 set to be updated -- Processing Dependency: tetex-fonts = 3.0 for package: tetex-3.0-33.8.6.amzn1.i386 -- Processing Dependency: dialog for package: tetex-3.0-33.8.6.amzn1.i386 --- Package tetex-dvips.i386 0:3.0-33.8.6.amzn1 set to be updated -- Processing Dependency: psutils for package: tetex-dvips-3.0-33.8.6.amzn1.i386 -- Running transaction check --- Package R-core.i386 0:2.10.0-2.el4 set to be updated -- Processing Dependency: firefox for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: ggv for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libg2c.so.0 for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libreadline.so.4 for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libtcl8.4.so for package: R-core-2.10.0-2.el4.i386 -- Processing Dependency: libtk8.4.so for package: R-core-2.10.0-2.el4.i386 --- Package dialog.i386 0:1.1-9.20080819.1.2.amzn1 set to be updated --- Package ghostscript.i386 0:8.15.2-9.11.11.amzn1 set to be updated -- Processing Dependency: ghostscript-fonts for package: ghostscript-8.15.2-9.11.11.amzn1.i386 --- Package netpbm.i386 0:10.35.58-8.4.amzn1 set to be updated --- Package psutils.i386 0:1.17-34.2.amzn1 set to be updated --- Package tetex-fonts.i386 0:3.0-33.8.6.amzn1 set to be updated -- Running transaction check --- Package R-core.i386 0:2.10.0-2.el4 set to be updated --
Re: [R] Problem using BRugs
On 15.10.2010 20:40, Sally Luo wrote: Hi R users, I am trying to call openbugs from R. And I got the following error message: ~ model is syntactically correct expected the collection operator c error pos 8 (error on line 1) Well, something is wrong, but hard to say without the data. I'd suggest to try the whole thing in OpenBUGS at first and see if it runs there. Afterwards go into R where it should work as well. If you still fail to find the error, you may send the stuff to my address privately and I may find some time to take a look. But please try yourself at first. Best wishes, Uwe Ligges variable ww is not defined in model or in data set [1] C:\\DOCUME~1\\maomao\\LOCALS~1\\Temp\\RtmpqJk9R3/inits1.txt Initializing chain 1: model must be compiled before initial values loaded model must be initialized before updating model must be initialized before DIC an be monitored Error in samplesSet(parametersToSave) : model must be initialized before monitors used ~~ I did define variable ww in my data and model (they are listed below). I am not sure if this is due to some errors in my code (please see below) or because openbugs cannot handle the model I am using. In my model, y[i] also depends on all other y[j]s. Could you help me figure out the problem and hopefully get the code to work? Many thanks for your help. --- Maomao ~~ data-list(y,cap2,pol2,cap1,pol1,g,wo,wd,ww,mu,tau) inits-function() {list(beta=beta0, rho_o=rho_o_0, rho_d=rho_d_0, rho_w=rho_w_0)} parameters-c(beta, rho_o, rho_d, rho_w) probit.sim-BRugsFit(data,inits,parameters,modelFile=spatial.openbugs.txt,numChains=1,nIter=2000) # my model model { for (i in 1:676) { y[i] ~ dbern(p[i]) wwy[i]- inprod(ww[i, 1:676] , y[]) woy[i]- inprod(wo[i, 1:676] , y[]) wdy[i]- inprod(wd[i, 1:676] , y[]) probit(p[i])- rho_o * woy[i] + rho_d * wdy[i] + rho_w * wwy[i] + beta[1] + beta[2] * cap2[i] + beta[3] * pol2[i] + beta[4] * cap1[i] + beta[5] * pol1[i] + beta[6] * g[i]+ e[i] } # Priors for (j in 1:6) { beta[1:6] ~ dmnorm(mu[1:6], tau[1:6, 1:6]) } rho_o ~ dunif(-1,1) rho_d ~ dunif(-1,1) rho_w ~ dunif(-1,1) for (i in 1:676) { e[i] ~ dnorm(0, 1) } } [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Class mode text isopen can read can write - too many open connections
I am downloading data files using RCurl and everything works except till some limit is hit and says too many connections open It is a simple download using URL and I am writing the status in a tryCatch block to a log file. showConnections() description class mode text isopen can read can write showConnections(all=T) description class mode text isopen can read can write 0 stdin terminal r text opened yesno 1 stdoutterminal w text opened no yes 2 stderrterminal w text opened no yes I tried closeAllConnections() but of no use. When I try to delete a downloaded file . It says cannot be done because folder is open in R GUI front end Any idea how to resolve this? sessionInfo() R version 2.11.1 (2010-05-31) i386-pc-mingw32 locale: [1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C LC_TIME=English_United Kingdom.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] RCurl_1.4-4.1 bitops_1.0-4.1 zoo_1.6-4 loaded via a namespace (and not attached): [1] grid_2.11.1 lattice_0.19-11 tools_2.11.1 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Class mode text isopen can read can write - too many open connections
Hi, Is it a public URL (i.e., that we can try downloading from too)? Do you get the same error now matter where/what you download or just from that one place? Finally, if you are using Windows XP, are you running R as an administrator (or very sure that the log file or whatever else you are creating is not being written to some place that Windows will try to restrict such as in Programs)? Cheers, Josh On Sun, Oct 17, 2010 at 8:57 AM, Santosh Srinivas santosh.srini...@gmail.com wrote: I am downloading data files using RCurl and everything works except till some limit is hit and says too many connections open It is a simple download using URL and I am writing the status in a tryCatch block to a log file. showConnections() description class mode text isopen can read can write showConnections(all=T) description class mode text isopen can read can write 0 stdin terminal r text opened yes no 1 stdout terminal w text opened no yes 2 stderr terminal w text opened no yes I tried closeAllConnections() but of no use. When I try to delete a downloaded file . It says cannot be done because folder is open in R GUI front end Any idea how to resolve this? sessionInfo() R version 2.11.1 (2010-05-31) i386-pc-mingw32 locale: [1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252 LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C LC_TIME=English_United Kingdom.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] RCurl_1.4-4.1 bitops_1.0-4.1 zoo_1.6-4 loaded via a namespace (and not attached): [1] grid_2.11.1 lattice_0.19-11 tools_2.11.1 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] lattice xyplot - formatting of multiple Y variables when using subgroups
On Sun, Oct 17, 2010 at 10:01 AM, Coen van Hasselt coenvanhass...@gmail.com wrote: Hi all, Using xyplot I want to print to Y variables (y1, y2) versus X, conditional on the group. How can I obtain a line (type=l) for one relationship (ie. y1 ~ x) and points (type=p) for the other (y2 ~ x) ? library(lattice) # create some sample data df-data.frame(group=as.factor(c(rep(a,4), rep(b,4))), # grouping variable for conditional plots x=c(1:4,1:4), # x variable y1=rnorm(4,0,1), # y1 y2=rnorm(4,0,1)) # y2 # Basically I want this plot, but then for y1~x points and for y2~x lines. xyplot(y1+y2 ~ x|group, data=df) # This works, but then I get the same plot in the two grouping windows because conditioning is lost in the panel function. xyplot(y1+y2 ~ x|group, data=df, type=l, panel=function(...){panel.xyplot(df$x,df$y1); panel.xyplot(df$x,df$y1, type=l)}) Try: xyplot(y1+y2 ~ x|group, data=df, type=c(l,p), panel=panel.superpose, distribute.type = TRUE) Thanks for your help. Coen -- Prasenjit __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] scaling on normlized data set
hosnaw hmnawaz at gmail.com writes: I am using R and tried to normalize the data within each sample group using RMA. When I tried to import the all the normalized expression data as a single text file and make a boxplot, it showed discrepancy among the sample groups. I tried to scale them or re-normalize them again, so that it can be used for further analysis. Unfortunately, I did not manage it on using AffyPLM package. Would you please help me out with this problem. I suggest you try your question on the Bioconductor mailing lists; I suspect you'll have a better chance of an answer there. It would also be helpful to provide a reproducible example, and more detail about what 'I did not manage it' means. good luck Ben Bolker __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Cauchy distribution
Hello all, I am a newbie in R so I would appreciate a little help on my topic :-) Firstly, I would like to fit a Cauchy distribution to my data. Any ideas for that? And secondly I would like to see the difference between my data and the fitting and how statistical important is that difference. Thanks in advance -- View this message in context: http://r.789695.n4.nabble.com/Cauchy-distribution-tp2999202p2999202.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Question of Quantile Regression for Longitudinal Data
I've used the function rq.fit.sfn and rq.fit.panel to estimate a quantile regression on a panel data set.Now I would like to compute an statistic to measure the goodness of fit of this model (T-statistics and P-value ). Does someone know how could I do that? For formal inference you are better off using rqss() in the quantreg package, but beware that formal inference for shrinkage estimators is still an active research topic. For goodness of fit statistics like the usual regression R^2, see FAQ() item 4 in the quantreg package. url:www.econ.uiuc.edu/~rogerRoger Koenker emailrkoen...@uiuc.eduDepartment of Economics vox: 217-333-4558University of Illinois fax: 217-244-6678Urbana, IL 61801 -- View this message in context: http://r.789695.n4.nabble.com/Question-of-Quantile-Regression-for-Longitudinal-Data-tp883458p2999206.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Cauchy distribution
evage el_vagena at hotmail.com writes: Firstly, I would like to fit a Cauchy distribution to my data. Any ideas for that? Start with library(MASS) fitdistr(x,cauchy) And secondly I would like to see the difference between my data and the fitting and how statistical important is that difference. General goodness-of-fit tests against an unspecified alternative are a little tricky for continuously distributed data. You could use ?ks.test , but the results will not be quite right because you will have estimated the parameters from the data -- see the last paragraph in the help page under Details. It is easier to evaluate relative goodness-of-fit of the Cauchy vs some other distribution. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R 2.12.0 - malware detect by antivirus software
Dear R-list members, I have just downloaded R 2.12.0 for Windows. When installing, my antivirus software detected some malware during the installation process. I use Windows XP SP3. My antivirus software is Avira Premium Security Suite, product version 10.0.0.542 (19/4/2010), search engine 8.02.04.82 (14/10/2010), virus definition file 7.10.12.231 (17/10/2010). That software said: Malware found. When I clicked in details, I found this information: object: open.exe; Detection: TR/ATRAPS.Gen. Consulting the Avira web site, this is indicated as a Trojan, dated 15 May 2008. I have repeated the installation process twice, always with the same malware detection. When installing, I used the English language, I ticked the Technical Manuals, PDF help pages and docs for Packages grid and Matrix, and I used the default options. Should I proceed with the installation of that version of R? Thank you very much. Paulo Barata -- Paulo Barata Fundacao Oswaldo Cruz - Oswaldo Cruz Foundation Rua Leopoldo Bulhoes 1480 - 8A 21041-210 Rio de Janeiro - RJ Brazil E-mail: pbar...@infolink.com.br Alternative e-mail: paulo.bar...@ensp.fiocruz.br __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] 64-bit R via ec2
Saw your post - please provide more info on using your images. Thanks. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Help in Dirichlet Process density estimation
Hi, friends, I'm using DPdensity package in R to analyze my data (N=1000). The given examples in that package ran pretty good. But when I applied it to my data set, it keeps saying matrix is not pd in chol subroutine. Is there anyone has ever used such package can share some ideas? Thank you very much, The package link is given below: http://cran.r-project.org/web/packages/DPpackage/DPpackage.pdf Jay -- View this message in context: http://r.789695.n4.nabble.com/Help-in-Dirichlet-Process-density-estimation-tp2999100p2999100.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] dpois().......bizarre warning messages
Dear Masters, I have a question to submit consider the following script m-4.95 obs-rpois(36,m) # i generate 36 realization from a poisson(m) hist(obs,freq=F) curve(dpois(x,m),add=T,col=red) #i wish to overlay on the histogram the theorical poisson density function errors are returned saing the x vector doesn't contain integers really bizarre i can't give explanation (R version 2.11.1, no source codes) would u be so kind to suggest me a solution??? thank u FB student of statistics at milano bicocca [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Cauchy distribution
Hello all, I am a newbie in R so I would appreciate a little help on my topic :-) Firstly, I would like to fit a Cauchy distribution to my data. Any ideas for that? And secondly I would like to see the difference between my data and the fitting and how statistical important is that difference. Thanks in advance -- View this message in context: http://r.789695.n4.nabble.com/Cauchy-distribution-tp2999172p2999172.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to install R on Linux via source compilation?
How to install R on Linux via source compilation? Has anybody done it? I could not find step by step instructions online. I would appreciate if you could share your experience. Thanks. -- View this message in context: http://r.789695.n4.nabble.com/How-to-install-R-on-Linux-via-source-compilation-tp2999218p2999218.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] yum install - not working for installing R on Linux
Thanks. Marc! I tried using 'sudo yum install R' - but got the following error -- $ sudo yum install R Loaded plugins: fastestmirror, security Loading mirror speeds from cached hostfile Setting up Install Process No package R available. Error: Nothing to do - will look into epel... -- View this message in context: http://r.789695.n4.nabble.com/yum-install-not-working-for-installing-R-on-Linux-tp2998891p2999219.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R 2.12.0 - malware detect by antivirus software
I checked with two online services which ran more than 40 different virus scanners on the file and only Avira gave a warning. Hence I assume it is a false positive with Avira and you can go on with the installation. @ Duncan as the maintainer for the binary setup installer: It might make sense to report the false positive to Avira in order to protect ourselves from dozens of messages on this list tomorrow. Additionally, you may want to add a note on the CRAN download page. Best wishes, Uwe Ligges On 17.10.2010 20:18, Paulo Barata wrote: Dear R-list members, I have just downloaded R 2.12.0 for Windows. When installing, my antivirus software detected some malware during the installation process. I use Windows XP SP3. My antivirus software is Avira Premium Security Suite, product version 10.0.0.542 (19/4/2010), search engine 8.02.04.82 (14/10/2010), virus definition file 7.10.12.231 (17/10/2010). That software said: Malware found. When I clicked in details, I found this information: object: open.exe; Detection: TR/ATRAPS.Gen. Consulting the Avira web site, this is indicated as a Trojan, dated 15 May 2008. I have repeated the installation process twice, always with the same malware detection. When installing, I used the English language, I ticked the Technical Manuals, PDF help pages and docs for Packages grid and Matrix, and I used the default options. Should I proceed with the installation of that version of R? Thank you very much. Paulo Barata -- Paulo Barata Fundacao Oswaldo Cruz - Oswaldo Cruz Foundation Rua Leopoldo Bulhoes 1480 - 8A 21041-210 Rio de Janeiro - RJ Brazil E-mail: pbar...@infolink.com.br Alternative e-mail: paulo.bar...@ensp.fiocruz.br __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] dpois().......bizarre warning messages
Federico Bonofiglio bonoricus at gmail.com writes: consider the following script m-4.95 obs-rpois(36,m) # i generate 36 realization from a poisson(m) hist(obs,freq=F) curve(dpois(x,m),add=T,col=red) #i wish to overlay on the histogram the theorical poisson density function errors are returned saing the x vector doesn't contain integers really bizarre i can't give explanation (R version 2.11.1, no source codes) I don't know about 'really bizarre'. By default curve() evaluates the expression it is given at 101 equally spaced points between 'from' and 'to' (see ?curve). In general these points won't be integers, so dpois() will quite reasonably complain ... curve(dpois(x,m),add=TRUE,col=red,from=0,to=9, n=10) would be reasonable. However, you will then run into another problem, which is that it's a bit tricky to get histograms to bin discrete data correctly. I would instead suggest something like plot(table(obs)/length(obs)) curve(dpois(x,m),add=TRUE,col=red,from=0,to=9,n=10,type=p) Getting in the habit of using TRUE and FALSE rather than T and F will save you some grief at some point in the future ... __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R 2.12.0 - malware detect by antivirus software
Uwe Ligges wrote: I checked with two online services which ran more than 40 different virus scanners on the file and only Avira gave a warning. Hence I assume it is a false positive with Avira and you can go on with the installation. @ Duncan as the maintainer for the binary setup installer: It might make sense to report the false positive to Avira in order to protect ourselves from dozens of messages on this list tomorrow. Additionally, you may want to add a note on the CRAN download page. I don't think so. False positives from sloppy virus checkers are too common. Paulo may want to help out Avira by pointing out their error, but I won't. Duncan Murdoch Best wishes, Uwe Ligges On 17.10.2010 20:18, Paulo Barata wrote: Dear R-list members, I have just downloaded R 2.12.0 for Windows. When installing, my antivirus software detected some malware during the installation process. I use Windows XP SP3. My antivirus software is Avira Premium Security Suite, product version 10.0.0.542 (19/4/2010), search engine 8.02.04.82 (14/10/2010), virus definition file 7.10.12.231 (17/10/2010). That software said: Malware found. When I clicked in details, I found this information: object: open.exe; Detection: TR/ATRAPS.Gen. Consulting the Avira web site, this is indicated as a Trojan, dated 15 May 2008. I have repeated the installation process twice, always with the same malware detection. When installing, I used the English language, I ticked the Technical Manuals, PDF help pages and docs for Packages grid and Matrix, and I used the default options. Should I proceed with the installation of that version of R? Thank you very much. Paulo Barata -- Paulo Barata Fundacao Oswaldo Cruz - Oswaldo Cruz Foundation Rua Leopoldo Bulhoes 1480 - 8A 21041-210 Rio de Janeiro - RJ Brazil E-mail: pbar...@infolink.com.br Alternative e-mail: paulo.bar...@ensp.fiocruz.br __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R 2.12.0 - malware detect by antivirus software
Dear Dr. Murdoch, My thanks to you and to Dr. Ligges for your replies. I will do my part and will inform Avira about what happened. If possible, I will send then the R 2.12.0 installation file for their examination. As Dr. Ligges said, it is quite possible indeed that a false positive alarm has happened. But please allow me to point out that Avira, as far as I know, is considered to be one of the best pieces of antivirus software in the market. See, for instance, the AV Comparatives web site at www.av-comparatives.org. No antivirus software is 100% perfect, that is, in the real world there is no software with a 0% false positive rate. Or, looking from the other side, every antivirus software is sloppy in some way. Considering that fact, shouldn't the R core team have some definite policy with regard to false positive alarms concerning the R installation file? Is this the first time that this happened? Will this be the last time? Best regards, Paulo Barata On 17/10/2010 17:10, Duncan Murdoch wrote: Uwe Ligges wrote: I checked with two online services which ran more than 40 different virus scanners on the file and only Avira gave a warning. Hence I assume it is a false positive with Avira and you can go on with the installation. @ Duncan as the maintainer for the binary setup installer: It might make sense to report the false positive to Avira in order to protect ourselves from dozens of messages on this list tomorrow. Additionally, you may want to add a note on the CRAN download page. I don't think so. False positives from sloppy virus checkers are too common. Paulo may want to help out Avira by pointing out their error, but I won't. Duncan Murdoch Best wishes, Uwe Ligges On 17.10.2010 20:18, Paulo Barata wrote: Dear R-list members, I have just downloaded R 2.12.0 for Windows. When installing, my antivirus software detected some malware during the installation process. I use Windows XP SP3. My antivirus software is Avira Premium Security Suite, product version 10.0.0.542 (19/4/2010), search engine 8.02.04.82 (14/10/2010), virus definition file 7.10.12.231 (17/10/2010). That software said: Malware found. When I clicked in details, I found this information: object: open.exe; Detection: TR/ATRAPS.Gen. Consulting the Avira web site, this is indicated as a Trojan, dated 15 May 2008. I have repeated the installation process twice, always with the same malware detection. When installing, I used the English language, I ticked the Technical Manuals, PDF help pages and docs for Packages grid and Matrix, and I used the default options. Should I proceed with the installation of that version of R? Thank you very much. Paulo Barata -- Paulo Barata Fundacao Oswaldo Cruz - Oswaldo Cruz Foundation Rua Leopoldo Bulhoes 1480 - 8A 21041-210 Rio de Janeiro - RJ Brazil E-mail: pbar...@infolink.com.br Alternative e-mail: paulo.bar...@ensp.fiocruz.br __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R 2.12.0 - malware detect by antivirus software
Paulo Barata wrote: Dear Dr. Murdoch, My thanks to you and to Dr. Ligges for your replies. I will do my part and will inform Avira about what happened. If possible, I will send then the R 2.12.0 installation file for their examination. As Dr. Ligges said, it is quite possible indeed that a false positive alarm has happened. But please allow me to point out that Avira, as far as I know, is considered to be one of the best pieces of antivirus software in the market. See, for instance, the AV Comparatives web site at www.av-comparatives.org. No antivirus software is 100% perfect, that is, in the real world there is no software with a 0% false positive rate. Or, looking from the other side, every antivirus software is sloppy in some way. Considering that fact, shouldn't the R core team have some definite policy with regard to false positive alarms concerning the R installation file? Is this the first time that this happened? Will this be the last time? This is by no means the first time, and I doubt it will be the last time. I think our policy is listed in the banner that prints when you start R: R is free software and comes with ABSOLUTELY NO WARRANTY. If you want a stronger warranty, you could try looking at commercial software (or commercial builds of R), but I doubt you'll get one that's worth very much. Duncan Murdoch Best regards, Paulo Barata On 17/10/2010 17:10, Duncan Murdoch wrote: Uwe Ligges wrote: I checked with two online services which ran more than 40 different virus scanners on the file and only Avira gave a warning. Hence I assume it is a false positive with Avira and you can go on with the installation. @ Duncan as the maintainer for the binary setup installer: It might make sense to report the false positive to Avira in order to protect ourselves from dozens of messages on this list tomorrow. Additionally, you may want to add a note on the CRAN download page. I don't think so. False positives from sloppy virus checkers are too common. Paulo may want to help out Avira by pointing out their error, but I won't. Duncan Murdoch Best wishes, Uwe Ligges On 17.10.2010 20:18, Paulo Barata wrote: Dear R-list members, I have just downloaded R 2.12.0 for Windows. When installing, my antivirus software detected some malware during the installation process. I use Windows XP SP3. My antivirus software is Avira Premium Security Suite, product version 10.0.0.542 (19/4/2010), search engine 8.02.04.82 (14/10/2010), virus definition file 7.10.12.231 (17/10/2010). That software said: Malware found. When I clicked in details, I found this information: object: open.exe; Detection: TR/ATRAPS.Gen. Consulting the Avira web site, this is indicated as a Trojan, dated 15 May 2008. I have repeated the installation process twice, always with the same malware detection. When installing, I used the English language, I ticked the Technical Manuals, PDF help pages and docs for Packages grid and Matrix, and I used the default options. Should I proceed with the installation of that version of R? Thank you very much. Paulo Barata -- Paulo Barata Fundacao Oswaldo Cruz - Oswaldo Cruz Foundation Rua Leopoldo Bulhoes 1480 - 8A 21041-210 Rio de Janeiro - RJ Brazil E-mail: pbar...@infolink.com.br Alternative e-mail: paulo.bar...@ensp.fiocruz.br __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to convert string to object?
Hi, Please try ?parse and ?eval. Here is an example: text - 3*6 parse(text=text) eval(parse(text=text)) - A R learner. -- View this message in context: http://r.789695.n4.nabble.com/how-to-convert-string-to-object-tp2999281p2999336.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] unbalanced repeated measurements Anova with mixed effects
Dear R-list members, I've been struggling with the proper setup for analysing my data. I've performed a route choice experiment, in which participants had to make a choice at each junction for the next road. During the experiment they received traffic information, but also encountered two different accidents. They also made trips without accidents. What I'm interested in is to see if the traffic information influenced their route choice, regarding their total travel time, the delay and the number of junctions they passed. These are thus three dependent variables. The independent variables are the type of traffic information and the accident situation, and personal characteristics such as age, gender and amount of kilometers driven each year. In order to simplify this, I've seperated each accident in a data frame (because the trips without accidents, don't have all the different types of traffic information). As far as my limited statical knowledge goes, this implies I have a mixed repeated measurements experiment. To be able to answer the hypotheses that traffic information influences traveltime, delay and number of junctions, I can do an Anova. However, the datasets are also unbalanced, because not all trips lead to the right destination. I've found that the car package presents the proper tools to do this, but I'm not sure if the following model will give the results I want to have. Can anyone help me with that? I've put the data in a wide format, where traveltime.1 stands for the measured traveltime with traffic information 1, etc. event1.mod.car-lm(cbind(traveltime.1,traveltime.2,traveltime.3)~age*gender*kmyear, data=event1.wide) event1.aov.car-Anova(event1.mod.car, idata=idata, idesign=~guidanceID) Can I also use the aov function? But because of the unbalanced data, this will probably not provide the right results. Is that right? event1.aov-aov(traveltime~guidanceID*gender*age*kmyear + Error(userID/guidanceID), data=event1) Thanks in advance! Thijs Muizelaar PhD student University of Twente __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] unbalanced repeated measurements Anova with mixed effects
Hello Thijs, I think that as you wrote, the aov wouldn't work for you here (due to the unbalanced design). I'd recommend you to have a look at the {ezhttp://cran.r-project.org/web/packages/ez/index.html } package, which offers a nice wrapping of the car Anova functions. I've listed a bunch of tutorials on the topic here: http://www.r-statistics.com/2010/04/repeated-measures-anova-with-r-tutorials/ That might prove useful for you. Best, Tal http://www.r-statistics.com/2010/04/repeated-measures-anova-with-r-tutorials/ Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- On Sun, Oct 17, 2010 at 10:03 PM, Thijs Muizelaar thijs.muizel...@xs4all.nl wrote: Dear R-list members, I've been struggling with the proper setup for analysing my data. I've performed a route choice experiment, in which participants had to make a choice at each junction for the next road. During the experiment they received traffic information, but also encountered two different accidents. They also made trips without accidents. What I'm interested in is to see if the traffic information influenced their route choice, regarding their total travel time, the delay and the number of junctions they passed. These are thus three dependent variables. The independent variables are the type of traffic information and the accident situation, and personal characteristics such as age, gender and amount of kilometers driven each year. In order to simplify this, I've seperated each accident in a data frame (because the trips without accidents, don't have all the different types of traffic information). As far as my limited statical knowledge goes, this implies I have a mixed repeated measurements experiment. To be able to answer the hypotheses that traffic information influences traveltime, delay and number of junctions, I can do an Anova. However, the datasets are also unbalanced, because not all trips lead to the right destination. I've found that the car package presents the proper tools to do this, but I'm not sure if the following model will give the results I want to have. Can anyone help me with that? I've put the data in a wide format, where traveltime.1 stands for the measured traveltime with traffic information 1, etc. event1.mod.car-lm(cbind(traveltime.1,traveltime.2,traveltime.3)~age*gender*kmyear, data=event1.wide) event1.aov.car-Anova(event1.mod.car, idata=idata, idesign=~guidanceID) Can I also use the aov function? But because of the unbalanced data, this will probably not provide the right results. Is that right? event1.aov-aov(traveltime~guidanceID*gender*age*kmyear + Error(userID/guidanceID), data=event1) Thanks in advance! Thijs Muizelaar PhD student University of Twente __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R 2.12 How many downloads
A general question- and excuse me if you find it irrelevant Are you tracking how many people finally download a specific R version by counting the number of downloads through log/ analytics software like GA etc? If so- can we see some numbers Ajay Websites- http://decisionstats.com http://dudeofdata.com Linkedin- www.linkedin.com/in/ajayohri https://emailoracle.com/opt_out/?image_uuid=5c3f9e5a-c6f3-a2fe-2a68-409a37161c77 On Sun, Oct 17, 2010 at 11:48 PM, Paulo Barata pbar...@infolink.com.brwrote: Dear R-list members, I have just downloaded R 2.12.0 for Windows. When installing, my antivirus software detected some malware during the installation process. I use Windows XP SP3. My antivirus software is Avira Premium Security Suite, product version 10.0.0.542 (19/4/2010), search engine 8.02.04.82 (14/10/2010), virus definition file 7.10.12.231 (17/10/2010). That software said: Malware found. When I clicked in details, I found this information: object: open.exe; Detection: TR/ATRAPS.Gen. Consulting the Avira web site, this is indicated as a Trojan, dated 15 May 2008. I have repeated the installation process twice, always with the same malware detection. When installing, I used the English language, I ticked the Technical Manuals, PDF help pages and docs for Packages grid and Matrix, and I used the default options. Should I proceed with the installation of that version of R? Thank you very much. Paulo Barata -- Paulo Barata Fundacao Oswaldo Cruz - Oswaldo Cruz Foundation Rua Leopoldo Bulhoes 1480 - 8A 21041-210 Rio de Janeiro - RJ Brazil E-mail: pbar...@infolink.com.br Alternative e-mail: paulo.bar...@ensp.fiocruz.br __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to convert string to object?
temp = ~aparch( temp1 = paste(temp,1, sep = ) temp2 = paste(temp1,1, sep = ,) temp3 = paste(temp2, ),sep = ) temp 3 is a character but I want to convert to formula object. How do I do this? -- View this message in context: http://r.789695.n4.nabble.com/how-to-convert-string-to-object-tp2999281p2999281.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to convert string to object?
how do I convert it to a language object? -- View this message in context: http://r.789695.n4.nabble.com/how-to-convert-string-to-object-tp2999281p2999299.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to convert string to object?
Have you tried this: temp = ~aparch( temp1 = paste(temp,1, sep = ) temp2 = paste(temp1,1, sep = ,) temp3 = paste(temp2, ),sep = ) temp3 [1] ~aparch(1,1) as.formula(temp3) ~aparch(1, 1) x - as.formula(temp3) str(x) Class 'formula' length 2 ~aparch(1, 1) ..- attr(*, .Environment)=environment: R_GlobalEnv On Sun, Oct 17, 2010 at 2:53 PM, lord12 trexi...@yahoo.com wrote: temp = ~aparch( temp1 = paste(temp,1, sep = ) temp2 = paste(temp1,1, sep = ,) temp3 = paste(temp2, ),sep = ) temp 3 is a character but I want to convert to formula object. How do I do this? -- View this message in context: http://r.789695.n4.nabble.com/how-to-convert-string-to-object-tp2999281p2999281.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to convert string to object?
Hi, Wu Gong and Jim Holtman gave you options that should work, but I suspect there is a way to circumvent the entire issue if we knew more about your context and goals. Of course pasting together calls and then evaluating them is always an option, but there may be a simpler way. This is all summarized nicely: On Sun, Oct 17, 2010 at 1:31 PM, jim holtman jholt...@gmail.com wrote: [snip] What is the problem that you are trying to solve? Cheers, Josh On Sun, Oct 17, 2010 at 11:53 AM, lord12 trexi...@yahoo.com wrote: temp = ~aparch( temp1 = paste(temp,1, sep = ) temp2 = paste(temp1,1, sep = ,) temp3 = paste(temp2, ),sep = ) temp 3 is a character but I want to convert to formula object. How do I do this? -- View this message in context: http://r.789695.n4.nabble.com/how-to-convert-string-to-object-tp2999281p2999281.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to fix error in the package 'rgenoud'
I could solve this problem by setting the boundary options as follows. par1Bnd-c(0.001,0.999) par2Bnd-c(-10,10) DomainMat-matrix(c(par1Bnd,par2Bnd), nrow = 2, ncol=2, byrow=TRUE) result-genoud(Qmin, nvars=2, starting.values=c(0.5,0), Domains=DomainMat, control=list(ndeps=c(1e-7,1e-2)), boundary.enforcement=2) To understand how to set up each option, you can refer to the links: http://sekhon.berkeley.edu/rgenoud/genoud.html http://sekhon.berkeley.edu/rgenoud/ In the above setting, Domains decides the boundary, and starting.values indicates the initial values of parameters. control is the list of control parameters in optim (For details, refer to http://sekhon.berkeley.edu/stats/html/optim.html). boundary.enforcement prevents the algorithm from going away from the boundary. On 13 October 2010 15:01, Wonsang You [via R] ml-node+2993619-1186574920-137...@n4.nabble.comml-node%2b2993619-1186574920-137...@n4.nabble.com wrote: I have to make correction in my error message which I introduced in my original message. Sorry for my mistake. Finally, I had the following error message after running the function 'genoud'. Error in optim(foo.vals, fn = fn1, gr = gr1, method = optim.method, control = control) : non-finite finite-difference value [1] When I execute 'traceback()' to trace where the error occured, I got the following results. Unfortunately, I could not figure out what was the problem from the above information. 6: optim(foo.vals, fn = fn1, gr = gr1, method = optim.method, control = control) 5: function (foo.vals) { ret - optim(foo.vals, fn = fn1, gr = gr1, method = optim.method, control = control) return(c(ret$value, ret$par)) }(c(0.220878697173384, -13.3643173824871)) 4: .Call(rgenoud, as.function(fn1), new.env(), as.integer(nvars), as.integer(pop.size), as.integer(max.generations), as.integer(wait.generations), as.integer(nStartingValues), as.real(starting.values), as.vector(P), as.matrix(Domains), as.integer(max), as.integer(gradient.check), as.integer(boundary.enforcement), as.double(solution.tolerance), as.integer(BFGS), as.integer(data.type.int), as.integer(provide.seeds), as.integer(unif.seed), as.integer(int.seed), as.integer(print.level), as.integer(share.type), as.integer(instance.number), as.integer(MemoryMatrix), as.integer(debug), as.character(output.path), as.integer(output.type), as.character(project.path), as.integer(hard.generation.limit), as.function(genoud.optim.wrapper101), as.integer(lexical), as.function(fnLexicalSort), as.function(fnMemoryMatrixEvaluate), as.integer(UserGradient), as.function(gr1func), as.real(P9mix), as.integer(BFGSburnin), as.integer(transform), PACKAGE = rgenoud) 3: genoud(Qmin, nvars = 2, starting.values = InitVal, max.generations = 10, wait.generations = 3, n = n, yper = yper, pertype = pertype) at wFGN.R#75 Wonsang You Leibniz Institute for Neurobiology -- View message @ http://r.789695.n4.nabble.com/How-to-fix-error-in-the-package-rgenoud-tp2993489p2993619.html To unsubscribe from How to fix error in the package 'rgenoud', click herehttp://r.789695.n4.nabble.com/template/TplServlet.jtp?tpl=unsubscribe_by_codenode=2993489code=eW91QGlmbi1tYWdkZWJ1cmcuZGV8Mjk5MzQ4OXwxODQ5NDg1ODM2. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] delete data row
I had been thinking of: x - c(1, (2^(0.5))^2 , 3, 5, (2^(0.5))^2 , 3, 1) y - 2 x[-which(zapsmall(x-y) == 0)] [1] 1 3 5 3 1 Using which() to convert logicals into integer subscripts is almost always unnecessary and often wrong. In this case it fails when no x is close to y, because integer(0) is the same thing as -integer(0): x[-which(zapsmall(x-10) == 0)] numeric(0) The whichless version, using logical subscripts, works (in this case we want all of x): x[zapsmall(x-10)!=0] [1] 1 2 3 5 2 3 1 When using logicals as subscripts, read the [ as such that. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] rgdal package (Matteo Toro)
Hi everybody, I'm trying to install the rgdal package in R, but it seems not possible... i'm typing install.packages(rgdal) Warning in install.packages(rgdal) : argument 'lib' is missing: using '/home/toro/R/i486-pc-linux-gnu-library/2. 9' --- Please select a CRAN mirror for use in this session --- Loading Tcl/Tk interface ... done Warning message: In getDependencies(pkgs, dependencies, available, lib) : package ‘rgdal’ is not available I also tried to download the package from http://sourceforge. net/projects/rgdal/files/ , and tried $ R CMD INSTALL /home/toro/Downloads/rgdal_0.3-5.tar.gz * Installing to library ‘/home/toro/R/i486-pc-linux-gnu-library/2.9’ * Installing *source* package ‘rgdal’ ... configure: creating ./config.status config.status: creating src/Makevars ** libs g++ -I/usr/share/R/include -I/usr/include/gdal -g -DRGDALDEBUG -fpic -g - O2 -c gdal-bindings.cpp -o gdal-bindings.o gdal-bindings.cpp: In function ‘char* asString(SEXPREC*, int)’: gdal-bindings.cpp:28: error: invalid conversion from ‘const char*’ to ‘char*’ make: *** [gdal-bindings.o] Error 1 ERROR: compilation failed for package ‘rgdal’ * Removing ‘/home/toro/R/i486-pc-linux-gnu-library/2.9/rgdal’ and this happens also for other versions of gdal I have downloaded. The biggest problem is that also other packages like spgrass6, spGDAL and spmaptools are dependent from gdalso i cannot go on Can I ask you to help me , please?? Thank you Matteo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] delete data row
On Oct 17, 2010, at 3:56 PM, William Dunlap wrote: I had been thinking of: x - c(1, (2^(0.5))^2 , 3, 5, (2^(0.5))^2 , 3, 1) y - 2 x[-which(zapsmall(x-y) == 0)] [1] 1 3 5 3 1 Using which() to convert logicals into integer subscripts is almost always unnecessary and often wrong. At one time I believed that too. However, in the situation where the test produces NA rather than a numeric value when one is indexing in the first argument. I have had the unpleasant experience of pages if useless and frustrating to understand output because of this feature. I learned to either use which() in the first argument to [ or to use subset to avoid inadvertent returns from logical indexing. x - 1:10 y - log(x-5) Warning message: In log(x - 5) : NaNs produced x[y-Inf] [1] NA NA NA NA 6 7 8 9 10 x[which(y-Inf)] [1] 6 7 8 9 10 If that test were used in a dataframe indexing, the entire line might come back as a result. In this case it fails when no x is close to y, because integer(0) is the same thing as -integer(0): x[-which(zapsmall(x-10) == 0)] numeric(0) The whichless version, using logical subscripts, works (in this case we want all of x): x[zapsmall(x-10)!=0] [1] 1 2 3 5 2 3 1 Maybe the rule should be don't use the -which construction: x - c(1, (2^(0.5))^2 , 3, 5, (2^(0.5))^2 , 3, 1) y - 2 x[which(zapsmall(x-10) != 0)] [1] 1 2 3 5 2 3 1 -- David. When using logicals as subscripts, read the [ as such that. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] trouble installing R-patched (R-2.12.0) when TMPDIR is specified
I noticed that if I specify the location of TMPDIR in .bashrc as follows on a Linux 64 bit system: export TMPDIR=/store/home/ayee/.tmp I get the following error message when installing R make[3]: Entering directory `/home/ayee/R-patched/src/library/base' building package 'base' make[4]: Entering directory `/home/ayee/R-patched/src/library/base' /bin/sh: line 8: /store/home/ayee/.tmp/R24402: No such file or directory mv: cannot stat `/store/home/ayee/.tmp/R24402': No such file or directory make[4]: *** [mkR] Error 1 make[4]: Leaving directory `/home/ayee/R-patched/src/library/base' make[3]: *** [all] Error 2 make[3]: Leaving directory `/home/ayee/R-patched/src/library/base' make[2]: *** [R] Error 1 make[2]: Leaving directory `/home/ayee/R-patched/src/library' make[1]: *** [R] Error 1 make[1]: Leaving directory `/home/ayee/R-patched/src' make: *** [R] Error 1 [rambo:~/R-patched]$ However, when I don't specify TMPDIR, it installs fine. Any suggestions/comments? Thanks, Andrew [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Getting tripped up on NAs in trying to create new variable
Hello R help: I have the following data: a - c(NA, 2, 2, 3, 2, NA) b - c(NA, NA, 3, NA, 1, 3) df - data.frame(a, b) df a b 1 NA NA 2 2 NA 3 2 3 4 3 NA 5 2 1 6 NA 3 I want to create variable c such that if there is a 3 in either variable a or variable b, variable c is 1(rows 3, 4 6 below). If 3 not in a or b and a value appears in a or b, then c is 0(row 2 below). If NA is present in both variables, c is NA (row 1 below). a b c 1 NA NA NA 2 2 NA 0 3 2 3 1 4 3 NA 1 5 2 1 0 6 NA 3 1 I have tried various ifelse attempts but have not hit upon the correct solution yet. For example, the following syntax throws NA for row two instead of the hope for 0. test - ifelse(is.na(df$a) is.na(df$b), NA, ifelse((!is.na(df$a) | !is.na(df$b)) ((df$a ==3 | df$b == 3)), 1, 0)) test NA NA 1 1 0 1 Any help much appreciated. -- Gregory L. Blevins Office 952 944-5743 Cell 612 251 0232 gregb...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] delete data row
I used the -which() construct initially to try to show deleting cases. I believe it hung around longer than it should have. That said, I have also had David's experience with NAs. What about a vectorized version of identical(TRUE, x)? This avoids the which() problem Bill pointed out, and the NA issue David mentioned. Does it introduce new problems? x - 1:10 y - log(x-5) VisTRUE - Vectorize(isTRUE) x[VisTRUE(y -Inf)] Josh On Sun, Oct 17, 2010 at 4:38 PM, David Winsemius dwinsem...@comcast.net wrote: On Oct 17, 2010, at 3:56 PM, William Dunlap wrote: I had been thinking of: x - c(1, (2^(0.5))^2 , 3, 5, (2^(0.5))^2 , 3, 1) y - 2 x[-which(zapsmall(x-y) == 0)] [1] 1 3 5 3 1 Using which() to convert logicals into integer subscripts is almost always unnecessary and often wrong. At one time I believed that too. However, in the situation where the test produces NA rather than a numeric value when one is indexing in the first argument. I have had the unpleasant experience of pages if useless and frustrating to understand output because of this feature. I learned to either use which() in the first argument to [ or to use subset to avoid inadvertent returns from logical indexing. x - 1:10 y - log(x-5) Warning message: In log(x - 5) : NaNs produced x[y-Inf] [1] NA NA NA NA 6 7 8 9 10 x[which(y-Inf)] [1] 6 7 8 9 10 If that test were used in a dataframe indexing, the entire line might come back as a result. In this case it fails when no x is close to y, because integer(0) is the same thing as -integer(0): x[-which(zapsmall(x-10) == 0)] numeric(0) The whichless version, using logical subscripts, works (in this case we want all of x): x[zapsmall(x-10)!=0] [1] 1 2 3 5 2 3 1 Maybe the rule should be don't use the -which construction: x - c(1, (2^(0.5))^2 , 3, 5, (2^(0.5))^2 , 3, 1) y - 2 x[which(zapsmall(x-10) != 0)] [1] 1 2 3 5 2 3 1 -- David. When using logicals as subscripts, read the [ as such that. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Getting tripped up on NAs in trying to create new variable
Tena koe Greg df$c - 0 df[apply(df[,-3], 1, function(x) any(x %in% 3)), 3] - 1 df[apply(df[,-3], 1, function(x) all(is.na(x))), 3] - NA df a b c 1 NA NA NA 2 2 NA 0 3 2 3 1 4 3 NA 1 5 2 1 0 6 NA 3 1 HTH Peter Alspach -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Greg Blevins Sent: Monday, 18 October 2010 2:04 p.m. To: r-help@r-project.org Subject: [R] Getting tripped up on NAs in trying to create new variable Hello R help: I have the following data: a - c(NA, 2, 2, 3, 2, NA) b - c(NA, NA, 3, NA, 1, 3) df - data.frame(a, b) df a b 1 NA NA 2 2 NA 3 2 3 4 3 NA 5 2 1 6 NA 3 I want to create variable c such that if there is a 3 in either variable a or variable b, variable c is 1(rows 3, 4 6 below). If 3 not in a or b and a value appears in a or b, then c is 0(row 2 below). If NA is present in both variables, c is NA (row 1 below). a b c 1 NA NA NA 2 2 NA 0 3 2 3 1 4 3 NA 1 5 2 1 0 6 NA 3 1 I have tried various ifelse attempts but have not hit upon the correct solution yet. For example, the following syntax throws NA for row two instead of the hope for 0. test - ifelse(is.na(df$a) is.na(df$b), NA, ifelse((!is.na(df$a) | !is.na(df$b)) ((df$a ==3 | df$b == 3)), 1, 0)) test NA NA 1 1 0 1 Any help much appreciated. -- Gregory L. Blevins Office 952 944-5743 Cell 612 251 0232 gregb...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. The contents of this e-mail are confidential and may be subject to legal privilege. If you are not the intended recipient you must not use, disseminate, distribute or reproduce all or any part of this e-mail or attachments. If you have received this e-mail in error, please notify the sender and delete all material pertaining to this e-mail. Any opinion or views expressed in this e-mail are those of the individual sender and may not represent those of The New Zealand Institute for Plant and Food Research Limited. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Getting tripped up on NAs in trying to create new variable
On Sun, Oct 17, 2010 at 9:03 PM, Greg Blevins gregb...@gmail.com wrote: Hello R help: I have the following data: a - c(NA, 2, 2, 3, 2, NA) b - c(NA, NA, 3, NA, 1, 3) df - data.frame(a, b) df a b 1 NA NA 2 2 NA 3 2 3 4 3 NA 5 2 1 6 NA 3 I want to create variable c such that if there is a 3 in either variable a or variable b, variable c is 1(rows 3, 4 6 below). If 3 not in a or b and a value appears in a or b, then c is 0(row 2 below). If NA is present in both variables, c is NA (row 1 below). a b c 1 NA NA NA 2 2 NA 0 3 2 3 1 4 3 NA 1 5 2 1 0 6 NA 3 1 I have tried various ifelse attempts but have not hit upon the correct solution yet. For example, the following syntax throws NA for row two instead of the hope for 0. Try this: transform(df, c = ifelse(is.na(a) is.na(b), NA, a %in% 3 | b %in% 3) + 0) -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Basic structure operations doubt
I'm doing these manipulations on the data frame and wondering why does R have to remember historical data on my operation and not just keep the needed info. Probably a basic fundamentals of the way R handles data .. Pls point me to the manual if possible .. I have this Index data: head(NIFTY_INDX) Constituents.list.of.S.P.CNX.Nifty X X.1 X.2 X.3 1 2 Company Name IndustrySymbol SeriesISIN Code 3 4 ACC Ltd. CEMENT AND CEMENT PRODUCTS ACC EQ INE012A01025 5Ambuja Cements Ltd. CEMENT AND CEMENT PRODUCTS AMBUJACEM EQ INE079A01024 6 Axis Bank Ltd. BANKS AXISBANK EQ INE238A01026 I Import the section that is relevant to me: Indx_Constituents - NIFTY_INDX[4:NROW(NIFTY_INDX),] head(Indx_Constituents) Constituents.list.of.S.P.CNX.Nifty X X.1 X.2 X.3 4 ACC Ltd. CEMENT AND CEMENT PRODUCTS ACC EQ INE012A01025 5Ambuja Cements Ltd. CEMENT AND CEMENT PRODUCTS AMBUJACEM EQ INE079A01024 6 Axis Bank Ltd. BANKS AXISBANK EQ INE238A01026 7Bajaj Auto Ltd. AUTOMOBILES - 2 AND 3 WHEELERS BAJAJ-AUTO EQ INE917I01010 8 Bharat Heavy Electricals Ltd. ELECTRICAL EQUIPMENT BHEL EQ INE257A01018 9 Bharat Petroleum Corporation Ltd. REFINERIES BPCL EQ INE029A01011 colNames - NIFTY_INDX[2,] colNames Constituents.list.of.S.P.CNX.NiftyXX.1X.2 X.3 2 Company Name Industry Symbol Series ISIN Code I want to assign the info from colNames[1,] to Indx_Constituents I am unable to do this directly ... I can probably pull out the values and do it but there should be an easier way Now when I do this: colNames[1,1] [1] Company Name 52 Levels: ACC Ltd. Ambuja Cements Ltd. Axis Bank Ltd. Bajaj Auto Ltd. Bharat Heavy Electricals Ltd. Bharat Petroleum Corporation Ltd. Bharti Airtel Ltd. Cairn India Ltd. Cipla Ltd. Company Name ... Wipro Ltd. Why does R have to remember the 52 levels?? Why can't it just have the relevant data stored What are the alternatives so that I can simply have my needed data in my data frames? Thanks for your explanation. -- Thanks R-Helpers. Yes, this is a silly question and it will not be repeated! :-) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Class mode text isopen can read can write - too many open connections
I'm basically doing using code: NOTE THIS IS A RECURSIVE DOWNLOAD ... SO CHANGE TO A DIRECTORY THAT YOU WANT TO JUNK ... After the download ... try deleting the data without closing R and it says the file is currently held open by R ... Not sure how I can close that connection .. Please let me know any release operations that I ened to add in the code too. library(zoo) library(RCurl) x - seq(as.Date(01-Jan-2010,format=%d-%b-%Y), Sys.Date(), by=1) #to generate series of dates #sDate - x[6] cmDownFun - function (sDate) { sMonth - casefold( as.character(sDate,format=%b),upper=T) #Get the month sYear - casefold( as.character(sDate,format=%Y),upper=T) #Get the month sDate1 - casefold( as.character(sDate, format=%d%b%Y), upper =T) #Get the date sURL - paste(http://www.nseindia.com/content/historical/EQUITIES/,sYear,/,sMonth,/cm,sDate1,bhav.csv.zip;, sep=) tryCatch( { download.file(sURL,paste(CM,sDate1,.zip,sep=)) #download the file print (paste(Successfully downloaded:, paste(CM,sDate1,.zip,sep=))) write(paste(Successfully downloaded:, paste(CM,sDate1,.zip,sep=)),file = Success-Log.txt,append=TRUE,sep=\n) closeAllConnections() }, warning = function (ex){ print(paste(Failed to download:, paste(CM,sDate1,.zip,sep=)),file = Failure-Log.txt,append=TRUE,sep=\n) write(paste(Failed to download:, paste(CM,sDate1,.zip,sep=)),file = Failure-Log.txt,append=TRUE,sep=\n) closeAllConnections() }) } #lapply(x, function(x) try(cmDownFun(x),silent = TRUE)) lapply(x, cmDownFun) -Original Message- From: Joshua Wiley [mailto:jwiley.ps...@gmail.com] Sent: 17 October 2010 21:39 To: Santosh Srinivas Cc: r-help@r-project.org Subject: Re: [R] Class mode text isopen can read can write - too many open connections Hi, Is it a public URL (i.e., that we can try downloading from too)? Do you get the same error now matter where/what you download or just from that one place? Finally, if you are using Windows XP, are you running R as an administrator (or very sure that the log file or whatever else you are creating is not being written to some place that Windows will try to restrict such as in Programs)? Cheers, Josh On Sun, Oct 17, 2010 at 8:57 AM, Santosh Srinivas santosh.srini...@gmail.com wrote: I am downloading data files using RCurl and everything works except till some limit is hit and says too many connections open It is a simple download using URL and I am writing the status in a tryCatch block to a log file. showConnections() � � description class mode text isopen can read can write showConnections(all=T) �description class � � �mode text � isopen � can read can write 0 stdin � � terminal r �text opened yes � �no 1 stdout � �terminal w �text opened no � � yes 2 stderr � �terminal w �text opened no � � yes I tried closeAllConnections() but of no use. When I try to delete a downloaded file . It says cannot be done because folder is open in R GUI front end Any idea how to resolve this? sessionInfo() R version 2.11.1 (2010-05-31) i386-pc-mingw32 locale: [1] LC_COLLATE=English_United Kingdom.1252 �LC_CTYPE=English_United Kingdom.1252 � �LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C LC_TIME=English_United Kingdom.1252 attached base packages: [1] stats � � graphics �grDevices utils � � datasets �methods � base other attached packages: [1] RCurl_1.4-4.1 �bitops_1.0-4.1 zoo_1.6-4 loaded via a namespace (and not attached): [1] grid_2.11.1 � � lattice_0.19-11 tools_2.11.1 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Basic structure operations doubt
Hi, The easiest way to get rid of the empty levels is with droplevels(). See ?droplevels for details. It actually has a method for data frames even. So you could just do something like: Indx_Constituents - droplevels(Indx_Constituents) or whatever your data frame was called and it will drop any unused levels for you. Cheers, Josh On Sun, Oct 17, 2010 at 7:06 PM, Santosh Srinivas santosh.srini...@gmail.com wrote: I'm doing these manipulations on the data frame and wondering why does R have to remember historical data on my operation and not just keep the needed info. Probably a basic fundamentals of the way R handles data .. Pls point me to the manual if possible .. I have this Index data: head(NIFTY_INDX) Constituents.list.of.S.P.CNX.Nifty X X.1 X.2 X.3 1 2 Company Name Industry Symbol Series ISIN Code 3 4 ACC Ltd. CEMENT AND CEMENT PRODUCTS ACC EQ INE012A01025 5 Ambuja Cements Ltd. CEMENT AND CEMENT PRODUCTS AMBUJACEM EQ INE079A01024 6 Axis Bank Ltd. BANKS AXISBANK EQ INE238A01026 I Import the section that is relevant to me: Indx_Constituents - NIFTY_INDX[4:NROW(NIFTY_INDX),] head(Indx_Constituents) Constituents.list.of.S.P.CNX.Nifty X X.1 X.2 X.3 4 ACC Ltd. CEMENT AND CEMENT PRODUCTS ACC EQ INE012A01025 5 Ambuja Cements Ltd. CEMENT AND CEMENT PRODUCTS AMBUJACEM EQ INE079A01024 6 Axis Bank Ltd. BANKS AXISBANK EQ INE238A01026 7 Bajaj Auto Ltd. AUTOMOBILES - 2 AND 3 WHEELERS BAJAJ-AUTO EQ INE917I01010 8 Bharat Heavy Electricals Ltd. ELECTRICAL EQUIPMENT BHEL EQ INE257A01018 9 Bharat Petroleum Corporation Ltd. REFINERIES BPCL EQ INE029A01011 colNames - NIFTY_INDX[2,] colNames Constituents.list.of.S.P.CNX.Nifty X X.1 X.2 X.3 2 Company Name Industry Symbol Series ISIN Code I want to assign the info from colNames[1,] to Indx_Constituents I am unable to do this directly ... I can probably pull out the values and do it but there should be an easier way Now when I do this: colNames[1,1] [1] Company Name 52 Levels: ACC Ltd. Ambuja Cements Ltd. Axis Bank Ltd. Bajaj Auto Ltd. Bharat Heavy Electricals Ltd. Bharat Petroleum Corporation Ltd. Bharti Airtel Ltd. Cairn India Ltd. Cipla Ltd. Company Name ... Wipro Ltd. Why does R have to remember the 52 levels?? Why can't it just have the relevant data stored What are the alternatives so that I can simply have my needed data in my data frames? Thanks for your explanation. -- Thanks R-Helpers. Yes, this is a silly question and it will not be repeated! :-) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] nonparaeff package, fdh() function
The nonparaeff package's function fdh(), when used with an output-orientation, produces an efficiency score that puzzles me. I am using nonparaeff in R version 2.8.1 running under Linux. In this context, I ran the following code: library(nonparaeff) input= c(6, 10, 16, 14, 15) output=c(8, 20, 26, 4, 24) tab.dat = data.frame(y=output, x=input) fdhoo = fdh(tab.dat, noutput=1, orientation=2) fdhoo That code produced the following output: eff 1 1 2 1 3 1 4 1 5 1 The efficiency score for DMU 4 surprises me. This DMU, using input quantity 14, should be able to produce at least as much as DMU 2, which uses input level 10. Yet DMU 4 produces 4 output units, compared to 20 for DMU 2. I would expect DMU 4 to be able to raise output by a factor of 5. If so, the reported eff is puzzling. Can anyone tell me how to get nonparaeff to produce correct efficiency scores in output orientation? I'll be very grateful for your suggestions. Best regards, John -- John P. Burkett Department of Economics University of Rhode Island Kingston, RI 02881-0808 USA phone (401) 874-9195 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Data contamination
Dear experts, Helps are badly needed. I'm trying to generate a panel data with error term from N(0,1) and alpha from U(0,20).Explanatory variables are from multivariate std normal distn. Problem arised when I tried to contaminate the data in Y by adding additional term from N(50,1). I ask the computer to choose 5 random data from Y by using the command runif(5,1,50) since we have 50 data altogether. i worry the computer will choose the same data twice. will that happen? i attach the command for comments. thanks for your help. -Mag ## N=10; Ti=5; K=3; alpha=matrix(1:N); beta=matrix(0,nrow=K, ncol=1); beta=matrix(1:K); generate.p-function(N,Ti,K){ X=matrix(,nrow=N*Ti,ncol=K); Y=matrix(,nrow=N*Ti,ncol=1); c=1 for (j in 1:N){ X[c:(Ti*j),]-rmvnorm(Ti,rep(0,K),diag(K)); Y[c:(Ti*j),]-alpha[j]+X[c:(Ti*j),]%*%beta+matrix(rnorm(Ti,1)); c=1+(Ti*j); } data.sim-cbind(Y,X) data.sim[runif(5,1,50),1]-data.sim[runif(5,1,50),1]+rnorm(5, mean=20, sd=1) data.sim; } # [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Basic structure operations doubt
Thanks Josh. At your convenience, Any pointers on why this was designed like this? i.e. shouldn’t droplevels() be the default behavior? I'm missing something in understanding on how these operations (manipulations) were designed to work. -Original Message- From: Joshua Wiley [mailto:jwiley.ps...@gmail.com] Sent: 18 October 2010 07:47 To: Santosh Srinivas Cc: r-help@r-project.org Subject: Re: [R] Basic structure operations doubt Hi, The easiest way to get rid of the empty levels is with droplevels(). See ?droplevels for details. It actually has a method for data frames even. So you could just do something like: Indx_Constituents - droplevels(Indx_Constituents) or whatever your data frame was called and it will drop any unused levels for you. Cheers, Josh On Sun, Oct 17, 2010 at 7:06 PM, Santosh Srinivas santosh.srini...@gmail.com wrote: I'm doing these manipulations on the data frame and wondering why does R have to remember historical data on my operation and not just keep the needed info. Probably a basic fundamentals of the way R handles data .. Pls point me to the manual if possible .. I have this Index data: head(NIFTY_INDX) �Constituents.list.of.S.P.CNX.Nifty � � � � � � � � � � � � �X � � � X.1 X.2 � � � � �X.3 1 2 � � � � � � � � � � � Company Name � � � � � � � � � Industry � �Symbol Series � �ISIN Code 3 4 � � � � � � � � � � � � � ACC Ltd. CEMENT AND CEMENT PRODUCTS � � � ACC EQ INE012A01025 5 � � � � � � � �Ambuja Cements Ltd. CEMENT AND CEMENT PRODUCTS AMBUJACEM EQ INE079A01024 6 � � � � � � � � � � Axis Bank Ltd. � � � � � � � � � � �BANKS �AXISBANK EQ INE238A01026 I Import the section that is relevant to me: Indx_Constituents - NIFTY_INDX[4:NROW(NIFTY_INDX),] head(Indx_Constituents) �Constituents.list.of.S.P.CNX.Nifty � � � � � � � � � � � � � � �X X.1 X.2 � � � � �X.3 4 � � � � � � � � � � � � � ACC Ltd. � � CEMENT AND CEMENT PRODUCTS ACC �EQ INE012A01025 5 � � � � � � � �Ambuja Cements Ltd. � � CEMENT AND CEMENT PRODUCTS AMBUJACEM �EQ INE079A01024 6 � � � � � � � � � � Axis Bank Ltd. � � � � � � � � � � � � �BANKS AXISBANK �EQ INE238A01026 7 � � � � � � � � � �Bajaj Auto Ltd. AUTOMOBILES - 2 AND 3 WHEELERS BAJAJ-AUTO �EQ INE917I01010 8 � � �Bharat Heavy Electricals Ltd. � � � � � ELECTRICAL EQUIPMENT BHEL �EQ INE257A01018 9 �Bharat Petroleum Corporation Ltd. � � � � � � � � � � REFINERIES BPCL �EQ INE029A01011 colNames - NIFTY_INDX[2,] colNames �Constituents.list.of.S.P.CNX.Nifty � � � �X � �X.1 � �X.2 � � � X.3 2 � � � � � � � � � � � Company Name Industry Symbol Series ISIN Code I want to assign the info from colNames[1,] to Indx_Constituents I am unable to do this directly ... I can probably pull out the values and do it but there should be an easier way Now when I do this: colNames[1,1] [1] Company Name 52 Levels: �ACC Ltd. Ambuja Cements Ltd. Axis Bank Ltd. Bajaj Auto Ltd. Bharat Heavy Electricals Ltd. Bharat Petroleum Corporation Ltd. Bharti Airtel Ltd. Cairn India Ltd. Cipla Ltd. Company Name ... Wipro Ltd. Why does R have to remember the 52 levels?? Why can't it just have the relevant data stored What are the alternatives so that I can simply have my needed data in my data frames? Thanks for your explanation. -- Thanks R-Helpers. Yes, this is a silly question and it will not be repeated! :-) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] paste an unevaluated expression
Hi R-users, I would like to create an expression without evaluating it. Then paste that expression to an object. Example: Result - paste('Result', 1, sep=) paste(Result, substitute(apply(exp.des[1:10,], 1, one.row, parms=parameters)), sep=-) However this pastes EACH element of the unevaluated expression. Instead I just would like the expression to be a character string, with just ONE element. I tried: toString(substitute(apply(exp.des[1:10,], 1, one.row, parms=parameters))) but it modifies the expression (e.g. removing parenthesis), which I do not want. Any idea on how to create an unevaluated expression and paste it to an object, to get a 1 element output? Thanks for your help Lorenzo [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] paste an unevaluated expression
On Sun, Oct 17, 2010 at 9:14 PM, Lorenzo Cattarino l.cattar...@uq.edu.au wrote: Hi R-users, I would like to create an expression without evaluating it. Then paste that expression to an object. Example: Result - paste('Result', 1, sep=) paste(Result, substitute(apply(exp.des[1:10,], 1, one.row, parms=parameters)), sep=-) However this pastes EACH element of the unevaluated expression. Instead I just would like the expression to be a character string, with just ONE element. Try this: s - substitute(...whatever...) paste(Result, format(s), sep = -) -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Data contamination
Hi, You are right, runif(5,1,50) could generate a same value twice. And I think that your code runs runif(5,1,50) twice too. Try ?sample selected - sample(1:50,3) data.sim[selected,1] - data.sim[selected,1] + rnorm(5, mean=20, sd=1) Hope it helps. - A R learner. -- View this message in context: http://r.789695.n4.nabble.com/Data-contamination-tp2999622p2999636.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] dpois().......bizarre warning messages
Hi: On Sun, Oct 17, 2010 at 8:46 AM, Federico Bonofiglio bonori...@gmail.comwrote: Dear Masters, I have a question to submit consider the following script m-4.95 obs-rpois(36,m) # i generate 36 realization from a poisson(m) hist(obs,freq=F) curve(dpois(x,m),add=T,col=red) #i wish to overlay on the histogram the theorical poisson density function A histogram is meant to be a crude density estimate of a continuous random variable; similarly, curve() is meant to display a continuous function of x. You have a [discrete] Poisson probability mass function (pmf) with a corresponding sample of size 36 from it. These should be displayed as probability mass functions and bar charts, respectively. I wouldn't be surprised if this were homework, but it's an opportunity to teach you a few things about the graphics packages , including lattice and ggplot2, which will be worth your time if you intend to pursue statistics beyond the present. Luckily(?), I have a little time today :) Discrete distributions should be plotted as discrete distributions. Bar charts are good for this task - the separation placed between categories is meant to denote that the values on the x-axis are discrete. You can superimpose a theoretical Poisson pmf onto a bar chart rather easily in both ggplot2 and lattice. I'll leave the base graphics solution to the end. There are two ways to go: (1) Compare the relative frequency bar chart of the sample with its theoretical pmf; (2) Compare the cumulative relative frequencies with the theoretical cumulative pmf. # Approach 1: Bar charts # Preliminary step: data manipulation Your goal is to overlay the theoretical pmf onto the empirical distribution, but the latter has to be a relative frequency distribution in order for the two to be comparable. The hardest part, in some sense, is to arrange the data properly so that the observed relative frequencies and the Poisson probabilities can all be plotted - from a sample of size 36, it is possible that one or more x values will be missing and cause gaps in the plot. We need to handle that contingency first before plotting. (I found that out the hard way while proofing the code.) The below is a little messy, but it's functional. m - 4.95 obs - rpois(36, 4.95) # Create a data frame from the frequency table generated from obs d - as.data.frame(table(obs)) d$Obs - as.numeric(as.character(d$obs) ) # convert obs from factor to numeric d$rfreq - with(d, Freq/sum(Freq)) # compute the relative frequencies # Now create a data frame that will compute Poisson probabilities for x = 0 to max(d$Obs): x - seq(0, max(d$Obs)) dpm - data.frame(x = x, pm = dpois(x, 4.95)) # Merge d and dpm, retaining all the rows of dpm - there may be NAs # in some places with respect to d dd - merge(d, dpm, by.x = 'Obs', by.y = 'x', all.y = TRUE) dd$obs - NULL # remove factor obs dd$Freq - NULL # remove raw frequencies - no longer needed # Convert NA relative frequencies to zero dd$rfreq[is.na(dd$rfreq)] - 0 dd str(dd) # everything should be numeric # Add the graphics packages to the session (make sure they're installed first) library(ggplot2) library(lattice) # Superimposed relative frequency bar charts with Poisson pmf: # the first is the lattice version, the second from ggplot2. # Lattice: the panel function is necessary to superimpose two different # graphs onto the same graphics surface. Type 'h' plots vertical lines from 0 # to the y-value for each x; lwd represents line width. xyplot(pm ~ Obs, data = dd, panel = function(x, y, ...) { panel.barchart(x, dd$rfreq, horizontal = FALSE, col = 'orange', ...) panel.xyplot(x, y, type = 'h', col = 'blue', lwd = 4) }, xlab = 'x', ylab = '', ylim = c(0, 0.3)) # ggplot2 is a modular approach to graphics. One puts down graphical layers # with geoms to which other graphical elements can be added. The resulting # graph is pretty much the same as the xyplot, but the default background is # different. Since geom_segment() doesn't use the fill 'aesthetic' (it's black # no matter what), we adjust the legend accordingly. Notice how the quoted # strings in fill = become the labels of the legend. Adjust the ylab() as needed. p - ggplot(dd, aes(x = Obs)) p + geom_bar(aes(y = rfreq, fill = 'observed'), stat = 'identity') + geom_segment(aes(xend = x, yend = 0, y = pm, fill = 'Poisson(4.95)'), size = 4) + scale_fill_manual('Type', values = c('observed' = 'orange', 'Poisson(4.95)' = 'black')) + xlab('x') + ylab() + ylim(0, 0.3) Another way to compare empirical and theoretical distributions is to compare their corresponding cdf's. # Approach 2: Empirical cdfs: # ggplot2's geom_step() will plot a step function from its input # arguments. In this case, it is convenient to 'melt' the data frame dd so that # the empirical and theoretical cumulative distributions can easily be plotted # separately in both
Re: [R] How to install R on Linux via source compilation?
On Sunday, October 17, 2010 10:27:48 am noclue_ wrote: How to install R on Linux via source compilation? Has anybody done it? I could not find step by step instructions online. I would appreciate if you could share your experience. If you are new to linux, I would strongly recommend using a package manager for your release (e.g. apt-get for ubuntu) and using the available binary. If you need to be on the bleeding edge then you will have to compile and install. Download the source archive, e.g. R-2.12.0.tar.gz, from CRAN. The simplest route from here would to bring up a BASH terminal and cd to the directory where the file was written during download. Uncompress it using tar, e.g. tar xzvf R-2.12.0,tar.gz That should uncompress the file to a new sub directory within the download directory. For instance, if your download directory is /home/your user name/downloads, then the new directory will be /home/your user name/downloads/R-2.12.0. Change to that directory. Listing the contents will show you a number of files including a file named INSTALL. Read that file first. Then check the other files it points to before doing anything else. It gives directions on the compilation and installation process for local or site-wide installation. The INSTALL file tells you run configure. You will need to execute that file by typing ./configure since you want to execute that specific configure script rather than another one that might be lurking somewhere in the path. Configure will stream a l list of checking messages. If critical elements are missing it will halt and give a message such as: configure: error: --with-x=yes (default) and X11 headers/libs are not available Every error that halts configure will need to be corrected by installing the missing element or adding a symbolic link to the correct file in the directory where configure looks for it. Many of the missing elements will available through the development packages that various releases of linux offer. The process will likely be incremental as each fix and execution will allow configure to run a little longer until the next error is encountered. Configure generates a file config.log that is informative about what is taking place. Grepping that file for the term error will probably produce a substantial list of less than critical errors. Once you have a clean configure, then you can return to the INSTALL directions. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Incorrect positioning of raster images on Windows
I am working on dumping raster data from R into PNG files using rasterImage(). I am working with a test matrix from the rasterImage() example and using it to produce a PNG image with the following code: # From the example for rasterImage(). A 3 pixel by 5 pixel b/w checkerboard. testImage - as.raster(0:1, nrow=3, ncol=5) testImage [,1] [,2] [,3] [,4] [,5] [1,] #00 #FF #00 #FF #00 [2,] #FF #00 #FF #00 #FF [3,] #00 #FF #00 #FF #00 png('test.png', width=5, height=3, units='px') # Just want the image, no margins, boarders or other fancy stuff. par(mar = c(0,0,0,0) ) plot.new() plotArea = par('fig') rasterImage(testImage, plotArea[1], plotArea[3], plotArea[2], plotArea[4], interpolate = FALSE ) dev.off() However, using R 2.12.0, 64 bit on Windows 7 I have a strange issue where the image is shifted up by one row and to the left by one row. In other words, the bottom row of pixels is missing along with the right column. The code works as I expect it to on OS X and Debian. Am I misusing the plotting commands in some way or should I submit an off-by-one bugreport to Bugzilla? Any suggestions or comments are most welcome. -Charlie - Charlie Sharpsteen Undergraduate-- Environmental Resources Engineering Humboldt State University -- View this message in context: http://r.789695.n4.nabble.com/Incorrect-positioning-of-raster-images-on-Windows-tp2999649p2999649.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.