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.
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
new()Initialize a PLNfit model
PLNfit$new(responses, covariates, offsets, weights, formula, control)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().
update()Update a PLNfit object
PLNfit$update(
B = NA,
Sigma = NA,
Omega = NA,
M = NA,
S = NA,
Ji = NA,
R2 = NA,
Z = NA,
A = NA,
monitoring = NA
)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
Update the current PLNfit object
optimize()Call to the NLopt or TORCH optimizer and update of the relevant fields
PLNfit$optimize(responses, covariates, offsets, weights, config)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 control argument which configures the optimizer
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.
PLNfit$optimize_vestep(
covariates,
offsets,
responses,
weights,
B = self$model_par$B,
Omega = self$model_par$Omega,
control = PLN_param(backend = "nlopt")
)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
A list with three components:
the matrix M of variational means,
the matrix S2 of variational variances
the vector log.lik of (variational) log-likelihood of each new observation
postTreatment()Update R2, fisher and std_err fields after optimization
PLNfit$postTreatment(
responses,
covariates,
offsets,
weights = rep(1, nrow(responses)),
config_post,
config_optim,
nullModel = NULL
)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.
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.
sandwich_var boolean indicating whether sandwich estimator should be computed to estimate the variance of the model parameters (highly underestimated). Default is FALSE.
trace integer for verbosity. should be > 1 to see output in post-treatments
predict()Predict position, scores or observations of new data.
PLNfit$predict(
newdata,
responses = NULL,
type = c("link", "response"),
level = 1,
envir = parent.frame()
)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) or response (predicted counts).
levelOptional integer value the level to be used in obtaining the predictions. Level zero corresponds to the population predictions (default if responses is 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
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
A matrix with predictions scores or counts.
predict_cond()Predict position, scores or observations of new data, conditionally on the observation of a (set of) variables
PLNfit$predict_cond(
newdata,
cond_responses,
type = c("link", "response"),
var_par = FALSE,
envir = parent.frame()
)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) or response (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
A matrix with predictions scores or counts.
show()User friendly print method
PLNfit$show(
model = paste("A multivariate Poisson Lognormal fit with", self$vcov_model,
"covariance model.\n")
)modelFirst line of the print output
clone()The objects of this class are cloneable with this method.
PLNfit$clone(deep = FALSE)deepWhether to make a deep clone.
if (FALSE) {
data(trichoptera)
trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate)
myPLN <- PLN(Abundance ~ 1, data = trichoptera)
class(myPLN)
print(myPLN)
}
Run the code above in your browser using DataLab