Skip to content

Zipln formula #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions R/utils-zipln.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ extract_model_zi <- function(call, envir) {
call_args <- c(as.list(call_args), list(xlev = attr(call$formula, "xlevels"), na.action = NULL))

## Extract terms for ZI and PLN components
terms <- .extract_terms_zi(as.formula(call$formula, env = envir))
terms <- .extract_terms_zi(as.formula(eval(call$formula, env = envir)))
## eval the call in the parent environment with adjustement due to ZI terms
call_args$formula <- terms$formula
frame <- do.call(stats::model.frame, call_args, envir = envir)

## Save level for predict function
xlevels <- list(PLN = .getXlevels(terms$PLN, frame))
if (!is.null(terms$ZI)) xlevels$ZI = .getXlevels(terms$ZI, frame)
attr(call$formula, "xlevels") <- xlevels
if (!is.null(xlevels$PLN)) attr(call$formula, "xlevels") <- xlevels

## Create the set of matrices to fit the PLN model
X <- model.matrix(terms$PLN, frame, xlev = xlevels$PLN)
Expand Down
6 changes: 4 additions & 2 deletions inst/case_studies/oaks_tree.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,16 @@ factoextra::fviz_pca_biplot(

## Network inference with sparce covariance estimation

system.time(myZIPLNnets <- ZIPLNnetwork(Abundance ~ 0 + tree + offset(log(Offset)), zi = "single", data = oaks, control = ZIPLNnetwork_param(min_ratio = 0.1)))

system.time(myPLNnets <- PLNnetwork(Abundance ~ 0 + tree + offset(log(Offset)), data = oaks, control = PLNnetwork_param(min_ratio = 0.1)))
plot(myPLNnets)
plot(getBestModel(myPLNnets, "EBIC"))
# stability_selection(myPLNnets)
# plot(getBestModel(myPLNnets, "StARS", stability = .975))

system.time(myZIPLNnets <- ZIPLNnetwork(Abundance ~ 0 + tree + offset(log(Offset)), zi = "single", data = oaks, control = ZIPLNnetwork_param(min_ratio = 0.1)))
plot(myZIPLNnets)
plot(getBestModel(myZIPLNnets, "EBIC"))

## Mixture model to recover tree structure
system.time(my_mixtures <- PLNmixture(Abundance ~ 1 + offset(log(Offset)), data = oaks, clusters = 1:5))

Expand Down
Loading