| ZIPLNfit {PLNmodels} | R Documentation |
An R6 Class to represent a ZIPLNfit
Description
The function ZIPLN() fits a model which is an instance of an object with class ZIPLNfit.
This class comes with a set of R6 methods, some of which are useful for the end-user and exported as S3 methods.
See the documentation for coef(), sigma(), predict().
Fields are accessed via active binding and cannot be changed by the user.
Details
Covariates for the Zero-Inflation parameter (using a logistic regression model) can be specified in the formula RHS using the pipe
(~ PLN effect | ZI effect) to separate covariates for the PLN part of the model from those for the Zero-Inflation part.
Note that different covariates can be used for each part.
Active bindings
nnumber of samples/sites
qnumber of dimensions of the latent space
pnumber of variables/species
dnumber of covariates in the PLN part
d0number of covariates in the ZI part
nb_param_zinumber of parameters in the ZI part of the model
nb_param_plnnumber of parameters in the PLN part of the model
nb_paramnumber of parameters in the ZIPLN model
model_para list with the matrices of parameters found in the model (B, Sigma, plus some others depending on the variant)
var_para list with two matrices, M and S2, which are the estimated parameters in the variational approximation
optim_para list with parameters useful for monitoring the optimization
latenta matrix: values of the latent vector (Z in the model)
latent_posa matrix: values of the latent position vector (Z) without covariates effects or offset
fitteda matrix: fitted values of the observations (A in the model)
vcov_modelcharacter: the model used for the covariance (either "spherical", "diagonal", "full" or "sparse")
zi_modelcharacter: the model used for the zero inflation (either "single", "row", "col" or "covar")
loglik(weighted) variational lower bound of the loglikelihood
loglik_vecelement-wise variational lower bound of the loglikelihood
BICvariational lower bound of the BIC
entropyEntropy of the variational distribution
entropy_ZIEntropy of the variational distribution
entropy_PLNEntropy of the Gaussian variational distribution in the PLN component
ICLvariational lower bound of the ICL
criteriaa vector with loglik, BIC, ICL and number of parameters
Methods
Public methods
Method update()
Update a ZIPLNfit object
Usage
ZIPLNfit$update( B = NA, B0 = NA, Pi = NA, Omega = NA, Sigma = NA, M = NA, S = NA, R = NA, Ji = NA, Z = NA, A = NA, monitoring = NA )
Arguments
Bmatrix of regression parameters in the Poisson lognormal component
B0matrix of regression parameters in the zero inflated component
PiZero inflated probability parameter (either scalar, row-vector, col-vector or matrix)
Omegaprecision matrix of the latent variables
Sigmacovariance matrix of the latent variables
Mmatrix of mean vectors for the variational approximation
Smatrix of standard deviation parameters for the variational approximation
Rmatrix of probabilities for the variational approximation
Jivector of variational lower bounds of the log-likelihoods (one value per sample)
Zmatrix of latent vectors (includes covariates and offset effects)
Amatrix of fitted values
monitoringa list with optimization monitoring quantities
Returns
Update the current ZIPLNfit object
Method new()
Initialize a ZIPLNfit model
Usage
ZIPLNfit$new(data, control)
Arguments
dataa named list used internally to carry the data matrices
controla list for controlling the optimization. See details.
Method optimize()
Call to the Cpp optimizer and update of the relevant fields
Usage
ZIPLNfit$optimize(data, control)
Arguments
dataa named list used internally to carry the data matrices
controla list for controlling the optimization. See details.
Method optimize_vestep()
Result of one call to the VE step of the optimization procedure: optimal variational parameters (M, S, R) and corresponding log likelihood values for fixed model parameters (Sigma, B, B0). Intended to position new data in the latent space.
Usage
ZIPLNfit$optimize_vestep( data, B = self$model_par$B, B0 = self$model_par$B0, Omega = self$model_par$Omega, control = ZIPLN_param(backend = "nlopt")$config_optim )
Arguments
dataa named list used internally to carry the data matrices
BOptional fixed value of the regression parameters in the PLN component
B0Optional fixed value of the regression parameters in the ZI component
Omegainverse variance-covariance matrix of the latent variables
controla list for controlling the optimization. See details.
Returns
A list with three components:
the matrix
Mof variational means,the matrix
Sof variational standard deviationsthe matrix
Rof variational ZI probabilitiesthe vector
Jiof (variational) log-likelihood of each new observationa list
monitoringwith information about convergence status
Method predict()
Predict position, scores or observations of new data. See predict.ZIPLNfit() for the S3 method and additional details
Usage
ZIPLNfit$predict(
newdata,
responses = NULL,
type = c("link", "response", "deflated"),
level = 1,
envir = parent.frame()
)Arguments
newdataA data frame in which to look for variables with which to predict. If omitted, the fitted values are used.
responsesOptional data frame containing the count of the observed variables (matching the names of the provided as data in the PLN function), assuming the interest in in testing the model.
typeScale used for the prediction. Either
"link"(default, predicted positions in the latent space),"response"(predicted average counts, accounting for zero-inflation) or"deflated"(predicted average counts, not accounting for zero-inflation and using only the PLN part of the model).levelOptional integer value the level to be used in obtaining the predictions. Level zero corresponds to the population predictions (default if
responsesis not provided) while level one (default) corresponds to predictions after evaluating the variational parameters for the new data.envirEnvironment in which the prediction is evaluated
Returns
A matrix with predictions scores or counts.
Method show()
User friendly print method
Usage
ZIPLNfit$show(
model = paste("A multivariate Zero Inflated Poisson Lognormal fit with",
private$covariance, "covariance model.\n")
)Arguments
modelFirst line of the print output
Method print()
User friendly print method
Usage
ZIPLNfit$print()
Method clone()
The objects of this class are cloneable with this method.
Usage
ZIPLNfit$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
Examples
## Not run:
# 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)
## End(Not run)