I want to select a Cox model with the forward procedure from a data.frame with no NA. Here is some sample data:
test <- data.frame(
x_1 = runif(100,0,1),
x_2 = runif(100,0,5),
x_3 = runif(100,10,20),
time = runif(100,50,200),
event = c(rep(0,70),rep(1,30))
)
This table has no signification but if we try to build a model anyway :
modeltest <- coxph(Surv(time, event) ~1, test)
modeltest.forward <- step(
modeltest,
data = test,
direction = "forward",
scope = list(lower = ~ 1, upper = ~ x_1 + x_2 + x_3)
)
The forward ends at the first step and says:
In is.na(fit$coefficients) : is.na() applied to non-(list or vector) of type 'NULL'
(three times)
I tried to change the upper model, I even tried upper = ~ 1
but the warning stays. I don't understand: I have no NAs and my vectors are all numerics (I checked it).
I searched if people had the same issue but all I could find was problems due to the name or class of the vectors.
What's wrong with my code?
step
function verifies if the models are ok (no NA in the estimations), it can't find any estimation for the null model which causes the error/warnings. Thus, the warning is ignorable without jeopardizing the outcome quality. If you get an error, maybe try to install a more recent version of R ? – Weimerdredge
function applied to acoxph
model with several covariates. Do you conclude that this could be a bug? (A few days ago it worked just fine) – Metacenterstep
(and i'm assumingdredge
too) can't deal with a model that have no coefficient. Does the error remain if you set m.min=1 ? – Weimer