Homework #11 STAT 505 Fall 2011

Due date: December 7, 2011
Include all R code as an appendix.
Include R output as needed to explain your analysis, but not in big chunks. It's your job to distill and explain which parts are important to look at.
  1. Exercise 11.1 p 248.
  2. Exercise 11.4 p 249, but use these data (a subset with missing values and singletons removed.)
    1. Plot square root CD4 percentage over time with regression lines.
      cd4$vdate <- as.Date(cd4$vdate)
      require(lattice)
      xyplot(sqrt(cd4pct) ~ vdate, cd4, group=newpid,type=c("p","r"))
      
    2. Create a fit for each kid using 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.
      
      	
    3. Extract coefficient vectors for each kid and obtain the two predictors we need, then fit between-child models as they specify. In the treatmnt column, 1 is control, 2 is treated.
       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))
      


    Author: Jim Robison-Cox
    Last Updated: