[R] Regression models w/ splines
John Fieberg
John.Fieberg at dnr.state.mn.us
Fri Apr 9 22:16:34 CEST 2004
Hi - I am fitting various Cox PH models with spline predictors. After
fitting the model, I would like to use termplot() to examine the
functional form of the fitted model (e.g., to obtain a plot of the
relative risk (or log r.r.) versus the predictors).
When there is only 1 predictor in the model, termplot returns a "?".
In this case, I have not been able to figure out how to create the
desired plot. Otherwise,termplot is easy to use.
Example:
library(survival)
library(splines)
data(pbc)
fit1<-coxph(Surv(time,status)~ns(bili,4)+ns(age,4), data=pbc)
fit2<-coxph(Surv(time,status)~ns(bili,4), data=pbc)
par(mfrow=c(2,2))
termplot(fit1) # returns two plots (one for bili and one for age)
termplot(fit2) # returns a "?" prompt
Does anyone have any suggestions for obtaining a plot of the log
relative risk as a function of bili in the second example (or for this
type of model in general)?
On a similar note, I would like to be able to obtain predicted values
for "new" subjects. I tried using:
temp<-data.frame(bili=0.8)
predict(fit2,newdata=temp, safe=T)
This gives the following error message:
Error in qr(t(const)) : NA/NaN/Inf in foreign function call (arg 1)
Is there a simple method available for obtaining predicted values for
new subjects when using these types of models?
I have encountered similar problems when trying to use smoothing
splines w/ the above examples (i.e., 'pspline' in the survival package).
I am currently using R version 1.8.1 for windows. Any help would be
greatly appreciated!
John
John Fieberg, Ph.D.
Wildlife Biometrician, MN DNR
5463-C W. Broadway
Forest Lake, MN 55434
Phone: (651) 296-2704
More information about the R-help
mailing list