[R] Error: system is computationally singular: reciprocal condition number

Ravi Varadhan rvaradhan at jhmi.edu
Sun Jun 28 16:30:36 CEST 2009


It is a basic linear algebra issue and has nothing to do with statistics

I told you what your problem is and also how to solve it.  

Ravi.

____________________________________________________________________

Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology
School of Medicine
Johns Hopkins University

Ph. (410) 502-2619
email: rvaradhan at jhmi.edu


----- Original Message -----
From: Moumita Das <das.moumita.online at gmail.com>
Date: Sunday, June 28, 2009 10:01 am
Subject: Re: [R] Error: system is computationally singular: reciprocal condition number
To: r-help at r-project.org


> I get this error .... on using the, traceback() function :--
>  > traceback()
>  10: .Call("La_dgesv", a, b, tol, PACKAGE = "base")
>  9: solve.default(Szz)
>  8: solve(Szz)
>  7: pcor.mat(firstvalue, secondvalue, third_var, method, na.rm = T)
>  6: PartialCorr_Calculation(value1, value2, third_var, method = "pearson",
>         na.rm = T)
>  5: Partial(contrld_third_var(rowvalues$matrix1, rowvalues$matrix2,
>         x <- stringOfItemCategoryToDataFrameOfItemCategory,
>  item_category_table,
>         pcor_type <- "ic"), data1, data2, pcor_thirdvar_type <- "all")
>  4: main()
>  3: eval.with.vis(expr, envir, enclos)
>  2: eval.with.vis(ei, envir)
>  1: source("correlationFP.R")
>  
>  what is this error ".*Call("La_dgesv", a, b, tol, PACKAGE = "base")*" 
>  how
>  can i rectify it?
>  I don't know statistics...going mad ,debugging this problem..
>  any help is highly appreciated !! :)
>  
>  Thanks in advance
>  Moumita
>  
>  On Thu, Jun 25, 2009 at 8:29 PM, Moumita Das
>  <das.moumita.online at gmail.com>wrote:
>  
>  >
>  > I get this error while computing partial correlation.
>  >
>  >
>  > *Error in solve.default(Szz) :
>  >   system is computationally singular: reciprocal condition number =
>  > 4.90109e-18*
>  >
>  > Why is it?Can anyone give me some idea ,how do i get rid it it?
>  >
>  > This is the function i use for calculating partial correlation.
>  >
>  >
>  > pcor.mat <- function(x,y,z,method="p",na.rm=T){
>  >
>  >
>  >     x <- c(x)
>  >     y <- c(y)
>  >     z <- as.data.frame(z)
>  >
>  >
>  >
>  >     if(dim(z)[2] == 0){
>  >         stop("There should be given data\n")
>  >     }
>  >
>  >     data <- data.frame(x,y,z)
>  >
>  >     if(na.rm == T){
>  >         data = na.omit(data)
>  >     }
>  >
>  >     xdata <- na.omit(data.frame(data[,c(1,2)]))
>  >     Sxx <- cov(xdata,xdata,m=method)
>  >
>  >     xzdata <- na.omit(data)
>  >     xdata <- data.frame(xzdata[,c(1,2)])
>  >     zdata <- data.frame(xzdata[,-c(1,2)])
>  >     Sxz <- cov(xdata,zdata,m=method)
>  >
>  >     zdata <- na.omit(data.frame(data[,-c(1,2)]))
>  >     Szz <- cov(zdata,zdata,m=method)
>  >
>  >
>  >     # is Szz positive definite?
>  >     zz.ev <- eigen(Szz)$values
>  >     if(min(zz.ev)[1]<0){
>  >
>  >         stop("\'Szz\' is not positive definite!\n")
>  >     }
>  >
>  >     # partial correlation
>  >     Sxx.z <- Sxx - Sxz %*% solve(Szz) %*% t(Sxz)
>  >
>  >     print(Sxx.z) # this gets printed
>  >
>  >     rxx.z <- cov2cor(Sxx.z)[1,2] #some problem in this function
>  > function (V)
>  >     {
>  >        print("cov2cor")
>  >        p <- (d <- dim(V))[1]
>  >         if (!is.numeric(V) || length(d) != 2L || p != d[2L])
>  >             stop("'V' is not a square numeric matrix")
>  >         Is <- sqrt(1/diag(V))
>  >         if (any(!is.finite(Is)))
>  >             warning("diag(.) had 0 or NA entries; non-finite result 
> is
>  > doubtful")
>  >         r <- V
>  >         r[] <- Is * V * rep(Is, each = p)
>  >         r[cbind(1L:p, 1L:p)] <- 1
>  >         r
>  >     }
>  >     return(rxx.z)
>  > }
>  >
>  > --
>  > Thanks
>  > Moumita
>  >
>  
>  
>  
>  -- 
>  Thanks
>  Moumita
>  
>  	[[alternative HTML version deleted]]
>  
>  ______________________________________________
>  R-help at r-project.org mailing list
>  
>  PLEASE do read the posting guide 
>  and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list