Hi, I am using nlme for data from nested design. That is, "tows" are nested within "trip", "trips" nested within "vessel", and "vessels" nested within "season". I also have several covariates, say "tow_time", "latitude" and "depth" My model is y = season + tow_time + latitude + depth + vessel(season) + trip(season, vessel) + e In SAS, the program would be proc mixed NOCLPRINT NOITPRINT data=obtwl.x; class vessel trip tow season depth; model y = season depth latitude /solution; <----------fixed effects random vessel(season) trip(season vessel); run; My question is: How this nested mixed-effects model can be fitted in R- "nlme"? Thanks in advance for the helps. Cheers! Han
Lorenz.Gygax@fat.admin.ch
2004-Apr-30 05:24 UTC
[R] Mixed-effects model for nested design data
Dear Han,> I am using nlme for data from nested design. That is, "tows" are nested > within "trip", "trips" nested within "vessel", and "vessels" nested > within "season". I also have several covariates, say "tow_time", > "latitude" and "depth" > My model is > y = season + tow_time + latitude + depth + vessel(season) + > trip(season, vessel) + e > In SAS, the program would be > proc mixed NOCLPRINT NOITPRINT data=obtwl.x; > class vessel trip tow season depth; > model y = season depth latitude /solution; <----------fixed effects > random vessel(season) trip(season vessel); > run; > My question is: How this nested mixed-effects model can be > fitted in R-> "nlme"?I do not know about SAS but I would guess that your model should be fitted as something like: lme (fixed= y ~ season + tow_time + latitude + depth, random= ~ 1 | season/vessel/trip) Maybe you should do some reading in the book by Pinheiro & Bates? They explain well how to set up models. Regards, Lorenz - Lorenz Gygax, Dr. sc. nat. Tel: +41 (0)52 368 33 84 / lorenz.gygax at fat.admin.ch Tag der offenen T??r, 11./12. Juni 2004: http://www.fat.ch/2004 Center for proper housing of ruminants and pigs Swiss Veterinary Office agroscope FAT T??nikon, CH-8356 Ettenhausen / Switzerland Fax : +41 (0)52 365 11 90 / Tel: +41 (0)52 368 31 31
quote:> I am using nlme for data from nested design. That is, "tows" arenested> within "trip", "trips" nested within "vessel", and "vessels" nested > within "season". I also have several covariates, say "tow_time", > "latitude" and "depth" > My model is > y = season + tow_time + latitude + depth + vessel(season) + > trip(season, vessel) + e > In SAS, the program would be > proc mixed NOCLPRINT NOITPRINT data=obtwl.x; > class vessel trip tow season depth; > model y = season depth latitude /solution; <----------fixed effects > random vessel(season) trip(season vessel); > run; > My question is: How this nested mixed-effects model can be > fitted in R-> "nlme"?> I do not know about SAS but I would guess that your model should be > fitted > as something like: > > lme (fixed= y ~ season + tow_time + latitude + depth, > random= ~ 1 | season/vessel/trip) > > Maybe you should do some reading in the book by Pinheiro & Bates? > They explain well how to set up models.I would create a grouped data variable, to avoid having season a both a random and fixed effect: your.data$SV<-getGroups(your.data, form=~1|season/vessel, level=2) the effect is to create a variable that groups vessels %in% season. BTW, according to your coding of the data, this stem is not always necessary. HTH Federico Calboli -- ================================ Federico C. F. Calboli Dipartimento di Biologia Via Selmi 3 40126 Bologna Italy tel (+39) 051 209 4187 fax (+39) 051 209 4286 f.calboli at ucl.ac.uk fcalboli at alma.unibo.it