[R] coxphw with categorical explanatory variables
Simon Gingins
simon.gingins at unine.ch
Wed Feb 18 10:42:31 CET 2015
Dear R helpers,
I am currently trying to analyze data with a cox proportional hazard survival analysis. For one of my datasets, the proportional hazards assumption is violated. Reading the literature, it seems that the weighted version of cox PH (function coxphw() ) is a good alternative in case of non proportional hazards. However, the function coxphw() does not seem to take categorical explanatory variables and I cannot figure out the reason why. Is there a statistical reason for that? Could you help me please?
In a few words, my data represents 6 species of fishes (~16 individuals per species) tested for their reaction towards novel objects. The response variable is the time to approach the novel object (the experiments was stopped after 5 minutes, so the data is right censored) ad the explanatory variable is species identity. When I run a coxph() model in R, it works with no problems (model1 below). If I run the same model but with the coxphw() function instead of the coxph() it gives me an error message (model2 below). If I coerce the explanatory variable into a numeric format, it also works (model3 below). However, I am not sure this last approach is appropriate, as I guess there must be a reason why coxphw() cannot deal with my response variable in the categorical (factor) format. Can anyone explain?
> model1 <- coxph(Surv(time=O1_approach_sec, event=O1_approach) ~ species, data=personew)
> model2 <- coxphw(Surv(time=O1_approach_sec, event=O1_approach) ~ species, data=personew, AHR=T)
Erreur dans weights[, 1] : indice hors limites
> model3 <- coxphw(Surv(time=O1_approach_sec, event=O1_approach) ~ as.numeric(species), data=personew, AHR=T)
Best regards
Simon
___________________________
Simon Gingins
PhD student
University of Neuchâtel
Institute of Biology
Department of Behavioural Ecology
Rue Emile-Argand 11
2000 Neuchâtel
Switzerland
Office: +41 32 718 31 09
research: http://www2.unine.ch/ethol/gingins_simon
photos: www.simongingins.com
[[alternative HTML version deleted]]
More information about the R-help
mailing list