[R] crr - computationally singular
mgordon
dr.max.gordon at gmail.com
Fri Jul 15 12:54:16 CEST 2011
Hi!
I guess that you have solved this error by now but I figured I'd post the
result of my 12 hour debugging session in case anyone else has the same
issue. Lets start with a more intuitive example that the one crr offers:
# CODE START #
# Define a set size
my_set_size <- 1000
# Create the covariables
cov <- cbind(rbinom(my_set_size, 1, .5),
rbinom(my_set_size, 1, .05),
rbinom(my_set_size, 1, .1))
dimnames(cov)[[2]] <- c('gender','risk factor 1','risk factor 2')
# Create random time to failure/cens periods
ftime <- rexp(my_set_size)
# Create events
my_event1 <- rbinom(my_set_size, 1, .04)
my_event2 <- rbinom(my_set_size, 1, .20)
# The competing event can't happen if 1 has already occurred
my_event2[my_event1 > 0] <- 0
fstatus <- my_event1 + my_event2*2
# Factor the censor variable
fstatus <- factor(fstatus, levels=c(0,1,2), labels=c("censored",
"re-operation", "death"))
# Check that it seems Ok
table(fstatus)
# Do the test
test_results <- crr(ftime, fstatus, cov, failcode="re-operation",
cencode="censored")
# Output the results
summary(test_results)
# CODE END #
Ok, so the error occurs in the .Fortran call to "crrval" (I think it was
called) that returns an empty variable if you forget to specify the factor
failcode, in other words exchange above crr to:
test_results <- crr(ftime, fstatus, cov, failcode=1, cencode="censored")
And you get the:
Error in solve.default(v[[1]]) :
Lapack routine dgesv: system is exactly singular
Another way to get a singular error is to have a covariate that is 0. Try to
exchange to this code for the covariates:
cov <- cbind(rbinom(my_set_size, 1, .5),
rbinom(my_set_size, 1, .05),
rbinom(my_set_size, 1, .1)*0)
And you get:
Error in drop(.Call("La_dgesv", a, as.matrix(b), tol, PACKAGE = "base")) :
Lapack routine dgesv: system is exactly singular
This code has been checked with 2.13.1 and cmprsk ver. 2.2.2
I'm not so familiar with R but I believe that this is actually a bug in the
cmprsk package which should check for the variables being factors and then
handle them as expected. I've noticed similar issues with cuminc function
that doesn't behave as expected when providing factored censoring variables.
I haven't seen any issues with factoring the covariates although I've used
http://www.stat.unipg.it/~luca/R/crr-addson.R Scruccas factor2ind function
when I've had non-binomial factors.
I hope someone out there will be able to avoid my 12 hours of debugging with
this post.
Max Gordon
--
View this message in context: http://r.789695.n4.nabble.com/crr-computationally-singular-tp891659p3669639.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list