I have what is probably a very simple problem but I would be very grateful to the list for any help or pointers to implement a solution in R. We have two types of measurements on the eye that we have collected in 62 patients at 5 fixed time points during a clinical visit over an office day. We want to establish if there is an association between the measurements. Obviously it would be wrong to generate a simple scatterplot of all 62*5 observations and consider something like a simple correlation coefficient. What I really need is to set up a 2-level model with measurements nested within patients and use, perhaps, one variable as a response and the other as a predictor. I would also like to add in time of day (probably as a categorical) to check this isn't affecting things. I haven't used multi-level modelling in R and wonder how I can simply go about fitting this model and looking at the significance of the estimates in R. I also have a plot in my mind - 62 little regression lines (n=5) and think that this might be informative..... Any help or pointers will be gratefully received - Many Thanks. Dr. David Crabb Department of Optometry and Visual Science, City University, Northampton Square, London EC1V OHB Tel: 44 207 040 0191 d.crabb at city.ac.uk http://www.city.ac.uk/optometry/about/staff/crabb.html
This should get you started tmp <- data.frame(y1=rnorm(62*5), y2=rnorm(62*5), time=rep(1:5, 62), id=factor(rep(1:62, each=5)) ) xyplot(y1 ~ y2 | id, data=tmp, group=time, pch=as.character(1:5)) tmp.aov <- aov(y1 ~ y2*factor(time) + Error(id), data=tmp) summary(tmp.aov)
Aov is not the right function for this problem. Lmer is designed for multilevel modeling. There are a lot of resources, but start with the following vignette Library(lme4) vignette("MlmRevSoft") And then turn to Pinhiero and Bates> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of > Richard M. Heiberger > Sent: Thursday, January 18, 2007 10:22 AM > To: Crabb, David; r-help at stat.math.ethz.ch > Subject: Re: [R] Help with problem - multilevel model? > > This should get you started > > > tmp <- data.frame(y1=rnorm(62*5), > y2=rnorm(62*5), > time=rep(1:5, 62), > id=factor(rep(1:62, each=5)) > ) > > xyplot(y1 ~ y2 | id, data=tmp, group=time, pch=as.character(1:5)) > > tmp.aov <- aov(y1 ~ y2*factor(time) + Error(id), data=tmp) > summary(tmp.aov) > > ______________________________________________ > 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. >