coldeyes.Rhelp
2007-Oct-15 03:10 UTC
[R] some question about partial prediction in survival
Hi there: i got a problem to get the prediction from a model recently. for example if i use a survival analysis to predict the risk. i use the code like below: i found the the prediction is not equal to (coef * x + coef * sex) , could someone help me with why this happened? and can someone explain to me how this command "predict(f, type="terms")" works? is every partial prediction equal to coef*x=predict(f,type="terms")[,1] and coef*sex=predict(f,type="terms")[,2]? it looks like they did not match. however "predict(f)=predict(f,type="terms")[,1]+predict(f,type="terms")[,2]" how should i understand this. thanks so much for your help test1 <- list(time= c(4, 1,1,2,2,3), status=c(1,1,0,1,1,0), x= c(0,1,1,1,0,0), sex= c(0,0,0,1,1,1)) f<-coxph( Surv(time, status) ~ x + sex, test1) Call: coxph(formula = Surv(time, status) ~ x + sex, data = test1) coef exp(coef) se(coef) z p x 1.713 5.546 1.34 1.282 0.20 sex -0.154 0.857 1.45 -0.106 0.92 Likelihood ratio test=1.85 on 2 df, p=0.397 n= 6 bests; T.D
Thomas Lumley
2007-Oct-15 15:09 UTC
[R] some question about partial prediction in survival
On Sun, 14 Oct 2007, coldeyes.Rhelp wrote:> Hi there: > i got a problem to get the prediction from a model recently. for > example if i use a survival analysis to predict the risk. i use the code > like below: i found the the prediction is not equal to (coef * x + coef > * sex) , could someone help me with why this happened?The intercept is not identifiable in a Cox model, and the code takes advantage of this to center the variables. The predicted values are the values you expected, minus the mean. For the example in ?predict.coxph R> fit<-coxph(Surv(time,status)~x,data=aml) R> predict(fit) 1 2 3 4 5 6 7 -0.4776692 -0.4776692 -0.4776692 -0.4776692 -0.4776692 -0.4776692 -0.4776692 8 9 10 11 12 13 14 -0.4776692 -0.4776692 -0.4776692 -0.4776692 0.4378634 0.4378634 0.4378634 15 16 17 18 19 20 21 0.4378634 0.4378634 0.4378634 0.4378634 0.4378634 0.4378634 0.4378634 22 23 0.4378634 0.4378634 R> sum(predict(fit)) [1] 7.21645e-16 R> a<-coef(fit)*(aml$x=="Nonmaintained") R> a-mean(a) [1] -0.4776692 -0.4776692 -0.4776692 -0.4776692 -0.4776692 -0.4776692 [7] -0.4776692 -0.4776692 -0.4776692 -0.4776692 -0.4776692 0.4378634 [13] 0.4378634 0.4378634 0.4378634 0.4378634 0.4378634 0.4378634 [19] 0.4378634 0.4378634 0.4378634 0.4378634 0.4378634> and can someone > explain to me how this command "predict(f, type="terms")" works? is > every partial prediction equal to coef*x=predict(f,type="terms")[,1] and > coef*sex=predict(f,type="terms")[,2]? it looks like they did not match. > however > "predict(f)=predict(f,type="terms")[,1]+predict(f,type="terms")[,2]"The same thing happens here. Each column of predict(,type="terms") sums to zero. In this case it is the same behaviour as lm() and glm(). -thomas