[R] plotting multilevel / lme lines

toby909 at gmail.com toby909 at gmail.com
Fri Apr 6 21:27:49 CEST 2007


Yesterday, I tried to do exactly this, too. Below is my approach. Unfortunately, 
I did not find a textbook example against which I could verify my code. Hints, 
simplifications, and verification highly appreciated!!!

### random slope! model
v = lme(POPULAR ~ SEX + TEXP, data=dta, random = ~ SEX | SCHOOL)
### setting up the thing to plot
a = matrix(t(cbind(0, coef(v)[,1], 1, coef(v)[,2])), ncol=2, byrow=1)
plot(a)
### connecting only the pairs I want to have connected, ie dont connect all dots
for (i in 1:(length(a)/4)*2-1) lines(a[i:(i+1),])

Thanks Toby

data downloaded from http://www.ats.ucla.edu/stat/examples/ma_hox/default.htm



Rense Nieuwenhuis wrote:
> Dear expeRts,
> 
> I am trying to plot a lme-object {package nlme) in such a way, that  
> on a selected level the x-axis represents the value on a selected  
> predictor and the y-axis represents the predicted-outcome variable.  
> The graphs would than consist of several lines that each represent  
> one group. I can't find such a plotting function.
> 
> I could write such a function myself, based on ranef() and fixef(),  
> but it would be a waste of time if such a function would already exist.
> 
> Does any of you such a function?
> 
> Regards,
> 
> Rense Nieuwenhuis
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list