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

cph fails with rhs in the form of factor(x) #31

Closed
tonigi opened this issue Sep 14, 2016 · 1 comment
Closed

cph fails with rhs in the form of factor(x) #31

tonigi opened this issue Sep 14, 2016 · 1 comment

Comments

@tonigi
Copy link

tonigi commented Sep 14, 2016

Using a formula like "surv ~ factor(x)" produces the error X[, mmcolnames, drop = FALSE] : subscript out of bounds.

set.seed(10)
n <- 500
ds <- data.frame(
  ftime = rexp(n),
  fstatus = sample(0:1, size = n, replace = TRUE),
  x = sample(LETTERS[1:4], size = n, replace = TRUE) )

library(rms)
dd <<- datadist(ds)
options(datadist="dd")

fit <- cph(Surv(ftime, fstatus) ~ factor(x), data=ds)

Passing an already-factored x works as expected. Not sure if this is the intended behavior, and/or the error message may be made more explicit. The debug argument clarified the problem.

> fit <- cph(Surv(ftime, fstatus == 1) ~ factor(x), data=ds,debug=T)

sformula

Surv(ftime, fstatus == 1) ~ factor(x)
     colnames(X)  mmcolnames Design colnames
[1,] "factor(x)B" "xB"       "x=B"          
[2,] "factor(x)C" "xC"       "x=C"          
[3,] "factor(x)D" "xD"       "x=D"          
Error in X[, mmcolnames, drop = FALSE] : subscript out of bounds

This may be analogous to #15 .

Thanks!

@harrelfe
Copy link
Owner

As described in issue 29, factor() was never supposed to work with rms. It only worked in the past by accident. Now it always fails. Make the variable a factor when constructing the dataset or use the scored() function in the model formula if the variable is ordered and might possibly have a linear effect.

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