I am trying to fit a Cox proportional hazards model with penalized splines using the survival
R package with the following, but it seems like I am hitting a limit on the number of coefficients that can be estimated given the total number of observations in the dataset.
For example,
library(survival)
data(lung)
lung <- na.omit(lung)
lung <- data.frame(apply(lung, 2, as.numeric))
nrow(lung) # 167 rows
model <- coxph(Surv(time, status) ~ pspline(inst) + pspline(age)
+ pspline(ph.ecog) + pspline(ph.karno) + pspline(pat.karno)
+ pspline(meal.cal) + pspline(wt.loss) + sex, data=lung,
method='breslow')
This yields Error in coxpenal.fit(X, Y, istrat, offset, init = init, control, weights = weights, : NA/NaN/Inf in foreign function call (arg 5)
.
But when I double the number of observations:
lung.2x <- as.data.frame(lapply(lung, rep, 2))
nrow(lung.2x) # 334 rows
model.2x <- coxph(Surv(time, status) ~ pspline(inst) + pspline(age)
+ pspline(ph.ecog) + pspline(ph.karno) + pspline(pat.karno)
+ pspline(meal.cal) + pspline(wt.loss) + sex, data=lung.2x,
method='breslow')
This runs.
Could anyone provide some insight as to why the model won't fit on the smaller dataset? Looking at model.2x$coefficients
, I see that there are 85 coefficients estimated which is still fewer than the number of observations in the smaller dataset.
(If it helps - the default values for pspline()
are 4 degrees of freedom and degree = 3, i.e. a cubic spline.)