Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

predict.coxph.penal ignores newdata when the model has only a sparse term #71

Open
camdenlo opened this issue May 15, 2019 · 2 comments

Comments

@camdenlo
Copy link

camdenlo commented May 15, 2019

This is closely related to #70 and also probably has minimal impact.

In predict.coxph.penal, when there is only a sparse /penalty term in the model, the newdata argument (if supplied) gets ignored in calculating the predictions (except for the assignment line 45, which gets overwritten).

if (nvar==1) {
# Only the sparse term!
if (!missing(newdata)) {
n <- nrow(as.data.frame(newdata))
pred <- rep(0,n)
}
se <- sqrt(object$fvar[indx])
pred <- object$linear.predictor
if (type=='risk') pred <- exp(pred)
if (type=='expected') {
pred <- object$y[,ncol(object$y)] -object$residuals
se.fit=FALSE
}
}

Currently, if newdata has been supplied, an error stops execution at line 47 unless "indx" has been defined outside the function (issue #70), but when that is fixed, the resulting predictions ignore newdata.

@camdenlo camdenlo changed the title predict.coxph.penal ignores newdata when the model has only a penalty term predict.coxph.penal ignores newdata when the model has only a sparse term May 17, 2019
@therneau
Copy link
Owner

therneau commented Jul 1, 2019

What do you want the prediction to be from a frailty model with new data?
I'm not trying to be difficult -- I have struggled with this question myself. Say the model has frailty(inst) to have a random effect per institution. If the new data contains a new institution -- give NA or the mean of the random effects distribution? Can I count on random effects having a consistent label?

@camdenlo
Copy link
Author

camdenlo commented Jul 1, 2019

I was thinking that the behavior would be the same as when there are fixed covariates in addition to the frailty term — that the predictions would be for a random effect of zero. In the case of a model with only a frailty term, the only part of newdata that would matter for predictions (and only if type="expected") would be the follow-up time. Rows of newdata that differed only in the value of the frailty term would get the same prediction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants