Dear R-help, I'm very sorry to ask 2 questions in a week. I am using the package 'crr' and it does exactly what I need it to when I use the dataset a. However, when I use dataset b I get the following error message: Error in drop(.Call("La_dgesv", a, as.matrix(b), tol, PACKAGE = "base")) : system is computationally singular: reciprocal condition number = 1.28654e-24 This is obviously as a result of a problem with the data but apart from dataset a having 1674 rows and dataset b having 701 rows there is really no difference between them. The code I am using is as follows where covaea and covaeb are matrices of covarites, all coded as binary variables. In case a:> covaea <- cbind(sexa,fsha,fdra,nsigna,eega,th1a,th2a,stype1a,stype2a,stype3a,pgu1a,pgu2a,log(agea),firstinta/1000,totsezbasea) > fita <- crr(snearma$with.Withtime,csaea,covaea,failcode=2,cencode=0)and in case b:> covaeb <- cbind(sexb,fshb,fdrb,nsignb,eegb,th1b,th2b,stype1b,stype2b,stype3b,stype4b,stype5b,pgu1b,pgu2b,(ageb/10)^(-1),firstintb,log(totsezbaseb)) > fitb <- crr(snearmb$with.Withtime,csaeb,covaeb,failcode=2,cencode=0)csaea and csaeb are the censoring indicators for a and b respectively which equal 1 for the event of interest, 2 for the competing risks event and 0 otherwise. Can anyone suggest a reason for the error message? I've tried running fitb with variants of covaeb and irrespective of the order of the covariates in the matrix, the code runs fine with 16 of the 17 covariates included but then produces an error message when the 17th is added. Thank you for your help, Laura
This means that your design matrix or model matrix is rank deficient, i.e it does not have linearly independent columns. Your predictors are collinear! Just take your design matrices "covaea" or "covaeb" with 17 predcitors and compute their rank or try to invert them. You will see the problem. Ravi. ---------------------------------------------------------------------------- ------- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: rvaradhan at jhmi.edu Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h tml ---------------------------------------------------------------------------- -------- -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Laura Bonnett Sent: Thursday, June 25, 2009 11:39 AM To: r-help at r-project.org Subject: [R] crr - computationally singular Dear R-help, I'm very sorry to ask 2 questions in a week. I am using the package 'crr' and it does exactly what I need it to when I use the dataset a. However, when I use dataset b I get the following error message: Error in drop(.Call("La_dgesv", a, as.matrix(b), tol, PACKAGE = "base")) : system is computationally singular: reciprocal condition number 1.28654e-24 This is obviously as a result of a problem with the data but apart from dataset a having 1674 rows and dataset b having 701 rows there is really no difference between them. The code I am using is as follows where covaea and covaeb are matrices of covarites, all coded as binary variables. In case a:> covaea <- > cbind(sexa,fsha,fdra,nsigna,eega,th1a,th2a,stype1a,stype2a,stype3a,pgu > 1a,pgu2a,log(agea),firstinta/1000,totsezbasea) > fita <- crr(snearma$with.Withtime,csaea,covaea,failcode=2,cencode=0)and in case b:> covaeb <- > cbind(sexb,fshb,fdrb,nsignb,eegb,th1b,th2b,stype1b,stype2b,stype3b,sty > pe4b,stype5b,pgu1b,pgu2b,(ageb/10)^(-1),firstintb,log(totsezbaseb)) > fitb <- crr(snearmb$with.Withtime,csaeb,covaeb,failcode=2,cencode=0)csaea and csaeb are the censoring indicators for a and b respectively which equal 1 for the event of interest, 2 for the competing risks event and 0 otherwise. Can anyone suggest a reason for the error message? I've tried running fitb with variants of covaeb and irrespective of the order of the covariates in the matrix, the code runs fine with 16 of the 17 covariates included but then produces an error message when the 17th is added. Thank you for your help, Laura ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
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.