Re: [R] plotting spline term when frailty term is included
On 03/02/2016 05:00 AM, r-help-requ...@r-project.org wrote: I'd very much appreciate your help in resolving a problem that I'm having with plotting a spline term. I have a Cox PH model including a smoothing spline and a frailty term as follows: fit<-coxph(Surv(start,end,exit) ~ x + pspline(z) + frailty(a)) When I run a model without a frailty term, I use the following in order to plot the splines: termplot(fit, term = 2, se = TRUE, ylab = "Log Hazard", rug=TRUE, xlab = "z_name") However, when the frailty term is included, it gives this error: Error in pred[, first] : subscript out of bounds What am I doing wrong here? Or is it the case that termplot does not work when splines and frailty are included? There are 3 parts to the answer. 1. The first is a warning: wrt to mixed effects Cox models, I shifted my energy to coxme over 10 years ago. The "penalized add on to coxph" approach of the frailty function was an ok first pass, but is just too limited for any but the simplest models. I'm unlikely fix issues, since there are others much higher on my priority list. 2. As Dave W. pointed out, the key issue is that predict(type='terms') does not work with for a model with two penalized terms, when one is frailty and the other pspline. Termplot depends on predict. 3. Again, as Dave W pointed out, the whole issue of what the "correct" answer would be gets much more complicated when one adds random effects to the mix; some things have not done because it is not clear where to go. (Survival curves for a mixed effects model only recently got added to my "todo" list, even though it has been on the wish list forever, because I finally have a notion of what a good approach would be.) In your case I'd advise an end run: fit the model using ns() instead of pspline. I like smoothing splines better than regression splines, but the fact is that for most data sets they result in nearly identical answers. Terry T __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] plotting spline term when frailty term is included
> On Mar 1, 2016, at 2:59 AM, Conor Edward Littlewrote: > > Dear colleagues, > > I'd very much appreciate your help in resolving a problem that I'm having > with plotting a spline term. > > I have a Cox PH model including a smoothing spline and a frailty term as > follows: > > fit<-coxph(Surv(start,end,exit) ~ x + pspline(z) + frailty(a)) > > When I run a model without a frailty term, I use the following in order to > plot the splines: > > termplot(fit, term = 2, se = TRUE, ylab = "Log Hazard", rug=TRUE, xlab = > "z_name") > > However, when the frailty term is included, it gives this error: > > Error in pred[, first] : subscript out of bounds I think this is due to the inability of `predict` to cope with the frailty model when type="terms". Using the example on the ?frailty page as teh basis for a reproducible example: > predict(coxph(Surv(time, status) ~ age + frailty(inst, df=4), lung), > type="terms") Error in predict.coxph.penal(coxph(Surv(time, status) ~ age + frailty(inst, : length of 'dimnames' [2] not equal to array extent > > What am I doing wrong here? Or is it the case that termplot does not work > when splines and frailty are included? > > A similar question was asked a number of years ago - as far as I can see it > didn't receive an answer (online, at least). > http://r.789695.n4.nabble.com/a-question-in-coxph-td908035.html The `?termplot` help-page says that there must be a `predict` method for the object that accepts a "terms"- argument. Therneau advises the use of the 'coxme'-package for mixed effects survival modeling and the `predict.coxme` function does not have a "terms" argument. Prediction with frailty: I think that the issue of prediction with frailty models may be more complex than you understand. My level of understanding is inadequate as well, so I tried searching for earlier answers. If Thomas Lumley says it is "hard" then I take him at my word. Appears you would need to do calculation separately for each value of the frailty "term" if you stay with the coxph/frailty environment. Therneau has written: "Residuals methods for coxme would be an important addition and is on my to-do list. (But as my wife would pointout, so is a bathroom remodel and she isn't holding her breath.)". So it appears that the problem is more than just a simple two line bit of code. Lumley's approach from 10+ years ago: http://markmail.org/search/?q=list%3Aorg.r-project.r-help+coxph+frailty+prediction+#query:list%3Aorg.r-project.r-help%20coxph%20frailty%20prediction%20+page:1+mid:qy7nxom3uknj2oop+state:results http://markmail.org/search/?q=list%3Aorg.r-project.r-help+coxph+frailty+prediction+#query:list%3Aorg.r-project.r-help%20coxph%20frailty%20prediction%20+page:1+mid:nbcdjwfs3jhqjsji+state:results > > Best, > Conor Little > > > > Conor Little > Postdoctoral Researcher > Department of Political Science, University of Copenhagen > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. David Winsemius Alameda, CA, USA __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] plotting spline term when frailty term is included
Dear colleagues, I'd very much appreciate your help in resolving a problem that I'm having with plotting a spline term. I have a Cox PH model including a smoothing spline and a frailty term as follows: fit<-coxph(Surv(start,end,exit) ~ x + pspline(z) + frailty(a)) When I run a model without a frailty term, I use the following in order to plot the splines: termplot(fit, term = 2, se = TRUE, ylab = "Log Hazard", rug=TRUE, xlab = "z_name") However, when the frailty term is included, it gives this error: Error in pred[, first] : subscript out of bounds What am I doing wrong here? Or is it the case that termplot does not work when splines and frailty are included? A similar question was asked a number of years ago - as far as I can see it didn't receive an answer (online, at least). http://r.789695.n4.nabble.com/a-question-in-coxph-td908035.html Best, Conor Little Conor Little Postdoctoral Researcher Department of Political Science, University of Copenhagen [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.