Pregunta

I think this should be something very easy, but I can't quite get my head around it.

I have the following code:

library(survival)
cox <- coxph(Surv(SURV, DEAD)~YEAR, data)
summary(cox)

but I would like to have the result split down into the individual years.

Here's what the SPSS syntax and solution would look like:

COXREG surv /STATUS=dead(1) /CONTRAST (year)=Indicator(1)
 /METHOD=ENTER year /PRINT=CI(95)
 /CRITERIA=PIN(.05) POUT(.10) ITERATE(20).
EXECUTE.

enter image description here

and the same thing in STATA:

xi: stcox i.year

Here's the output of

str(data)

enter image description here

¿Fue útil?

Solución

You did not show us str(data) or how to construct a reproducible example the gave "data". I suspect that "YEAR" will turn out to be a numeric vector. If it had been a factor variable you would have seen an Intercept and n-1 coefficients. The Interecpt coefficient would then have been the same as the "year" and the other coefficients would have matched up to the year(n) values. You told the SPSS engine that "year" was an "INDICATOR" but you didn't offer the same courtesy to the R engine.

Try this:

data$year.ind <- factor(data$year)  # equivalent of SPSS INDICATOR
                                    # or SAS /CLASS
cox.mdl <- coxph(Surv(SURV, DEAD)~YEAR, data)
as.matrix(coef(coc.mdl)
summary(cox.mdl)

Otros consejos

R often splits computing and display of results to allow more freedom. I assume you need the predict function of coxph (?predict.coxph).

There are examples at the bottom of the documentation page, most likely you want

predict(cox, type="terms")
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top