[R] Survival curve mean adjusted for covariate: NEED TO DO IN NEXT 2 HOURS, PLEASE HELP

Ben Bolker bbolker at gmail.com
Tue Sep 21 15:43:55 CEST 2010


mark.fisher123 <marko.fisher2008 <at> gmail.com> writes:

[snip]
> library(survival) 
> survdata<-read.csv("data.csv") 
> 
> ##Fit Weibull model to data 
> 
> WeiModel<-survreg(Surv(survdata$Time,survdata$Status)~survdata$gender) 
> summary(WeiModel) 
> 
> P<-pweibull(n, scale=exp(WeiModel$coef[1]), shape=1/WeiModel$scale) 
> 
> ##Return mean 
> 
> scale<-exp(WeiModel$coef[1]) 
> shape<-1/WeiModel$scale 
> 
> mean <- scale*gamma(1+1/shape) 
> The problem is that the mean is based on the baseline coefficient which
> assumes the population is male (= 0). I want an adjusted mean which isnt
> assuming the whole population is male, or female - so the baseline
> coefficient is completely adjusted for gender. 

  Well, you will get different answers depending on the sex ratio of
the population.  If you want to predict based on the existing population,
then just go ahead and fit the model without including gender as
a covariate (~1 rather than ~gender).  The other possibility would
be to use coef(WeiModel)[1]+coef(WeiModel)[2]/2 as the (log-scale)
scale parameter, but I'm not sure that would be correct.



More information about the R-help mailing list