diff --git a/R/SQUIC.R b/R/SQUIC.R index c7389351be6f805633aa9fd4dc38d16d6c20d2ae..461578d8b38cd2c809b1cc60f008fde5656d4d6b 100644 --- a/R/SQUIC.R +++ b/R/SQUIC.R @@ -18,7 +18,7 @@ usethis::use_package("Matrix") # Main function -SQUIC <- function(Y, lambda, max_iter=100, tol=1e-4,tol_inv=1e-3,verbose=1, M=NULL, X0=NULL, W0=NULL) { +SQUIC <- function(Y, lambda, max_iter=100, tol=1e-3,tol_inv=1e-4,verbose=1, M=NULL, X0=NULL, W0=NULL) { verbose <- min(verbose,1) @@ -45,7 +45,6 @@ SQUIC <- function(Y, lambda, max_iter=100, tol=1e-4,tol_inv=1e-3,verbose=1, M=NU stop('#SQUIC: tol_inv must be great than zero.') } - if(is.null(M)){ # Make empty sparse matrix of type dgCMatrix. M <- as(Matrix::sparseMatrix(dims = c(p,p), i={}, j={}),"dgCMatrix") diff --git a/README.md b/README.md index afd42ec2307667030e8f375fc60d99550af354af..14be4e1a36ecfd65faa747f2af615bc63840012a 100644 --- a/README.md +++ b/README.md @@ -22,22 +22,23 @@ _Note: The environment variable ``SQUIC_LIB_PATH`` defines the location of ``lib In this example, we will use SQUIC to estimate the precision matrix of a synthetically generated dataset with correlated random variables, where the true precision matrix is tridiagonal. ```angular2 -library(SQUIC) +library(SQUIC) p <- 1024 n <- 100 lambda <- .4 # generate a tridiagonal matrix -iC_star <- Matrix::bandSparse(p,p,(-1):1,list(rep(-.5, p-1),rep(1.25,p), rep(-.5,p-1))) +iC_star <- Matrix::bandSparse(p, p, (-1):1, list(rep(-.5, p-1), rep(1.25, p), rep(-.5, p-1))) # generate the data +set.seed(1) z <- replicate(n,rnorm(p)) iC_L <- chol(iC_star) -data <- matrix(solve(iC_L,z),p,n) +Y <- matrix(solve(iC_L,z),p,n) -# Run SQUIC -out <- SQUIC(data,lambda) +# run SQUIC +out <- SQUIC(Y,lambda) ``` For further details type ``help(SQUIC)``. diff --git a/man/SQUIC.Rd b/man/SQUIC.Rd index 0433d2491533a699cadbc4863dba1968af4940a5..7962f05a20659acf5051c17a3cd7d64642ba6961 100644 --- a/man/SQUIC.Rd +++ b/man/SQUIC.Rd @@ -11,7 +11,7 @@ large-scale sparse precision matrix estimation. } \usage{ - SQUIC(Y,lambda,max_iter=100,tol=1e-4,tol_inv=1e-3,verbose=1,M=NULL,X0=NULL,W0=NULL) + SQUIC(Y,lambda,max_iter=100,tol=1e-3,tol_inv=1e-4,verbose=1,M=NULL,X0=NULL,W0=NULL) } \arguments{ @@ -81,18 +81,19 @@ library(SQUIC) p <- 1024 n <- 100 -lambda <- 0.4 +lambda <- .4 # generate a tridiagonal matrix -iC_star <- Matrix::bandSparse(p,p,(-1):1,list(rep(-.5,p-1),rep(1.25,p),rep(-.5,p-1))) +iC_star <- Matrix::bandSparse(p, p, (-1):1, list(rep(-.5, p-1), rep(1.25, p), rep(-.5, p-1))) # generate the data -z <- replicate(n,rnorm(p)); -iC_L <- chol(iC_star); -data <- matrix(solve(iC_L,z),p,n); +set.seed(1) +z <- replicate(n,rnorm(p)) +iC_L <- chol(iC_star) +Y <- matrix(solve(iC_L,z),p,n) -# Run SQUIC -out <- SQUIC(data,lambda) +# run SQUIC +out <- SQUIC(Y,lambda) } \keyword{sparse precision matrix estimation}