SCM

SCM Repository

[matrix] Diff of /pkg/R/sparseMatrix.R
ViewVC logotype

Diff of /pkg/R/sparseMatrix.R

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2095, Wed Dec 5 17:57:24 2007 UTC revision 2096, Fri Dec 7 17:44:44 2007 UTC
# Line 477  Line 477 
477                      type = type)                      type = type)
478            })            })
479    
480    setMethod("cov2cor", signature(V = "sparseMatrix"),
481              function(V) {
482                  ## like stats::cov2cor() but making sure all matrices stay sparse
483                  p <- (d <- dim(V))[1]
484                  if (p != d[2])
485                      stop("'V' is not a *square* matrix")
486                  if(!is(V, "dMatrix"))
487                      V <- as(V, "dMatrix")# actually "dsparseMatrix"
488                  Is <- sqrt(1/diag(V))
489                  if (any(!is.finite(Is))) ## original had 0 or NA
490                      warning("diag(.) had 0 or NA entries; non-finite result is doubtful")
491                  ## TODO: if  <diagonal> %*% <sparse> was implemented more efficiently
492                  ##       we'd rather use that!
493                  Is <- as(Diagonal(x = Is), "sparseMatrix")
494                  r <- Is %*% V %*% Is
495                  r[cbind(1L:p,1L:p)] <- 1 # exact in diagonal
496                  as(r, "symmetricMatrix")
497              })
498    
499    
500    
501  lm.fit.sparse <-  lm.fit.sparse <-
502  function(x, y, offset = NULL, method = c("qr", "cholesky"),  function(x, y, offset = NULL, method = c("qr", "cholesky"),

Legend:
Removed from v.2095  
changed lines
  Added in v.2096

root@r-forge.r-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business Powered By FusionForge