[R] lme between-group and within-group covariance
Dear R users, I would be interested in using the lme() function to fit a linear mixed model to a longitudinal dataset. I know this function allows for the specification of a within-group covariance structure. However, does it allow for the explicit specification of a between-group covariance structure? Being able to specify both separately would be very important in the context of my project since, as might be expected, they have different implications/interpretations. For instance, the mixed procedure in SAS allows users to specify the two structures separately by adding a value for the type argument after the RANDOM statement and the REPEATED statement. My question is thus if we can do the same with lme(). I thank you most sincerely for your help. -- View this message in context: http://www.nabble.com/lme-between-group-and-within-group-covariance-tp22834748p22834748.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] lme between-group and within-group covariance
I will try to make this more precise. In the lme() function, the "correlation" argument allows the user to specify a within-group correlation structure, i.e. the structure of the Lambda matrix using the mixed model notation in Pineiro and Bates. What I want to do is specify a distinct structure for the Psi matrix (same notation), that is, a correlation structure for the random effects. If lme() doesn't allow for this, is there any other function that I could use? MUHC-Research wrote: > > Dear R users, > > I would be interested in using the lme() function to fit a linear mixed > model to a longitudinal dataset. I know this function allows for the > specification of a within-group covariance structure. However, does it > allow for the explicit specification of a between-group covariance > structure? > > Being able to specify both separately would be very important in the > context of my project since, as might be expected, they have different > implications/interpretations. > > For instance, the mixed procedure in SAS allows users to specify the two > structures separately by adding a value for the type argument after the > RANDOM statement and the REPEATED statement. > > My question is thus if we can do the same with lme(). > > I thank you most sincerely for your help. > -- View this message in context: http://www.nabble.com/lme-between-group-and-within-group-covariance-tp22834748p22868945.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] Overlaying graphs from different datasets with ggplot
Dear R-users, I recently began using the ggplot2 package and I am still in the process of getting used to it. My goal would be to plot on the same grid a number of curves derived from two distinct datasets. The first dataset (called molten.data) looks like this : Column names : Perc, Week, Weight P10 21 333.3554 P90 21 486.0480 P10 22 452.6347 P90 22 563.8263 P10 23 575.0960 P90 23 661.6841 P10 24 700.4449 P90 24 779.4067 P10 25 828.4966 P90 25 917.1222 The second dataset (called skj) looks like this: Column names : Week, Perc, Weight 211 317.5 221 392.5 231 467.5 241 542.5 251 617.5 261 697.5 212 535.0 222 632.5 232 737.5 242 855.0 252 980.0 262 1115.0 213 425.0 223 512.5 233 602.5 243 697.5 253 800.0 263 907.5 Now, I plot my graphs using (with the Perc column in skj being a factor) : p <- ggplot(molten.data, aes(x=Week, y=Weight, group=Perc)) ; p <- p + geom_line(aes(colour = Perc,size=1,linetype=Perc)) ; p + geom_line(data=skj,mapping=aes(x=Week,y=Weight,group=Perc,linetype=Perc)) ; This yields the following error message: ## Error in data.frame(c("#FF6C91FF", "#00C1A9FF"), c("solid", "22", "42", : arguments imply differing number of rows: 2, 5 ## If I remove the linetype=Perc argument, I get a graph, but also a warning: ## Warning message: In data$arrow <- NULL : Coercing LHS to a list ## So, what am I doing wrong in this situation? I thank you sincerely for your help, Luc -- View this message in context: http://www.nabble.com/Overlaying-graphs-from-different-datasets-with-ggplot-tp23322409p23322409.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] A beginner's question about ggplot
Dear R-users, I would have another question about the ggplot() function in the ggplot2 package. All the examples I've read so far in the documentation make use of a single neatly formatted data.frame. However, sometimes, one may be interested in plotting on the same grid information or objects derived from two totally different datasets and customize both displays. I still cannot tell how this can be done using ggplot(). Here's an example. ### ## A very simple data.frame; my.data = data.frame(X1 = as.factor(rep(1:2,c(4,4))),X2=c(4,3,5,2,6,2,3,5),X3=c(1:3,2,2:4,5)) ; ## Let's say I want to add the X^2 line to the plot; squared = data.frame(X=1:12,Y=((1:12)/2)^2) ; ## A scatterplot for my.data ; p = ggplot(my.data,aes(x=X2,y=X3,group=X1)) ; p = p+geom_point(aes(colour=X1)) ; # How can "squared" be added to the plot? At first, I used p+geom_line(data=squared,aes(x=X,y=Y,group=1,colour="green")) ; but the plotted line is always blue! In fact, I can replace colour by any character value and I will still get a blue line. Although I may be wrong, I think this is pretty straightforward. Can anyone give me a pointer as to how we can add arbitrary curves to a ggplot graph and then customize them? A bit later, I'll have to overlay histograms derived from totally different datasets and, if possible, I'd like to use the ggplot2 library for that too, hence the importance of understanding how ggplot objects can be mixed. Thanks a lot, Luc -- View this message in context: http://www.nabble.com/A-beginner%27s-question-about-ggplot-tp23336793p23336793.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.