| PLNfit {PLNmodels} | R Documentation |
An R6 Class to represent a PLNfit in a standard, general framework
Description
The function PLN() fit a model which is an instance of a object with class PLNfit.
Objects produced by the functions PLNnetwork(), PLNPCA(), PLNmixture() and PLNLDA() also enjoy the methods of PLNfit() by inheritance.
This class comes with a set of R6 methods, some of them being useful for the user and exported as S3 methods.
See the documentation for coef(), sigma(), predict(), vcov() and standard_error().
Fields are accessed via active binding and cannot be changed by the user.
Active bindings
nnumber of samples
qnumber of dimensions of the latent space
pnumber of species
dnumber of covariates
nb_paramnumber of parameters in the current PLN model
model_para list with the matrices of the model parameters: B (covariates), Sigma (covariance), Omega (precision matrix), plus some others depending on the variant)
var_para list with the matrices of the variational parameters: M (means) and S2 (variances)
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_coefmatrix of sandwich estimator of the variance-covariance of B (need fixed -ie known- covariance at the moment)
vcov_modelcharacter: the model used for the residual covariance
weightsobservational weights
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
ICLvariational lower bound of the ICL
R_squaredapproximated goodness-of-fit criterion
criteriaa vector with loglik, BIC, ICL and number of parameters
Methods
Public methods
Method new()
Initialize a PLNfit model
Usage
PLNfit$new(responses, covariates, offsets, weights, formula, control)
Arguments
responsesthe matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class
covariatesdesign matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily-class
offsetsoffset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class
weightsan optional vector of observation weights to be used in the fitting process.
formulamodel formula used for fitting, extracted from the formula in the upper-level call
controla list-like structure for controlling the fit, see
PLN_param().
Method update()
Update a PLNfit object
Usage
PLNfit$update( B = NA, Sigma = NA, Omega = NA, M = NA, S = NA, Ji = NA, R2 = NA, Z = NA, A = NA, monitoring = NA )
Arguments
Bmatrix of regression matrix
Sigmavariance-covariance matrix of the latent variables
Omegaprecision matrix of the latent variables. Inverse of Sigma.
Mmatrix of variational parameters for the mean
Smatrix of variational parameters for the variance
Jivector of variational lower bounds of the log-likelihoods (one value per sample)
R2approximate R^2 goodness-of-fit criterion
Zmatrix of latent vectors (includes covariates and offset effects)
Amatrix of fitted values
monitoringa list with optimization monitoring quantities
Returns
Update the current PLNfit object
Method optimize()
Call to the NLopt or TORCH optimizer and update of the relevant fields
Usage
PLNfit$optimize(responses, covariates, offsets, weights, config)
Arguments
responsesthe matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class
covariatesdesign matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily-class
offsetsoffset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class
weightsan optional vector of observation weights to be used in the fitting process.
configpart of the
controlargument which configures the optimizer
Method optimize_vestep()
Result of one call to the VE step of the optimization procedure: optimal variational parameters (M, S) and corresponding log likelihood values for fixed model parameters (Sigma, B). Intended to position new data in the latent space.
Usage
PLNfit$optimize_vestep( covariates, offsets, responses, weights, B = self$model_par$B, Omega = self$model_par$Omega, control = PLN_param(backend = "nlopt") )
Arguments
covariatesdesign matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily-class
offsetsoffset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class
responsesthe matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class
weightsan optional vector of observation weights to be used in the fitting process.
BOptional fixed value of the regression parameters
Omegaprecision matrix of the latent variables. Inverse of Sigma.
controla list-like structure for controlling the fit, see
PLN_param().Sigmavariance-covariance matrix of the latent variables
Returns
A list with three components:
the matrix
Mof variational means,the matrix
S2of variational variancesthe vector
log.likof (variational) log-likelihood of each new observation
Method postTreatment()
Update R2, fisher and std_err fields after optimization
Usage
PLNfit$postTreatment( responses, covariates, offsets, weights = rep(1, nrow(responses)), config_post, config_optim, nullModel = NULL )
Arguments
responsesthe matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class
covariatesdesign matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily-class
offsetsoffset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class
weightsan optional vector of observation weights to be used in the fitting process.
config_posta list for controlling the post-treatments (optional bootstrap, jackknife, R2, etc.). See details
config_optima list for controlling the optimization (optional bootstrap, jackknife, R2, etc.). See details
nullModelnull model used for approximate R2 computations. Defaults to a GLM model with same design matrix but not latent variable.
Details
The list of parameters config controls the post-treatment processing, with the following entries:
jackknife boolean indicating whether jackknife should be performed to evaluate bias and variance of the model parameters. Default is FALSE.
bootstrap integer indicating the number of bootstrap resamples generated to evaluate the variance of the model parameters. Default is 0 (inactivated).
variational_var boolean indicating whether variational Fisher information matrix should be computed to estimate the variance of the model parameters (highly underestimated). Default is FALSE.
rsquared boolean indicating whether approximation of R2 based on deviance should be computed. Default is TRUE
trace integer for verbosity. should be > 1 to see output in post-treatments
Method predict()
Predict position, scores or observations of new data.
Usage
PLNfit$predict(
newdata,
responses = NULL,
type = c("link", "response"),
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) orresponse(predicted counts).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
Details
Note that level = 1 can only be used if responses are provided,
as the variational parameters can't be estimated otherwise. In the absence of responses, level is ignored and the fitted values are returned
Returns
A matrix with predictions scores or counts.
Method predict_cond()
Predict position, scores or observations of new data, conditionally on the observation of a (set of) variables
Usage
PLNfit$predict_cond(
newdata,
cond_responses,
type = c("link", "response"),
var_par = FALSE,
envir = parent.frame()
)Arguments
newdataa data frame containing the covariates of the sites where to predict
cond_responsesa data frame containing the count of the observed variables (matching the names of the provided as data in the PLN function)
typeScale used for the prediction. Either
link(default, predicted positions in the latent space) orresponse(predicted counts).var_parBoolean. Should new estimations of the variational parameters of mean and variance be sent back, as attributes of the matrix of predictions. Default to
FALSE.envirEnvironment in which the prediction is evaluated
Returns
A matrix with predictions scores or counts.
Method show()
User friendly print method
Usage
PLNfit$show(
model = paste("A multivariate Poisson Lognormal fit with", self$vcov_model,
"covariance model.\n")
)Arguments
modelFirst line of the print output
Method print()
User friendly print method
Usage
PLNfit$print()
Method clone()
The objects of this class are cloneable with this method.
Usage
PLNfit$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
Examples
## Not run:
data(trichoptera)
trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate)
myPLN <- PLN(Abundance ~ 1, data = trichoptera)
class(myPLN)
print(myPLN)
## End(Not run)