Skip to content

Commit

Permalink
updated namespace and man via roxygen
Browse files Browse the repository at this point in the history
  • Loading branch information
zdk123 committed Oct 25, 2017
1 parent d705428 commit e35b73e
Show file tree
Hide file tree
Showing 49 changed files with 41 additions and 86 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: SpiecEasi
Title: Sparse Inverse Covariance for Ecological Statistical Inference
Version: 0.1.2
Version: 0.1.3
Authors.R: c(person("Zachary", "Kurtz", role = c("aut", "cre"),
email="zachary.kurtz@med.nyu.edu"), person("Christian",
"Mueller", role = c("aut")), person("Emily", "Miraldi",
Expand All @@ -21,4 +21,4 @@ Suggests:
testthat
License: getOptions('devtools.desc.license')
LazyData: true
RoxygenNote: 5.0.1
RoxygenNote: 6.0.1
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export(synth_comm_from_counts)
export(tril)
export(triu)
export(triu2diag)
import(phyloseq)
importFrom(MASS,ginv)
importFrom(VGAM,dzinegbin)
importFrom(VGAM,dzipois)
Expand Down
74 changes: 38 additions & 36 deletions R/SparseICov.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ spiec.easi <- function(obj, ...) {

#' Spiec-Easi pipeline
#' @method spiec.easi phyloseq
#' @import phyloseq
#' @export
spiec.easi.phyloseq <- function(obj, ...) {
if (!require('foo')) {
stop('\'Phyloseq\' package is not installed')
}
OTU <- otu_table(obj)@.Data
if (otu_table(obj)@taxa_are_rows) OTU <- t(OTU)
spiec.easi.default(OTU, ...)
Expand All @@ -25,15 +27,15 @@ spiec.easi.phyloseq <- function(obj, ...) {
#' @param ... further arguments to sparseiCov
#' @method spiec.easi default
#' @export
spiec.easi.default <- function(data, method='glasso', sel.criterion='stars', verbose=TRUE,
spiec.easi.default <- function(data, method='glasso', sel.criterion='stars', verbose=TRUE,
icov.select=TRUE, icov.select.params=list(), ...) {

args <- list(...)
if (verbose) message("Normalizing/clr transformation of data with pseudocount ...")
data.clr <- t(clr(data+1, 1))
if (verbose) message(paste("Inverse Covariance Estimation with", method, "...", sep=" "))
est <- do.call('sparseiCov', c(list(data=data.clr, method=method), args))

if (icov.select) {
if (verbose) message(paste("Model selection with", sel.criterion, "...", sep=" "))
est <- do.call('icov.select', c(list(est=est, criterion=sel.criterion), icov.select.params))
Expand Down Expand Up @@ -90,7 +92,7 @@ spiec.easi.default <- function(data, method='glasso', sel.criterion='stars', ver
#' huge::huge.roc(est.f$path, Theta)
#'
sparseiCov <- function(data, method, npn=FALSE, verbose=FALSE, cov.output = TRUE, ...) {

if (npn) data <- huge::huge.npn(data, verbose=verbose)

args <- list(...)
Expand All @@ -100,7 +102,7 @@ sparseiCov <- function(data, method, npn=FALSE, verbose=FALSE, cov.output = TRUE
if (is.null(args$lambda.min.ratio)) args$lambda.min.ratio <- 1e-3

if (method %in% c("glasso")) {
do.call(huge::huge, c(args, list(x=data, method=method, verbose=verbose,
do.call(huge::huge, c(args, list(x=data, method=method, verbose=verbose,
cov.output = cov.output)))

} else if (method %in% c('mb')) {
Expand All @@ -115,7 +117,7 @@ sparseiCov <- function(data, method, npn=FALSE, verbose=FALSE, cov.output = TRUE

#' Model selection for picking the right \code{lambda} penalty.
#' This is identical to huge::huge.stars except that the subsampling loop is replaced with an mclapply function to add parallelization capabilities.
#'
#'
#' @param est an estimate/model as produced by the sparseiCov function
#' @param criterion character string specifying criterion/method for model selection accepts 'stars' [default], 'ric', 'ebic'
#' @param stars.thresh variability threshold for stars selection
Expand All @@ -126,7 +128,7 @@ sparseiCov <- function(data, method, npn=FALSE, verbose=FALSE, cov.output = TRUE
#' @param normfun normalize internally if data should be renormalized
#' @importFrom parallel mclapply
#' @export
icov.select <- function(est, criterion = 'stars', stars.thresh = 0.05, ebic.gamma = 0.5,
icov.select <- function(est, criterion = 'stars', stars.thresh = 0.05, ebic.gamma = 0.5,
stars.subsample.ratio = NULL, rep.num = 20, ncores=1, normfun=function(x) x, verbose=FALSE) {
gcinfo(FALSE)
if (est$cov.input) {
Expand All @@ -135,9 +137,9 @@ icov.select <- function(est, criterion = 'stars', stars.thresh = 0.05, ebic.gamm
return(est)
}
if (!est$cov.input) {
if (est$method == "mb" && is.null(criterion))
if (est$method == "mb" && is.null(criterion))
criterion = "stars"
if (est$method == "ct" && is.null(criterion))
if (est$method == "ct" && is.null(criterion))
criterion = "ebic"
n = nrow(est$data)
d = ncol(est$data)
Expand All @@ -155,8 +157,8 @@ icov.select <- function(est, criterion = 'stars', stars.thresh = 0.05, ebic.gamm
nr = n
r = 1:n
}
out = .C("RIC", X = as.double(est$data), dd = as.integer(d),
nn = as.integer(n), r = as.integer(r), nr = as.integer(nr),
out = .C("RIC", X = as.double(est$data), dd = as.integer(d),
nn = as.integer(n), r = as.integer(r), nr = as.integer(nr),
lambda_opt = as.double(0), PACKAGE = "huge")
est$opt.lambda = out$lambda_opt/n
rm(out)
Expand All @@ -169,28 +171,28 @@ icov.select <- function(est, criterion = 'stars', stars.thresh = 0.05, ebic.gamm
message("Computing the optimal graph....")
# flush.console()
}
if (est$opt.lambda > max(cor(est$data)))
if (est$opt.lambda > max(cor(est$data)))
est$refit = Matrix(0, d, d)
else {
if (est$method == "mb")
est$refit = huge::huge.mb(est$data, lambda = est$opt.lambda,
if (est$method == "mb")
est$refit = huge::huge.mb(est$data, lambda = est$opt.lambda,
sym = est$sym, idx.mat = est$idx.mat, verbose = FALSE)$path[[1]]
if (est$method == "glasso") {
if (!is.null(est$cov)) {
tmp = huge::huge.glasso(est$data, lambda = est$opt.lambda,
tmp = huge::huge.glasso(est$data, lambda = est$opt.lambda,
scr = est$scr, cov.output = TRUE, verbose = FALSE)
est$opt.cov = tmp$cov[[1]]
}
if (is.null(est$cov))
tmp = huge::huge.glasso(est$data, lambda = est$opt.lambda,
if (is.null(est$cov))
tmp = huge::huge.glasso(est$data, lambda = est$opt.lambda,
verbose = FALSE)
est$refit = tmp$path[[1]]
est$opt.icov = tmp$icov[[1]]
rm(tmp)
gc()
}
if (est$method == "ct")
est$refit = huge::huge.ct(est$data, lambda = est$opt.lambda,
if (est$method == "ct")
est$refit = huge::huge.ct(est$data, lambda = est$opt.lambda,
verbose = FALSE)$path[[1]]
}
est$opt.sparsity = sum(est$refit)/d/(d - 1)
Expand All @@ -208,7 +210,7 @@ icov.select <- function(est, criterion = 'stars', stars.thresh = 0.05, ebic.gamm
est$opt.index = which.min(est$ebic.score)
est$refit = est$path[[est$opt.index]]
est$opt.icov = est$icov[[est$opt.index]]
if (est$cov.output)
if (est$cov.output)
est$opt.cov = est$cov[[est$opt.index]]
est$opt.lambda = est$lambda[est$opt.index]
est$opt.sparsity = est$sparsity[est$opt.index]
Expand All @@ -219,14 +221,14 @@ icov.select <- function(est, criterion = 'stars', stars.thresh = 0.05, ebic.gamm
}
if (criterion == "stars") {
if (is.null(stars.subsample.ratio)) {
if (n > 144)
if (n > 144)
stars.subsample.ratio = 10 * sqrt(n)/n
if (n <= 144)
if (n <= 144)
stars.subsample.ratio = 0.8
}

# for (i in 1:nlambda) merge[[i]] <- Matrix(0, d, d)

if (verbose) {
mes = "Conducting Subsampling....."
message(mes, appendLF = FALSE)
Expand All @@ -236,23 +238,23 @@ icov.select <- function(est, criterion = 'stars', stars.thresh = 0.05, ebic.gamm
# for (i in 1:rep.num) {
premerge <- parallel::mclapply(1:rep.num, function(i) {
# if (verbose) {
# mes <- paste(c("Conducting Subsampling....in progress:",
# mes <- paste(c("Conducting Subsampling....in progress:",
# floor(100 * i/rep.num), "%"), collapse = "")
# cat(mes, "\r")
# flush.console()
# }
# merge <- replicate(nlambda, Matrix(0, d,d))
ind.sample = sample(c(1:n), floor(n * stars.subsample.ratio),
ind.sample = sample(c(1:n), floor(n * stars.subsample.ratio),
replace = FALSE)
if (est$method == "mb")
tmp = huge::huge.mb(normfun(est$data[ind.sample, ]), lambda = est$lambda,
scr = est$scr, idx.mat = est$idx.mat, sym = est$sym,
if (est$method == "mb")
tmp = huge::huge.mb(normfun(est$data[ind.sample, ]), lambda = est$lambda,
scr = est$scr, idx.mat = est$idx.mat, sym = est$sym,
verbose = FALSE)$path
if (est$method == "ct")
tmp = huge::huge.ct(normfun(est$data[ind.sample, ]), lambda = est$lambda,
if (est$method == "ct")
tmp = huge::huge.ct(normfun(est$data[ind.sample, ]), lambda = est$lambda,
verbose = FALSE)$path
if (est$method == "glasso")
tmp = huge::huge.glasso(normfun(est$data[ind.sample, ]), lambda = est$lambda,
if (est$method == "glasso")
tmp = huge::huge.glasso(normfun(est$data[ind.sample, ]), lambda = est$lambda,
scr = est$scr, verbose = FALSE)$path
# for (j in 1:nlambda) merge[[j]] <- merge[[j]] + tmp[[j]]

Expand All @@ -279,14 +281,14 @@ icov.select <- function(est, criterion = 'stars', stars.thresh = 0.05, ebic.gamm
est$merge[[i]] <- merge[[i]]/rep.num
est$variability[i] <- 4 * sum(est$merge[[i]] * (1 - est$merge[[i]]))/(d * (d - 1))
}
est$opt.index = max(which.max(est$variability >=
est$opt.index = max(which.max(est$variability >=
stars.thresh)[1] - 1, 1)
est$refit = est$path[[est$opt.index]]
est$opt.lambda = est$lambda[est$opt.index]
est$opt.sparsity = est$sparsity[est$opt.index]
if (est$method == "glasso") {
est$opt.icov = est$icov[[est$opt.index]]
if (!is.null(est$cov))
if (!is.null(est$cov))
est$opt.cov = est$cov[[est$opt.index]]
}
}
Expand Down
1 change: 0 additions & 1 deletion man/adj2igraph.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/alr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/as.data.frame.graph.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/as.matrix.graph.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/band.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/block.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/clr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/cluster.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/cor2cov.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/cov2prec.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/erdos_renyi.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/fitdistr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/getOptBeta.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/getOptMerge.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/get_comm_params.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/graph2prec.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/graph2prec2.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/hub.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/icov.select.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/make_graph.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/make_precision_mat.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/neff.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/norm_diric.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/norm_pseudo.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/norm_to_total.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/prec2cov.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/pval.sparccboot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/qqdplot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/qqdplot_comm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/rmvnegbin.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/rmvnorm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/rmvpois.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/rmvzinegbin.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/rmvzipois.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e35b73e

Please sign in to comment.