[R] how to control the label position on panels of trellise plot
Hi, I am wondering how to control the label position on panels of trellise plot. I have 6 panels, I want to all x label positions at the bottom of each panel. How should I do that? Similar, how should I control y label positions of each panel? 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] error in mixed effect model when use "maximum likelihood"
Dear List, I tried to fit a mixed effect model. data are like this: groupid time t control 10 4.3 control 20 3.7 control 30 4.0 control 40 3.6 control 50 4.1 control 60 3.8 .. control 45 5.1 control 55 4.5 control 65 3.3 it has repeated measurement("t") for each "id" at different "time". So I constructed a mixed effect model using package nlme: m1<-lme(t~time*group,random=~time|id,data=p_long) it worked fine. However when I used m2<-lme(t~time*group,random=~time|id,data=p_long,method="ML") it gave me error: "Error in lme.formula(t ~ time * group, random = ~time | id, data = p_long, : nlminb problem, convergence error code = 1 message = iteration limit reached without convergence (9)" and if I changed it to m3<-lme(t~time*group,random=~1|id,data=p_long,method="ML") It also worked fine. In summary, m1 used "random=~time|id" and no "ML" (so it was "REML"), it worked fine. m2 used "random=~time|id" and "ML", it gave errors m3 used "random=~1|id", and "ML", it worked fine. Could someone explain these to me? Thanks you. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] unix like commands in R?
Thank you Ted. I did try page(file,method="print"), it did behave as "less". I will try the code to modify the profile as well to see how it goes. Thank you very much. On Mon, Aug 24, 2009 at 5:32 PM, Ted Harding wrote: > On 24-Aug-09 21:56:06, zrl wrote: > > Dear List: > > I am trying to find a command in R which is like the unix command > > "less" or "more" to show the data in a object of R. > > did anyone can help me on this? > > > > Is there a collection of such unix-like commands in R? > > > > Thanks. > > > > -ZRL > > There is a page() command in R -- see '?page'. From your query I take > it you are in fact using either Linux or Unix (or possible a Mac BSD > type OS). > > Have a look at options("pager") to see what is currently uses. > > I have modified my R setup so that it uses 'less' (on Linux) as > the pager program. > > I did this in my .Rprofile (in home directory) by putting in the > lines: > > > .xthelp <- function() { >tdir <- tempdir() >pgr <- paste(tdir, "/pgr", sep="") >con <- file(pgr, "w") >cat("#! /bin/bash\n", file=con) >cat("export HLPFIL=`mktemp ", tdir, "/R_hlp.XX`\n", >sep="", file=con) >cat("cat > $HLPFIL\nxterm -e less $HLPFIL &\n", file=con) >close(con) >system(paste("chmod 755 ", pgr, sep="")) >options(pager=pgr) > } > .xthelp() > rm(.xthelp) > > > This opens anything which might be paged in a separate xterm, > so thatfor instance, all responses to "?." come up in a new > xterm being paged by 'less'. Likewise, if you page a large object > (such as a matrix M with 500 rows), using 'page(M), you will > again see the result paged in 'less' in a separate window. > > This code was suggested by Roger Bivand in response to a query > of mine back in 2003. The URL is > > http://finzi.psych.upenn.edu/R/Rhelp02/archive/21642.html > > This was an improvement on a previous solution of my own, which > is also quoted in the above URL. > > Hoping this helps, > Ted. > > > E-Mail: (Ted Harding) > Fax-to-email: +44 (0)870 094 0861 > Date: 24-Aug-09 Time: 23:32:18 > -- XFMail -- > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to explain the interaction terms regarding "treatmentcontrast" of lm model
Thank you all for your help. Daniel, I want to know if I really understand your answer. I calculated each group mean and sub mean as below: > tapply(val,group,mean) group1 group2 group3 4.215670 5.664411 7.210819 > tapply(val,sub,mean) abcd 4.856927 5.199305 6.183979 6.547655 and intercept (group=1 and sub=a) is: 3.506216 (see original post table) average difference between group2 and group1 is: 5.664411 - 4.215670=1.448741 average difference between sub b and sub a is: 5.199305-4.856972=0.342333 therefore, if I understand this right, the reference level for interaction between sub=b and group=2 should be the sum of the above numbers, which is: 3.506216+1.448741+0.342333=5.29729 Am I right? Thank you vey much. On Fri, Aug 28, 2009 at 7:02 PM, Daniel Malter wrote: > The intercept is group=1, sub=a, > > The interaction between sub=b and group=2 implies that both sub=b and > group=2 direct effects are included. That is, with the direct effects only > you are now at: intercept+group2+subb, which means the intercept (group1 > and > sub=a) + the average difference between group=2 and group=1 + the average > difference between sub=b and sub=a. This is the reference level for the > interaction effect between group=2 and sub=b. This is not one-specific > group > in your experiment but rather a generic average group (average group=2, > average sub=b). Your interaction effect now asks the question how much does > group=2 with sub=b stand out from the average in its group and in its sub. > > To clarify your confusion, you may want to write out the model formula. > > Daniel > > - > cuncta stricte discussurus > - > > -Ursprüngliche Nachricht- > Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im > Auftrag von zrl > Gesendet: Friday, August 28, 2009 6:49 PM > An: r-help > Betreff: [R] how to explain the interaction terms regarding > "treatmentcontrast" of lm model > > Dear list, > > I am confused on how to explain the interaction term in the context of > "treatment contrast". > > for example, I have an data frame as below: > sub group val > 1a group1 3.685625 > 2a group1 3.407445 > 3a group1 4.040920 > 4a group1 2.890875 > 5b group1 3.853280 > 6b group1 4.113585 > 7b group1 3.043250 > 8b group1 3.800920 > 9c group1 5.394305 > 10 c group1 5.004290 > 11 c group1 4.651435 > 12 c group1 4.286650 > 13 d group1 4.773440 > 14 d group1 3.982200 > 15 d group1 5.718690 > 16 d group1 4.803815 > . > 45 d group3 8.021240 > 46 d group3 7.641685 > 47 d group3 7.519445 > 48 d group3 9.514580 > > then: > > >tapply(val,list(group,sub),mean) > abcd > group1 3.506216 3.702759 4.834170 4.819536 > group2 4.831503 5.246833 5.930116 6.649191 > group3 6.233062 6.648325 7.787651 8.174238 > > > summary(lm(val~group*sub)) > > Call: > lm(formula = val ~ group * sub) > > Residuals: > Min 1Q Median 3Q Max > -1.24378 -0.50184 -0.03726 0.51748 1.34034 > > Coefficients: > Estimate Std. Error t value Pr(>|t|) > (Intercept)3.5062 0.3278 10.696 9.98e-13 *** > groupgroup21.3253 0.4636 2.859 0.00703 ** > groupgroup32.7268 0.4636 5.882 9.98e-07 *** > subb 0.1965 0.4636 0.424 0.67411 > subc 1.3280 0.4636 2.865 0.00693 ** > subd 1.3133 0.4636 2.833 0.00751 ** > groupgroup2:subb 0.2188 0.6556 0.334 0.74052 > groupgroup3:subb 0.2187 0.6556 0.334 0.74060 > groupgroup2:subc -0.2293 0.6556 -0.350 0.72851 > groupgroup3:subc 0.2266 0.6556 0.346 0.73158 > groupgroup2:subd 0.5044 0.6556 0.769 0.44671 > groupgroup3:subd 0.6279 0.6556 0.958 0.34460 > --- > Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1 > > Residual standard error: 0.6556 on 36 degrees of freedom > Multiple R-squared: 0.8607, Adjusted R-squared: 0.8182 > F-statistic: 20.22 on 11 and 36 DF, p-value: 3.296e-12 > > > My question is: > with "treatment contrast" in R, Coefficients, groupgroup2,groupgroup3, > subb, > subc,subd are the difference from Intercept 3.5062 (reference level for > intercepts). > But what is the reference level for the interaction terms? such as > groupgroup2:subb,groupgroup3:subb,and etc. > > Thanks. > > [[alternative HTML version deleted]] > > > [[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 explain the interaction terms regarding "treatment contrast" of lm model
Dear list, I am confused on how to explain the interaction term in the context of "treatment contrast". for example, I have an data frame as below: sub group val 1a group1 3.685625 2a group1 3.407445 3a group1 4.040920 4a group1 2.890875 5b group1 3.853280 6b group1 4.113585 7b group1 3.043250 8b group1 3.800920 9c group1 5.394305 10 c group1 5.004290 11 c group1 4.651435 12 c group1 4.286650 13 d group1 4.773440 14 d group1 3.982200 15 d group1 5.718690 16 d group1 4.803815 . 45 d group3 8.021240 46 d group3 7.641685 47 d group3 7.519445 48 d group3 9.514580 then: >tapply(val,list(group,sub),mean) abcd group1 3.506216 3.702759 4.834170 4.819536 group2 4.831503 5.246833 5.930116 6.649191 group3 6.233062 6.648325 7.787651 8.174238 > summary(lm(val~group*sub)) Call: lm(formula = val ~ group * sub) Residuals: Min 1Q Median 3Q Max -1.24378 -0.50184 -0.03726 0.51748 1.34034 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept)3.5062 0.3278 10.696 9.98e-13 *** groupgroup21.3253 0.4636 2.859 0.00703 ** groupgroup32.7268 0.4636 5.882 9.98e-07 *** subb 0.1965 0.4636 0.424 0.67411 subc 1.3280 0.4636 2.865 0.00693 ** subd 1.3133 0.4636 2.833 0.00751 ** groupgroup2:subb 0.2188 0.6556 0.334 0.74052 groupgroup3:subb 0.2187 0.6556 0.334 0.74060 groupgroup2:subc -0.2293 0.6556 -0.350 0.72851 groupgroup3:subc 0.2266 0.6556 0.346 0.73158 groupgroup2:subd 0.5044 0.6556 0.769 0.44671 groupgroup3:subd 0.6279 0.6556 0.958 0.34460 --- Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1 Residual standard error: 0.6556 on 36 degrees of freedom Multiple R-squared: 0.8607, Adjusted R-squared: 0.8182 F-statistic: 20.22 on 11 and 36 DF, p-value: 3.296e-12 My question is: with "treatment contrast" in R, Coefficients, groupgroup2,groupgroup3, subb, subc,subd are the difference from Intercept 3.5062 (reference level for intercepts). But what is the reference level for the interaction terms? such as groupgroup2:subb,groupgroup3:subb,and etc. 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] unix like commands in R?
Dear List: I am trying to find a command in R which is like the unix command "less" or "more" to show the data in a object of R. did anyone can help me on this? Is there a collection of such unix-like commands in R? Thanks. -ZRL [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to load packages from different location
Very helpful, thank you Phil. -ZRL On Tue, Jul 28, 2009 at 6:06 PM, Phil Spector wrote: > I'm attaching some slides that address this issue. > I hope you find them useful. > > - Phil Spector > Statistical Computing Facility > Department of Statistics > UC Berkeley > spec...@stat.berkeley.edu > > > > On Tue, 28 Jul 2009, zrl wrote: > > Dear list: >> >> I know this may be an old question. >> >> I know how to install the packages to a different directory, for example, >> /home/zrl/tmp >> and I know how to load it >> >>> library("genefilter",lib.loc="/home/zrl/tmp") >>> >> >> but I found some package(for example package A) will have to load some >> other packages as well, and this time package A will look for the package >> in >> the original installation directory not the "/home/zrl/tmp". >> >> My question is, how could I tell R from now on, for every package needed >> to >> be loaded, should only be searched for in "/home/zrl/tmp"? >> >> thanks. >> >> -ZRL >> >>[[alternative HTML version deleted]] >> >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to load packages from different location
Dear list: I know this may be an old question. I know how to install the packages to a different directory, for example, /home/zrl/tmp and I know how to load it >library("genefilter",lib.loc="/home/zrl/tmp") but I found some package(for example package A) will have to load some other packages as well, and this time package A will look for the package in the original installation directory not the "/home/zrl/tmp". My question is, how could I tell R from now on, for every package needed to be loaded, should only be searched for in "/home/zrl/tmp"? thanks. -ZRL [[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] allocation/initialization of arrays/lists
Dear list, I have a question regarding how to allocate or initialize the proper type of the arrays or lists. I have a for loop, each iteration, I want it to assign a subset of a data frame to an element of an array or list. However, I am wondering how I should initialize or allocate the empty array or list so that it has the same number of the elements as the subsets I am going to assign and also make the data type is compatible to the subset I am going to assign to it. It should look like this: #initialize or allocate. ( I don't know how to) { some codes: initialize an array or list (which one is better?) with "n" elements} #"for" loop for assigning a subset of a large data frame to the elements of the array or list (which on is better?) for (i in 1: n){ array[i] <- df[df$V1==A[i],] } Thanks. ZRL [[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.