Skip to content

Commit

Permalink
version 1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Tibshirani authored and gaborcsardi committed Jan 8, 2009
1 parent 5331956 commit 5b3fd3c
Show file tree
Hide file tree
Showing 7 changed files with 464 additions and 235 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
@@ -1,9 +1,9 @@
Package: glasso
Title: Graphical lasso- estimation of Gaussian graphical models
Version: 1.2
Version: 1.3
Author: Jerome Friedman, Trevor Hastie and Rob Tibshirani
Description: Graphical lasso
Maintainer: Rob Tibshirani <tibs@stat.stanford.edu>
License: GPL-2
URL: http://www-stat.stanford.edu/~tibs/glasso
Packaged: Wed Jun 18 23:50:37 2008; tibs
Packaged: Thu Jan 8 07:40:34 2009; tibs
1 change: 1 addition & 0 deletions NAMESPACE
@@ -1,2 +1,3 @@
export(glasso)
export(glassopath)
useDynLib(glasso)
1 change: 0 additions & 1 deletion R/glasso.R
Expand Up @@ -35,7 +35,6 @@ if(start.type=="warm"){
ww=w.init
xx=wi.init
}


itrace=1*trace
ipen=1*(penalize.diagonal)
Expand Down
43 changes: 43 additions & 0 deletions R/glassopath.R
@@ -0,0 +1,43 @@
glassopath=function (s, rholist=NULL, thr = 1e-04, maxit = 10000, approx = FALSE
,
penalize.diagonal = TRUE, w.init = NULL,
wi.init = NULL, trace = FALSE)
{
n = nrow(s)
if(is.null(rholist)){
rholist=seq(max(abs(s))/10,max(abs(s)),length=10)
}
rholist=sort(rholist)
itrace = 1 * trace
ipen = 1 * (penalize.diagonal)
ia = 1 * approx
rho=xx=ww=matrix(0,n,n)
nrho=length(rholist)
beta=what=array(0,c(n,n,nrho))
jerrs=rep(0,nrho)
mode(rholist) = "single"
mode(nrho) = "integer"
mode(rho) = "single"
mode(s) = "single"
mode(ww) = "single"
mode(xx) = "single"
mode(n) = "integer"
mode(maxit) = "integer"
mode(ia) = "integer"
mode(itrace) = "integer"
mode(ipen) = "integer"
mode(thr) = "single"
mode(beta) = "single"
mode(what) = "single"
mode(jerrs) = "integer"

junk <- .Fortran("glassopath", beta=beta,what=what,jerrs=jerrs,rholist,nrho,n, s, rho, ia, itrace, ipen,
thr, maxit = maxit, ww = ww, xx = xx, niter = integer(1),
del = single(1), ierr = integer(1), PACKAGE="glasso")

xx = array(junk$beta, c(n,n,nrho))
what = array(junk$what, c(n,n,nrho))
return(list(w=what, wi = xx,
approx = approx, rholist=rholist, errflag = junk$jerrs))
}

4 changes: 2 additions & 2 deletions man/glasso.Rd
Expand Up @@ -26,7 +26,7 @@ Only needed when start="warm" is specified}
Only needed when start="warm" is specified}
\item{trace}{Flag for printing out information as iterations proceed.
Default FALSE}
}}
}

\details{
Estimates a sparse inverse covariance matrix using a lasso (L1) penalty,
Expand Down Expand Up @@ -55,7 +55,7 @@ Jerome Friedman, Trevor Hastie and Robert Tibshirani (2007).
Sparse inverse covariance estimation with the lasso.
Biostatistics 2007. http://www-stat.stanford.edu/~tibs/ftp/graph.pdf

Meinshausen, N. and B\"{u}hlmann, P.(2006)
Meinshausen, N. and Buhlmann, P.(2006)
High dimensional graphs
and variable selection with the lasso.
Annals of Statistics,34, p1436-1462.
Expand Down
76 changes: 76 additions & 0 deletions man/glassopath.Rd
@@ -0,0 +1,76 @@
\name{glassopath}
\alias{glassopath}
\title{Compute the Graphical lasso along a path}
\description{
Estimates a sparse inverse covariance matrix using a lasso (L1) penalty, along a path
of values for the regularization parameter
}
\usage{
glassopath(s, rholist=NULL, thr=1.0e-4, maxit=1e4, approx=FALSE, penalize.diagonal=TRUE, w.init=NULL,wi.init=NULL, trace=FALSE)
}
\arguments{
\item{s}{Covariance matrix:p by p matrix (symmetric)}
\item{rholist}{Vector of non-negative regularization parameters for the lasso.
Should be increasing from smallest to largest; actual path is computed from largest
to smallest value of rho).
If NULL, 10 values in a (hopefully reasonable) range are used. Note that
the same parameter rholist[j] is used for all entries of the inverse covariance matrix;
different penalties for different entries are not allowed. }
\item{thr}{Threshold for convergence. Default value is 1e-4. Iterations stop when average absolute parameter change is less than thr * ave(abs(offdiag(s)))}
\item{maxit}{Maximum number of iterations of outer loop. Default 10,000}
\item{approx}{Approximation flag: if true, computes Meinhausen-Buhlmann(2006)
approximation}
\item{penalize.diagonal}{Should diagonal of inverse covariance be penalized?
Dafault TRUE.}
\item{w.init}{Optional starting values for estimated covariance matrix (p by p).
Only needed when start="warm" is specified}
\item{wi.init}{Optional starting values for estimated inverse covariance matrix (p by p)
Only needed when start="warm" is specified}
\item{trace}{Flag for printing out information as iterations proceed.
Default FALSE}
}

\details{
Estimates a sparse inverse covariance matrix using a lasso (L1) penalty, along a path of
regularization paramaters,
using the approach of Friedman, Hastie and Tibshirani (2007).
The Meinhausen-Buhlmann (2006) approximation is also implemented.
The algorithm can also be used to estimate a graph with missing edges,
by specifying which edges to omit in the zero argument, and setting rho=0.
Or both fixed zeroes for some elements and regularization on the other elements
can be specified.
}
\value{
A list with components
\item{w}{Estimated covariance matrices, an array of dimension (nrow(s),ncol(n), length(rholist))}
\item{wi}{Estimated inverse covariance matrix, an array of dimension (nrow(s),ncol(n), length(rholist))}
\item{approx}{Value of input argument approx}
\item{rholist}{Values of regularization parameter used}
\item{errflag}{values of error flag (0 means no memory allocation error)}
}


\references{
Jerome Friedman, Trevor Hastie and Robert Tibshirani (2007).
Sparse inverse covariance estimation with the lasso.
Biostatistics 2007. http://www-stat.stanford.edu/~tibs/ftp/graph.pdf

Meinshausen, N. and Buhlmann, P.(2006)
High dimensional graphs
and variable selection with the lasso.
Annals of Statistics,34, p1436-1462.
}
\examples{


set.seed(100)

x<-matrix(rnorm(50*20),ncol=20)
s<- var(x)
a<-glassopath(s)

}
\keyword{multivariate}
\keyword{models}
\keyword{graphs}

0 comments on commit 5b3fd3c

Please sign in to comment.