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

peter dalgaard pdalgd at gmail.com
Tue Sep 21 15:58:40 CEST 2010


On Sep 21, 2010, at 15:43 , Ben Bolker wrote:

> 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.

I'd do the per-gender mean first, then the mixture mean by weighting according to gender proportions (possibly equal to those of the data). That would be (a) answering the question as posed and (b) based on a correct model. 

-pd

(BTW, it is *very* tempting to cite Simon Blomberg's tagline with a Subject header like that...)  

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list