hossiet
2010-Oct-07 20:16 UTC
[R] Categorical variables and Plotting a Cox model with interaction terms
I'm a new to the R world and I have been following the John Fox Appendix on Cox regression (http://cran.r-project.org/doc/contrib/Fox-Companion/appendix-cox-regression.pdf) to run some analyses. I have been able to generate models and some simple figures e.g.:>library(splines) #required for survival package >library(survival) #req for Coxph >Field1<-read.csv("c:/R/Field1.csv") >attach(Field1) >mod.Field1 <- coxph(Surv(Survival, Censored) ~ Colour * Size + Site,data=Field1)>mod.Field1Colour and Size are binary (dummy) variables (i.e., 0 and 1) and Site is a location (i.e., 1, 2, 3). Question 1: my site variable is technically a categorical (i.e., not ranked), random factor but how do I (or can I?)define this? Fox shows this method for plotting out seperate curves for a single factor:> mod.allison <- coxph(Surv(week, arrest) ~ fin + age + race + wexp + mar + > paro + prio,+ data=Rossi)> attach(Rossi) > Rossi.fin <- data.frame(fin=c(0,1), age=rep(mean(age),2), > race=rep(mean(race),2),+ wexp=rep(mean(wexp),2), mar=rep(mean(mar),2), paro=rep(mean(paro),2), + prio=rep(mean(prio),2))> detach() > plot(survfit(mod.allison, newdata=Rossi.fin), conf.int=T,+ lty=c(1,2), ylim=c(.6, 1))> legend(locator(1), legend=c(?fin = 0?, ?fin = 1?), lty=c(1,2))In this example the terms in the model were all main effects. Question 2: How would you define the variable Rossi.fin if say there was a paro*prio interaction term? Basically, I want to generate a survival plot with 2 lines (e.g. 0=small, 1=big) using my model, but I can't figure out how to define the code becasue my model has interaction terms. Any help with this would be greatly apreciated. Sincerely, hossiet -- View this message in context: http://r.789695.n4.nabble.com/Categorical-variables-and-Plotting-a-Cox-model-with-interaction-terms-tp2967483p2967483.html Sent from the R help mailing list archive at Nabble.com.
Reasonably Related Threads
- Modelling survival with time-dependent covariates
- How to specify "newdata" in a Cox-Modell with a time dependent interaction term?
- p-value for hazard ratio in Cox proportional hazards regression?
- Elegir más de un dato en data frame
- has_one problem in a form