### ZIPLNfit Example Source: https://pln-team.github.io/PLNmodels/reference/ZIPLNfit.html Example code showing how to fit a ZIPLN model and inspect the resulting ZIPLNfit object. ```APIDOC ## ZIPLNfit Example ### Description This example demonstrates how to fit a Zero-Inflated Poisson Lognormal (ZIPLN) model using the `ZIPLN` function and then inspect the resulting `ZIPLNfit` object. ### Usage ```r if (FALSE) { # \dontrun{ # See other examples in function ZIPLN data(trichoptera) trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) myPLN <- ZIPLN(Abundance ~ 1, data = trichoptera) class(myPLN) print(myPLN) } # } ``` ### Details - The example uses the `trichoptera` dataset. - `prepare_data` is used to format the data. - `ZIPLN` fits the model with the formula `Abundance ~ 1`. - `class` and `print` are used to inspect the resulting object. ``` -------------------------------- ### Fit PLNnetwork and get best model Source: https://pln-team.github.io/PLNmodels/reference/PLNnetworkfit.html Example wrapped in \dontrun that loads the trichoptera dataset, prepares abundance and covariate data, fits a PLNnetwork model with formula Abundance ~ 1, retrieves the best model with getBestModel, and prints its class and details. ```r if (FALSE) { # \dontrun{ data(trichoptera) trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) nets <- PLNnetwork(Abundance ~ 1, data = trichoptera) myPLNnet <- getBestModel(nets) class(myPLNnet) print(myPLNnet) } # } ``` -------------------------------- ### Example: compute_PLN_starting_point with barents data Source: https://pln-team.github.io/PLNmodels/reference/compute_PLN_starting_point.html Example wrapped in \dontrun, demonstrating both default LM and GLM methods. Requires the barents dataset and constructs the model matrix with covariates Latitude, Longitude, Depth, and Temperature. ```R if (FALSE) { # \dontrun{ data(barents) Y <- barents$Abundance X <- model.matrix(Abundance ~ Latitude + Longitude + Depth + Temperature, data = barents) O <- log(barents$Offset) w <- rep(1, nrow(Y)) compute_PLN_starting_point(Y, X, O, w) compute_PLN_starting_point(Y, X, O, w, method = "GLM") } # } ``` -------------------------------- ### PLNfit Example Source: https://pln-team.github.io/PLNmodels/reference/PLNfit.html Example of fitting a PLN model and inspecting the resulting PLNfit object. ```APIDOC ## PLNfit Example ### Description Example of fitting a PLN model and inspecting the resulting PLNfit object. ### Usage ```r if (FALSE) { # \dontrun{ data(trichoptera) trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) myPLN <- PLN(Abundance ~ 1, data = trichoptera) class(myPLN) print(myPLN) } # } ``` ### Arguments None. ### Details This example uses the trichoptera dataset, prepares the data with `prepare_data`, fits a PLN model with `PLN`, and then prints the class and the object. ### Value No return value; the example is for demonstration. ### Examples ```r if (FALSE) { # \dontrun{ data(trichoptera) trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) myPLN <- PLN(Abundance ~ 1, data = trichoptera) class(myPLN) print(myPLN) } # } ``` ``` -------------------------------- ### Example: Fit ZIPLN model and extract coefficients Source: https://pln-team.github.io/PLNmodels/reference/coef.ZIPLNfit.html Example from the documentation that fits a ZIPLN model on a subset of the scRNA dataset and prints initialization and adjustment messages. The resulting model object can then be used with coef() to extract coefficients. ```r data(scRNA) # data subsample: only 100 random cell and the 50 most varying transcript subset <- sample.int(nrow(scRNA), 100) myPLN <- ZIPLN(counts[, 1:50] ~ 1 + offset(log(total_counts)), subset = subset, data = scRNA) #> #> Initialization... #> Adjusting a ZI-PLN model with full covariance model and single specific parameter(s) in Zero inflation component. #> DONE! ``` -------------------------------- ### Example: Plot network from PLNnetworkfit Source: https://pln-team.github.io/PLNmodels/reference/plot.PLNnetworkfit.html Example workflow: load trichoptera data, prepare it, fit a PLNnetwork model, select the best model, and plot the network. The plot call is wrapped in \dontrun{}. ```R data(trichoptera) trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) fits <- PLNnetwork(Abundance ~ 1, data = trichoptera) #> #> Initialization... #> Adjusting 30 PLN with sparse inverse covariance estimation #> Joint optimization alternating gradient descent and graphical-lasso #> sparsifying penalty = 0.5246191 sparsifying penalty = 0.4845754 sparsifying penalty = 0.4475881 sparsifying penalty = 0.4134241 sparsifying penalty = 0.3818678 sparsifying penalty = 0.3527202 sparsifying penalty = 0.3257973 sparsifying penalty = 0.3009295 sparsifying penalty = 0.2779598 sparsifying penalty = 0.2567434 sparsifying penalty = 0.2371464 sparsifying penalty = 0.2190452 sparsifying penalty = 0.2023257 sparsifying penalty = 0.1868823 sparsifying penalty = 0.1726178 sparsifying penalty = 0.159442 sparsifying penalty = 0.1472719 sparsifying penalty = 0.1360308 sparsifying penalty = 0.1256477 sparsifying penalty = 0.1160571 sparsifying penalty = 0.1071986 sparsifying penalty = 0.09901618 sparsifying penalty = 0.09145836 sparsifying penalty = 0.08447742 sparsifying penalty = 0.07802933 sparsifying penalty = 0.07207342 sparsifying penalty = 0.06657212 sparsifying penalty = 0.06149072 sparsifying penalty = 0.05679719 sparsifying penalty = 0.05246191 #> Post-treatments #> DONE! myNet <- getBestModel(fits) if (FALSE) { # \dontrun{ plot(myNet) } # } ``` -------------------------------- ### Example: Fit ZIPLN with fixed Omega Source: https://pln-team.github.io/PLNmodels/reference/ZIPLNfit_fixed.html Example from the documentation (wrapped in \dontrun) that prepares the trichoptera data and fits a ZIPLN model with a fixed diagonal Omega matrix. It prints the class and the fitted model. ```r if (FALSE) { # \dontrun{ # See other examples in function ZIPLN data(trichoptera) trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) myPLN <- ZIPLN(Abundance ~ 1, data = trichoptera, control = ZIPLN_param(Omega = diag(ncol(trichoptera$Abundance)))) class(myPLN) print(myPLN) } # } ``` -------------------------------- ### Example: Fitting and Inspecting a PLNnetworkfit Model Source: https://pln-team.github.io/PLNmodels/reference/PLNnetworkfit.html Demonstrates how to prepare data, fit a PLNnetwork model, retrieve the best model, and inspect its class and print output. ```APIDOC ## Example: Fitting and Inspecting a PLNnetworkfit Model ### Description This example shows how to use the PLNnetworkfit class by preparing data, fitting a PLNnetwork model, and retrieving the best model. ### Usage ```r if (FALSE) { # \dontrun{ data(trichoptera) trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) nets <- PLNnetwork(Abundance ~ 1, data = trichoptera) myPLNnet <- getBestModel(nets) class(myPLNnet) print(myPLNnet) } # } ``` ### Details - `data(trichoptera)` loads the trichoptera dataset. - `prepare_data()` prepares the abundance and covariate data. - `PLNnetwork()` fits a PLN network model with the formula `Abundance ~ 1`. - `getBestModel()` extracts the best model according to the selection criterion. - `class()` and `print()` are used to inspect the resulting PLNnetworkfit object. ``` -------------------------------- ### compute_ZIPLN_starting_point Source: https://pln-team.github.io/PLNmodels/reference/compute_ZIPLN_starting_point.html Computes a fast starting point for ZIPLN model initialization using linear models and empirical zero rates. ```APIDOC ## compute_ZIPLN_starting_point ### Description Computes a fast LM-based starting point for ZIPLN: one multivariate `lm.fit` for the PLN component and empirical zero rates / binomial GLMs for the ZI component. Replaces the previous per-species `pscl::zeroinfl` loop. ### Usage ```r compute_ZIPLN_starting_point(Y, X, X0, O, w = NULL) ``` ### Arguments - **Y** (matrix) - Required - Response count matrix (n × p) - **X** (matrix) - Required - Design matrix for the PLN component (n × d) - **X0** (matrix) - Required - Design matrix for the ZI component (n × d0, empty `matrix(NA,0,0)` when unused) - **O** (matrix) - Required - Offset matrix in log-scale (n × p) - **w** (numeric vector) - Optional - Weight vector of length n (defaults to uniform weights) ### Value Named list: `B` (d × p), `M` (n × p), `S2` (n × p), `R` (n × p), `B0` (d0 × p) ``` -------------------------------- ### Example: PCA visualization with trichoptera data Source: https://pln-team.github.io/PLNmodels/reference/plot.PLNPCAfit.html Complete example showing data preparation, model fitting with PLNPCA, selecting the best model, and plotting individual, variable, and both factor maps. The plotting calls are wrapped in \dontrun{} and are not executed. ```r data(trichoptera) trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) myPCAs <- PLNPCA(Abundance ~ 1 + offset(log(Offset)), data = trichoptera, ranks = 1:5) #> #> Initialization... #> #> Adjusting 5 PLN models for PCA analysis. #> Rank approximation = 1 Rank approximation = 2 Rank approximation = 3 Rank approximation = 4 Rank approximation = 5 #> Post-treatments #> DONE! myPCA <- getBestModel(myPCAs) if (FALSE) { # \dontrun{ plot(myPCA, map = "individual", nb_axes=2, ind_cols = trichoptera$Group) plot(myPCA, map = "variable", nb_axes=2) plot(myPCA, map = "both", nb_axes=2, ind_cols = trichoptera$Group) } # } ``` -------------------------------- ### Example: Prepare data and fit PLNnetwork Source: https://pln-team.github.io/PLNmodels/reference/extract_probs.html Loads the trichoptera dataset, prepares it, and fits a PLNnetwork model with an offset. The output shows the optimization progress with sparsifying penalties. ```r data(trichoptera) trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) nets <- PLNnetwork(Abundance ~ 1 + offset(log(Offset)), data = trichoptera) #> #> Initialization... #> Adjusting 30 PLN with sparse inverse covariance estimation #> Joint optimization alternating gradient descent and graphical-lasso #> sparsifying penalty = 0.3985143 sparsifying penalty = 0.368096 sparsifying penalty = 0.3399996 sparsifying penalty = 0.3140477 sparsifying penalty = 0.2900767 sparsifying penalty = 0.2679354 sparsifying penalty = 0.2474841 sparsifying penalty = 0.2285939 sparsifying penalty = 0.2111455 sparsifying penalty = 0.1950289 sparsifying penalty = 0.1801425 sparsifying penalty = 0.1663924 sparsifying penalty = 0.1536918 sparsifying penalty = 0.1419607 sparsifying penalty = 0.1311249 sparsifying penalty = 0.1211163 sparsifying penalty = 0.1118716 sparsifying penalty = 0.1033325 sparsifying penalty = 0.09544523 sparsifying penalty = 0.08815998 sparsifying penalty = 0.0814308 sparsifying penalty = 0.07521526 sparsifying penalty = 0.06947414 sparsifying penalty = 0.06417124 sparsifying penalty = 0.0592731 sparsifying penalty = 0.05474884 sparsifying penalty = 0.05056991 sparsifying penalty = 0.04670995 sparsifying penalty = 0.04314462 sparsifying penalty = 0.03985143 #> Post-treatments #> DONE! ``` -------------------------------- ### ZIPLNfit_sparse Example Source: https://pln-team.github.io/PLNmodels/reference/ZIPLNfit_sparse.html Example usage of the ZIPLN function to create a ZIPLNfit_sparse object, with printing and plotting. ```APIDOC ## ZIPLNfit_sparse ### Description Example of fitting a sparse zero-inflated Poisson lognormal model using the ZIPLN function and inspecting the resulting ZIPLNfit_sparse object. ### Usage ```r if (FALSE) { # \dontrun{ # See other examples in function ZIPLN data(trichoptera) trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) myPLN <- ZIPLN(Abundance ~ 1, data = trichoptera, control= ZIPLN_param(penalty = 1)) class(myPLN) print(myPLN) plot(myPLN) } # } ``` ### Arguments - **data** (data.frame) - Required - The dataset containing abundance and covariate information. - **formula** (formula) - Required - Model formula, e.g., `Abundance ~ 1`. - **control** (list) - Optional - Control parameters, e.g., `ZIPLN_param(penalty = 1)` for sparse regularization. ### Details This example demonstrates the typical workflow: load the trichoptera dataset, prepare it, fit a ZIPLN model with a penalty, and then examine the resulting object's class, print summary, and generate plots. ### Value An object of class `ZIPLNfit_sparse` (inheriting from `ZIPLNfit`), which contains the fitted model parameters and can be used for further analysis. ### Examples ```r if (FALSE) { # \dontrun{ # See other examples in function ZIPLN data(trichoptera) trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) myPLN <- ZIPLN(Abundance ~ 1, data = trichoptera, control= ZIPLN_param(penalty = 1)) class(myPLN) print(myPLN) plot(myPLN) } # } ``` ``` -------------------------------- ### PLNPCAfit Example Source: https://pln-team.github.io/PLNmodels/reference/PLNPCAfit.html Example of fitting a PLNPCA model and accessing the resulting PLNPCAfit object, including its fields and S3 methods. ```APIDOC ## PLNPCAfit ### Description PLNPCAfit is an R6 class representing a fitted Poisson Lognormal model with rank-constrained PCA. It extends PLNfit and PCA classes. ### Usage ```r data(trichoptera) trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) myPCAs <- PLNPCA(Abundance ~ 1 + offset(log(Offset)), data = trichoptera, ranks = 1:5) myPCA <- getBestModel(myPCAs) ``` ### Fields - `$model_par` - Model parameters - `$latent` - Latent variables - `$latent_pos` - Latent variables (positive) - `$var_par` - Variational parameters - `$optim_par` - Optimization parameters - `$loglik` - Log-likelihood - `$BIC` - Bayesian Information Criterion - `$ICL` - Integrated Completed Likelihood - `$loglik_vec` - Log-likelihood vector - `$nb_param` - Number of parameters - `$criteria` - Model selection criteria - `$percent_var` - Percentage of variance explained - `$corr_circle` - Correlation circle - `$scores` - PCA scores - `$rotation` - PCA rotation - `$eig` - Eigenvalues - `$var` - Variance - `$ind` - Individual coordinates ### S3 Methods - `print()` - Print the model - `coef()` - Extract coefficients - `sigma()` - Extract standard deviation - `vcov()` - Variance-covariance matrix - `fitted()` - Fitted values - `predict()` - Predictions - `predict_cond()` - Conditional predictions - `standard_error()` - Standard errors - `plot.PLNPCAfit()` - Plot the model ### Example Output ``` #> Poisson Lognormal with rank constrained for PCA (rank = 3) #> ================================================================== #> nb_param loglik BIC AIC ICL #> 65 -1056.865 -1183.349 -1121.865 -1241.534 #> ================================================================== ``` ``` -------------------------------- ### Example: Fit ZIPLN with diagonal covariance Source: https://pln-team.github.io/PLNmodels/reference/ZIPLNfit_diagonal.html Example code (not run) showing how to fit a ZIPLN model with diagonal covariance using the trichoptera dataset. It prepares the data, fits the model, and prints the class and the model object. ```r if (FALSE) { # \dontrun{ # See other examples in function ZIPLN data(trichoptera) trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) myPLN <- ZIPLN(Abundance ~ 1, data = trichoptera, control = ZIPLN_param(covariance = "diagonal")) class(myPLN) print(myPLN) } # } ``` -------------------------------- ### Example: Fit PLNPCA on trichoptera data with parallel computation Source: https://pln-team.github.io/PLNmodels/reference/PLNPCA.html Example from the documentation showing how to fit PLNPCA models on the trichoptera dataset. It sets up parallel computation with mc.cores, prepares the data, and runs PLNPCA with ranks 1:5. The output shows the initialization and adjustment progress. ```R ## Use parallel to dispatch the computations on 2 workers if (FALSE) { # \dontrun{ options(mc.cores = 2) } # } data(trichoptera) trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) myPCA <- PLNPCA(Abundance ~ 1 + offset(log(Offset)), data = trichoptera, ranks = 1:5) #> #> Initialization... #> #> Adjusting 5 PLN models for PCA analysis. #> Rank approximation = 1 Rank approximation = 2 Rank approximation = 3 Rank approximation = 4 Rank approximation = 5 #> Post-treatments #> DONE! if (FALSE) { # \dontrun{ options(mc.cores = 1) } # } ``` -------------------------------- ### Fit ZIPLN model on trichoptera data Source: https://pln-team.github.io/PLNmodels/reference/ZIPLNfit.html This example shows how to fit a ZIPLN model using the ZIPLN function. It prepares the trichoptera dataset and fits a model with an intercept-only formula. The example is wrapped in a dontrun block, so it is not executed by default. ```r if (FALSE) { # \dontrun{ # See other examples in function ZIPLN data(trichoptera) trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) myPLN <- ZIPLN(Abundance ~ 1, data = trichoptera) class(myPLN) print(myPLN) } # } ``` -------------------------------- ### Example: predict groups with PLNLDA on trichoptera data Source: https://pln-team.github.io/PLNmodels/reference/predict.PLNLDAfit.html Demonstrates fitting a PLNLDA model and predicting posterior probabilities and response groups. The example is wrapped in a dontrun block, so it is not executed by default. It shows how to compute posterior probabilities and predicted groups, then compare them to true groups. ```r data(trichoptera) trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) myLDA <- PLNLDA(Abundance ~ 0 + offset(log(Offset)), grouping = Group, data = trichoptera) #> #> Performing discriminant Analysis... #> DONE! if (FALSE) { # \dontrun{ post_probs <- predict(myLDA, newdata = trichoptera, type = "posterior", scale = "prob") head(round(post_probs, digits = 3)) predicted_group <- predict(myLDA, newdata = trichoptera, type = "response") table(predicted_group, trichoptera$Group, dnn = c("predicted", "true")) } # } ``` -------------------------------- ### Example: stability_selection with trichoptera data Source: https://pln-team.github.io/PLNmodels/reference/stability_selection.html Example code that prepares the trichoptera dataset, fits a PLNnetwork model, and runs stability_selection with 10 subsamples. The example is wrapped in a dontrun block. ```r data(trichoptera) trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) fits <- PLNnetwork(Abundance ~ 1, data = trichoptera) #> #> Initialization... #> Adjusting 30 PLN with sparse inverse covariance estimation #> Joint optimization alternating gradient descent and graphical-lasso #> sparsifying penalty = 0.5246191 sparsifying penalty = 0.4845754 sparsifying penalty = 0.4475881 sparsifying penalty = 0.4134241 sparsifying penalty = 0.3818678 sparsifying penalty = 0.3527202 sparsifying penalty = 0.3257973 sparsifying penalty = 0.3009295 sparsifying penalty = 0.2779598 sparsifying penalty = 0.2567434 sparsifying penalty = 0.2371464 sparsifying penalty = 0.2190452 sparsifying penalty = 0.2023257 sparsifying penalty = 0.1868823 sparsifying penalty = 0.1726178 sparsifying penalty = 0.159442 sparsifying penalty = 0.1472719 sparsifying penalty = 0.1360308 sparsifying penalty = 0.1256477 sparsifying penalty = 0.1160571 sparsifying penalty = 0.1071986 sparsifying penalty = 0.09901618 sparsifying penalty = 0.09145836 sparsifying penalty = 0.08447742 sparsifying penalty = 0.07802933 sparsifying penalty = 0.07207342 sparsifying penalty = 0.06657212 sparsifying penalty = 0.06149072 sparsifying penalty = 0.05679719 sparsifying penalty = 0.05246191 #> Post-treatments #> DONE! if (FALSE) { # \dontrun{ n <- nrow(trichoptera) subs <- replicate(10, sample.int(n, size = n/2), simplify = FALSE) stability_selection(nets, subsamples = subs) } # } ``` -------------------------------- ### getModel example with PLNPCA Source: https://pln-team.github.io/PLNmodels/reference/getModel.html Example usage of getModel to extract a model from a PLNPCAfamily. The example is wrapped in a dontrun block, so it is not executed by default. It prepares the trichoptera data, fits a PLNPCA model with ranks 1:5, and extracts the model with rank 2. ```R if (FALSE) { # \dontrun{ data(trichoptera) trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) myPCA <- PLNPCA(Abundance ~ 1 + offset(log(Offset)), data = trichoptera, ranks = 1:5) myModel <- getModel(myPCA, 2) } # } ``` -------------------------------- ### Example: Plot individual factor map for PLNLDAfit Source: https://pln-team.github.io/PLNmodels/reference/plot.PLNLDAfit.html This example loads the trichoptera dataset, prepares the data, fits a PLNLDA model, and plots the individual factor map with two axes. The plot call is wrapped in a dontrun block, so it is not executed in examples. ```r data(trichoptera) trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) myPLNLDA <- PLNLDA(Abundance ~ 1, grouping = Group, data = trichoptera) #> #> Performing discriminant Analysis... #> DONE! if (FALSE) { # \dontrun{ plot(myPLNLDA, map = "individual", nb_axes = 2) } # } ``` -------------------------------- ### PLNLDA example Source: https://pln-team.github.io/PLNmodels/reference/PLNLDAfit.html Example of fitting a PLNLDA model using the trichoptera dataset, including data preparation and printing the fitted object. ```APIDOC ## PLNLDA Example ### Description This example demonstrates how to fit a PLNLDA model using the trichoptera dataset. ### Usage ```r if (FALSE) { # \dontrun{ data(trichoptera) trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) myPLNLDA <- PLNLDA(Abundance ~ 1, grouping = Group, data = trichoptera) class(myPLNLDA) print(myPLNLDA) } # } ``` ### Arguments - **formula** (formula) - Required - A formula specifying the model, e.g., `Abundance ~ 1`. - **grouping** (factor) - Required - The grouping variable for the data. - **data** (data.frame) - Required - The prepared data frame containing abundance and covariates. ### Details This example is wrapped in `\dontrun{}` and is not executed during package checks. ### Value An object of class `PLNLDAfit`. ### Examples ```r if (FALSE) { # \dontrun{ data(trichoptera) trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) myPLNLDA <- PLNLDA(Abundance ~ 1, grouping = Group, data = trichoptera) class(myPLNLDA) print(myPLNLDA) } # } ``` ``` -------------------------------- ### compute_PLN_starting_point() Source: https://pln-team.github.io/PLNmodels/reference/index.html Helper function for PLN initialization. ```APIDOC ## compute_PLN_starting_point() ### Description Helper function for PLN initialization. ### Usage `compute_PLN_starting_point()` ### Arguments No arguments documented. ### Value No return value documented. ``` -------------------------------- ### Function usage signature for compute_PLN_starting_point Source: https://pln-team.github.io/PLNmodels/reference/compute_PLN_starting_point.html Shows the required arguments and default method for compute_PLN_starting_point. The method argument accepts either "LM" (default) or "GLM". ```R compute_PLN_starting_point(Y, X, O, w, method = c("LM", "GLM")) ``` -------------------------------- ### Install PLNmodels from CRAN and GitHub Source: https://pln-team.github.io/PLNmodels/index.html Install the stable version from CRAN, the development version from GitHub, or a specific tagged release using remotes. ```R install.packages("PLNmodels") # last stable version, from CRAN remotes::install_github("pln-team/PLNmodels") # development version, from GitHub remotes::install_github("pln-team/PLNmodels@tag_number") # a specific tagged release ``` -------------------------------- ### Example: Extract best model from PLNPCA Source: https://pln-team.github.io/PLNmodels/reference/getBestModel.html Example usage of getBestModel on a PLNPCAfamily object. The example is wrapped in 'if (FALSE)' to prevent execution during documentation checks. It prepares the trichoptera data, fits a PLNPCA model with ranks 1:4, and extracts the best model using the default criterion. ```r if (FALSE) { # \dontrun{ data(trichoptera) trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) myPCA <- PLNPCA(Abundance ~ 1 + offset(log(Offset)), data = trichoptera, ranks = 1:4) myModel <- getBestModel(myPCA) } # } ``` -------------------------------- ### PLNLDA example with diagonal covariance Source: https://pln-team.github.io/PLNmodels/reference/PLNLDAfit_diagonal.html Example code showing how to fit a PLNLDA model with diagonal covariance using the trichoptera dataset, and how to inspect the resulting object class and print it. ```APIDOC ## PLNLDA example with diagonal covariance ### Description This example demonstrates fitting a PLNLDA model with diagonal covariance using the `PLNLDA` function on the trichoptera dataset, and then inspecting the fitted model object. ### Usage ```r if (FALSE) { # \dontrun{ data(trichoptera) trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) myPLNLDA <- PLNLDA(Abundance ~ 1, grouping = Group, data = trichoptera, control = PLNLDA_param(covariance = "diagonal")) class(myPLNLDA) print(myPLNLDA) } # } ``` ### Arguments - `Abundance ~ 1` (formula) - Required - The model formula for the abundance response. - `grouping = Group` (factor) - Required - The grouping variable for discriminant analysis. - `data = trichoptera` (data.frame) - Required - The dataset containing the variables. - `control = PLNLDA_param(covariance = "diagonal")` (list) - Required - Control parameters specifying diagonal covariance. ### Details - The `prepare_data` function is used to prepare the abundance and covariate data. - The `PLNLDA` function fits the model. - `class(myPLNLDA)` returns the class of the fitted object. - `print(myPLNLDA)` prints the fitted model summary. ### Value The fitted PLNLDA model object of class `PLNLDAfit` (or subclass). ``` -------------------------------- ### PLNPCAfit$warm_start_from() Source: https://pln-team.github.io/PLNmodels/reference/PLNPCAfit.html Reinitializes parameters for sequential warm-starting from a lower-rank fit, carrying over fitted loadings, scores, variances, and regression coefficients, and padding new columns using the inception SVD or zeros/0.1. ```APIDOC ## PLNPCAfit$warm_start_from() ### Description Reinitialize parameters for sequential warm-starting from a lower-rank fit. Fitted loadings C, scores M, variances S, and regression coefficients B from `prev_fit` are carried over; new columns are padded using the inception SVD (C) or zeros/0.1 (M/S). ### Usage ``` PLNPCAfit$warm_start_from(prev_fit, svdM) ``` ### Arguments - **prev_fit** - a converged `PLNPCAfit` of rank `self$rank - k` (k >= 1) - **svdM** - the inception SVD (from `PLNPCAfamily`) ``` -------------------------------- ### PLNfit_genpop$new() Source: https://pln-team.github.io/PLNmodels/reference/PLNfit_genpop.html Initializes a PLNfit_genpop model with responses, covariates, offsets, weights, formula, and control parameters. The control list must include a fixed correlation matrix C. ```APIDOC ## PLNfit_genpop$new() ### Description Initialize a `PLNfit_genpop` model. ### Method Constructor ### Usage ``` PLNfit_genpop$new(responses, covariates, offsets, weights, formula, control) ``` ### Parameters #### Arguments - **responses** (matrix) - Required - The matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class. - **covariates** (matrix) - Required - Design matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily-class. - **offsets** (matrix) - Required - Offset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class. - **weights** (vector) - Optional - An optional vector of observation weights to be used in the fitting process. - **formula** (formula) - Required - Model formula used for fitting, extracted from the formula in the upper-level call. - **control** (list) - Required - A list for controlling the optimization, must include a field `C` (the fixed p x p correlation matrix). See details. ### Details Sigma = sigma2 * (rho * C + (1 - rho) * I_p), where C is a fixed p x p correlation matrix supplied by the user (`control$C`) and (sigma2, rho) are estimated. See `GeneticCovTraits` in `src/covariance_pln.h` for the C++ side. ### Example ```r if (FALSE) { # \dontrun{ data(trichoptera) trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) p <- ncol(trichoptera$Abundance) C <- 0.5^abs(outer(1:p, 1:p, "-")); diag(C) <- 1 myPLN <- PLN(Abundance ~ 1, data = trichoptera, control = PLN_param(covariance = "genpop", C = C)) class(myPLN) print(myPLN) } # } ``` ``` -------------------------------- ### Example: plot network from ZIPLNfit_sparse Source: https://pln-team.github.io/PLNmodels/reference/plot.ZIPLNfit_sparse.html Fits a ZIPLN model with sparse covariance and plots the network. The example is wrapped in \dontrun{} and includes data preparation and model fitting with a penalty of 0.1. ```r data(trichoptera) trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) fit <- ZIPLN(Abundance ~ 1, data = trichoptera, control = ZIPLN_param(penalty = 0.1)) #> ℹ The penalty now applies on the correlation scale by default: the penalties #> given are taken as such, between 0 and 1. Until version 1.3.2 they were on #> the covariance scale. #> ℹ Set `penalty_scale = "covariance"` in the control parameters to get the #> former behavior back, or `penalty_scale = "correlation"` to keep the #> penalties as they are, without this message. #> This message is displayed once per session. #> #> Initialization... #> Adjusting a ZI-PLN model with sparse covariance model and single specific parameter(s) in Zero inflation component. #> DONE! if (FALSE) { # \dontrun{ plot(fit) } # } ``` -------------------------------- ### ZIPLNfit$show() usage Source: https://pln-team.github.io/PLNmodels/reference/ZIPLNfit.html User-friendly print method with a customizable first line. ```r ZIPLNfit$show( model = paste("A multivariate Zero Inflated Poisson Lognormal fit with", self$vcov_model, "covariance model.\n") ) ``` -------------------------------- ### Example: Stability selection and extract probabilities as vector Source: https://pln-team.github.io/PLNmodels/reference/extract_probs.html Performs stability selection on the fitted network and extracts edge selection probabilities as a named vector. Wrapped in \dontrun{} to avoid execution in examples. ```r if (FALSE) { # \dontrun{ stability_selection(nets) probs <- extract_probs(nets, crit = "StARS", format = "vector") probs } # } ``` -------------------------------- ### ZIPLNfit$show() Source: https://pln-team.github.io/PLNmodels/reference/ZIPLNfit.html User-friendly print method for the ZIPLNfit object. ```APIDOC ## ZIPLNfit$show() ### Description User-friendly print method for the ZIPLNfit object. ### Method R6 method ### Usage ```r ZIPLNfit$show( model = paste("A multivariate Zero Inflated Poisson Lognormal fit with", self$vcov_model, "covariance model.\n") ) ``` ### Parameters - **model** (character) - Optional - First line of the print output. ``` -------------------------------- ### ZIPLNfit_spherical$new() Source: https://pln-team.github.io/PLNmodels/reference/ZIPLNfit_spherical.html Initializes a ZIPLNfit_spherical model with the provided data and control parameters. ```APIDOC ## ZIPLNfit_spherical$new() ### Description Initialize a `ZIPLNfit_spherical` model. ### Usage ``` ZIPLNfit_spherical$new(data, control) ``` ### Arguments - **data** (named list) - Required - A named list used internally to carry the data matrices. - **control** (list) - Required - A list for controlling the optimization. See details. ``` -------------------------------- ### PLNmixturefit$new() Source: https://pln-team.github.io/PLNmodels/reference/PLNmixturefit.html Initializes a PLNmixturefit model with the provided responses, covariates, offsets, posterior probabilities, formula, and control parameters. ```APIDOC ## PLNmixturefit$new() ### Description Initializes a PLNmixturefit model. ### Usage ```r PLNmixturefit$new( responses, covariates, offsets, posteriorProb, formula, control ) ``` ### Arguments - **responses** (matrix) - Required - The matrix of responses common to every model. - **covariates** (matrix) - Required - The matrix of covariates common to every model. - **offsets** (matrix) - Required - The matrix of offsets common to every model. - **posteriorProb** (matrix) - Required - Matrix of posterior probability for cluster belonging. - **formula** (formula) - Required - Model formula used for fitting, extracted from the formula in the upper-level call. - **control** (list) - Required - A list for controlling the optimization. ``` -------------------------------- ### ZIPLNnetworkfamily$new() Source: https://pln-team.github.io/PLNmodels/reference/ZIPLNnetworkfamily.html Initializes all models in the collection with given penalties, data, and control parameters. ```APIDOC ## ZIPLNnetworkfamily$new() ### Description Initializes all models in the collection with given penalties, data, and control parameters. ### Usage ``` ZIPLNnetworkfamily$new(penalties, data, control) ``` ### Arguments - **penalties** (vector of positive real numbers) - Required - A vector of positive real numbers controlling the level of sparsity of the underlying network. - **data** (named list) - Required - A named list used internally to carry the data matrices. - **control** (list) - Required - A list for controlling the optimization. ### Returns Updates current `PLNnetworkfit` with smart starting values. ``` -------------------------------- ### Example: Fit PLN mixture and plot PCA and matrix Source: https://pln-team.github.io/PLNmodels/reference/plot.PLNmixturefit.html Fits a PLN mixture model on the trichoptera data and plots the results using 'pca' and 'matrix' types. The example is wrapped in \dontrun{} and includes the model fitting output. ```r data(trichoptera) trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) myPLN <- PLNmixture(Abundance ~ 1 + offset(log(Offset)), data = trichoptera, control = PLNmixture_param(smoothing = "none")) %>% getBestModel() #> #> Initialization... #> #> Adjusting 5 PLN mixture models. #> number of cluster = 1 number of cluster = 2 number of cluster = 3 number of cluster = 4 number of cluster = 5 #> Post-treatments #> DONE! if (FALSE) { # \dontrun{ plot(myPLN, "pca") plot(myPLN, "matrix") } # } ``` -------------------------------- ### PLNmixturefit$show() Source: https://pln-team.github.io/PLNmodels/reference/PLNmixturefit.html User friendly print method. ```APIDOC ## PLNmixturefit$show() ### Description User friendly print method. ### Method R6 method ### Usage ``` PLNmixturefit$show() ``` ```