mark.fisher123
2010-Sep-21 12:09 UTC
[R] Survival curve mean adjusted for covariate: NEED TO DO IN NEXT 2 HOURS, PLEASE HELP
Hi I am trying to determine the mean of a Weibull function that has been fit to a data set, adjusted for a categorical covariate , gender (0=male,1=female). Here is my code: 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) mean 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. Help ASAP would be much appreciated! Thanks! Mark -- View this message in context: http://r.789695.n4.nabble.com/Survival-curve-mean-adjusted-for-covariate-NEED-TO-DO-IN-NEXT-2-HOURS-PLEASE-HELP-tp2548484p2548484.html Sent from the R help mailing list archive at Nabble.com.
Ben Bolker
2010-Sep-21 13:43 UTC
[R] Survival curve mean adjusted for covariate: NEED TO DO IN NEXT 2 HOURS, PLEASE HELP
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.
mark.fisher123
2010-Sep-21 15:20 UTC
[R] Survival curve mean adjusted for covariate: NEED TO DO IN NEXT 2 HOURS, PLEASE HELP
Thanks for the help everyone - problem solved in time! -- View this message in context: http://r.789695.n4.nabble.com/Survival-curve-mean-adjusted-for-covariate-NEED-TO-DO-IN-NEXT-2-HOURS-PLEASE-HELP-tp2548484p2548854.html Sent from the R help mailing list archive at Nabble.com.