cd4$vdate <- as.Date(cd4$vdate)
require(lattice)
xyplot(sqrt(cd4pct) ~ vdate, cd4, group=newpid,type=c("p","r"))
lmList
in nlme
package. (The intervals command creates 95%
CIs for each kid's intercept and slope.)
require(nlme) cd4.kidfit <- lmList(sqrt(cd4pct) ~ I(as.numeric(vdate)-7128)|factor(newpid),cd4[,3:5]) plot(intervals(cd4.kidfit))Suggestion from Brian: Instead of making time =0 occur in the middle of all dates, you could use
I(visage-baseage) to make time zero occur on
the first visit of each kid. Then intercepts will be
initial cd4 counts, which make more sense than counts at
an arbitrary time.Instead of using lmList, you could build a function to fit a SLR for each child. That will give slightly different estimates because lmList assumes there is one common variance across all kids.
intercepts <- summary(cd4.kidfit)$coefficients[,1,1] slopes <- summary(cd4.kidfit)$coefficients[,1,2] plot(slopes~intercepts) age1 <- with(cd4, tapply(baseage, newpid,min)) trt <- with(cd4, tapply(treatmnt, newpid,min))