marginpred              package:survey              R Documentation

_S_t_a_n_d_a_r_d_i_s_e_d _p_r_e_d_i_c_t_i_o_n_s (_p_r_e_d_i_c_t_i_v_e _m_a_r_g_i_n_s) _f_o_r _r_e_g_r_e_s_s_i_o_n _m_o_d_e_l_s.

_D_e_s_c_r_i_p_t_i_o_n:

     Reweights the design (using 'calibrate') so that the adjustment
     variables are uncorrelated with the variables in the model, and
     then performs predictions by calling 'predict'.  When the
     adjustment model is saturated this is equivalent to direct
     standardization on the adjustment variables.

     The 'svycoxph' and 'svykmlist' methods return survival curves.

_U_s_a_g_e:

     marginpred(model, adjustfor, predictat, ...)
     ## S3 method for class 'svycoxph':
     marginpred(model, adjustfor, predictat, se=FALSE, ...)
     ## S3 method for class 'svykmlist':
     marginpred(model, adjustfor, predictat, se=FALSE, ...)
     ## S3 method for class 'svyglm':
     marginpred(model, adjustfor, predictat,  ...)

_A_r_g_u_m_e_n_t_s:

   model: A regression model object of a class that has a 'marginpred'
          method 

adjustfor: Model formula specifying adjustment variables, which must be
          in the design object of the model 

predictat: A data frame giving values of the variables in 'model' to
          predict at

      se: Estimate standard errors for the survival curve (uses a lot
          of memory if the sample size is large)

     ...: Extra arguments, passed to the 'predict' method for 'model'

_S_e_e _A_l_s_o:

     'calibrate'

     'predict.svycoxph'

_E_x_a_m_p_l_e_s:

     ## generate data with apparent group effect from confounding
     set.seed(42)
     df<-data.frame(x=rnorm(100))
     df$time<-rexp(100)*exp(df$x-1)
     df$status<-1
     df$group<-(df$x+rnorm(100))>0
     des<-svydesign(id=~1,data=df)
     newdf<-data.frame(group=c(FALSE,TRUE), x=c(0,0))

     ## Cox model
     m0<-svycoxph(Surv(time,status)~group,design=des)
     m1<-svycoxph(Surv(time,status)~group+x,design=des)
     ## conditional predictions, unadjusted and adjusted
     cpred0<-predict(m0, type="curve", newdata=newdf, se=TRUE)
     cpred1<-predict(m1, type="curve", newdata=newdf, se=TRUE)
     ## adjusted marginal prediction
     mpred<-marginpred(m0, adjustfor=~x, predictat=newdf, se=TRUE)

     plot(cpred0)
     lines(cpred1[[1]],col="red")
     lines(cpred1[[2]],col="red")
     lines(mpred[[1]],col="blue")
     lines(mpred[[2]],col="blue")

     ## Kaplan--Meier
     s2<-svykm(Surv(time,status>0)~group, design=des)
     p2<-marginpred(s2, adjustfor=~x, predictat=newdf,se=TRUE)
     plot(s2)
     lines(p2[[1]],col="green")
     lines(p2[[2]],col="green")

     ## logistic regression
     logisticm <- svyglm(group~time, family=quasibinomial, design=des)
     newdf$time<-c(0.1,0.8)
     logisticpred <- marginpred(logisticm, adjustfor=~x, predictat=newdf)

