The function PLNPCA() produces a collection of models which are instances of object with class PLNPCAfit.
This class comes with a set of methods, some of them being useful for the user:
See the documentation for the methods inherited by PLNfit and the plot() methods for PCA visualization
PLNmodels::PLNfit -> PLNPCAfit
rankthe dimension of the current model
nb_paramnumber of parameters in the current PLN model
entropyentropy of the variational distribution
latent_posa matrix: values of the latent position vector (Z) without covariates effects or offset
model_para list with the matrices associated with the estimated parameters of the pPCA model: Theta (covariates), Sigma (latent covariance) and B (latent loadings)
percent_varthe percent of variance explained by each axis
corr_circlea matrix of correlations to plot the correlation circles
scoresa matrix of scores to plot the individual factor maps (a.k.a. principal components)
rotationa matrix of rotation of the latent space
eigdescription of the eigenvalues, similar to percent_var but for use with external methods
vara list of data frames with PCA results for the variables: coord (coordinates of the variables), cor (correlation between variables and dimensions), cos2 (Cosine of the variables) and contrib (contributions of the variable to the axes)
inda list of data frames with PCA results for the individuals: coord (coordinates of the individuals), cos2 (Cosine of the individuals), contrib (contributions of individuals to an axis inertia) and dist (distance of individuals to the origin).
callHacky binding for compatibility with factoextra functions
new()Initialize a PLNPCAfit object
PLNPCAfit$new(
rank,
responses,
covariates,
offsets,
weights,
formula,
xlevels,
control
)rankrank of the PCA (or equivalently, dimension of the latent space)
responsesthe matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily
covariatesdesign matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily
offsetsoffset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily
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
xlevelsnamed listed of factor levels included in the models, extracted from the formula in the upper-level call and used for predictions.
controla list for controlling the optimization. See details.
update()Update a PLNPCAfit object
PLNPCAfit$update(
Theta = NA,
Sigma = NA,
B = NA,
M = NA,
S2 = NA,
Z = NA,
A = NA,
Ji = NA,
R2 = NA,
monitoring = NA
)Thetamatrix of regression matrix
Sigmavariance-covariance matrix of the latent variables
Bmatrix of PCA loadings (in the latent space)
Mmatrix of mean vectors for the variational approximation
S2matrix of variance vectors for the variational approximation
Zmatrix of latent vectors (includes covariates and offset effects)
Amatrix of fitted values
Jivector of variational lower bounds of the log-likelihoods (one value per sample)
R2approximate R^2 goodness-of-fit criterion
monitoringa list with optimization monitoring quantities
Update the current PLNPCAfit object
optimize()Call to the C++ optimizer and update of the relevant fields
PLNPCAfit$optimize(responses, covariates, offsets, weights, control)responsesthe matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily
covariatesdesign matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily
offsetsoffset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily
weightsan optional vector of observation weights to be used in the fitting process.
controla list for controlling the optimization. See details.
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 (B, Theta). Intended to position new data in the latent space for further use with PCA.
PLNPCAfit$VEstep(
covariates,
offsets,
responses,
weights = rep(1, nrow(responses)),
control = list()
)covariatesdesign matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily
offsetsoffset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily
responsesthe matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily
weightsan optional vector of observation weights to be used in the fitting process.
controla list for controlling the optimization. See details.
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
project()Project new samples into the PCA space using one VE step
PLNPCAfit$project(newdata, control = list(), envir = parent.frame())newdataA data frame in which to look for variables, offsets and counts with which to predict.
controla list for controlling the optimization. See PLN() for details.
envirEnvironment in which the projection is evaluated
the named matrix of scores for the newdata, expressed in the same coordinate system as self$scores
setVisualization()Compute PCA scores in the latent space and update corresponding fields.
PLNPCAfit$setVisualization(scale.unit = FALSE)scale.unitLogical. Should PCA scores be rescaled to have unit variance
postTreatment()Update R2, fisher, std_err fields and set up visualization after optimization
PLNPCAfit$postTreatment(responses, covariates, offsets, weights, nullModel)responsesthe matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily
covariatesdesign matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily
offsetsoffset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily
weightsan optional vector of observation weights to be used in the fitting process.
nullModelnull model used for approximate R2 computations. Defaults to a GLM model with same design matrix but not latent variable.
compute_fisher()Safely compute the fisher information matrix (FIM)
PLNPCAfit$compute_fisher(type = c("wald", "louis"), X = NULL)typeapproximation scheme to compute the fisher information matrix. Either wald (default) or louis. type = "louis" results in smaller confidence intervals.
Xdesign matrix used to compute the FIM
a sparse matrix with sensible dimension names
plot_individual_map()Plot the factorial map of the PCA
PLNPCAfit$plot_individual_map(
axes = 1:min(2, self$rank),
main = "Individual Factor Map",
plot = TRUE,
cols = "default"
)axesnumeric, the axes to use for the plot when map = "individual" or "variable". Default it c(1,min(rank))
maincharacter. A title for the single plot (individual or variable factor map). If NULL (the default), an hopefully appropriate title will be used.
plotlogical. Should the plot be displayed or sent back as ggplot object
colsa character, factor or numeric to define the color associated with the individuals. By default, all individuals receive the default color of the current palette.
a ggplot graphic
plot_correlation_circle()Plot the correlation circle of a specified axis for a PLNLDAfit object
PLNPCAfit$plot_correlation_circle(
axes = 1:min(2, self$rank),
main = "Variable Factor Map",
cols = "default",
plot = TRUE
)axesnumeric, the axes to use for the plot when map = "individual" or "variable". Default it c(1,min(rank))
maincharacter. A title for the single plot (individual or variable factor map). If NULL (the default), an hopefully appropriate title will be used.
colsa character, factor or numeric to define the color associated with the variables. By default, all variables receive the default color of the current palette.
plotlogical. Should the plot be displayed or sent back as ggplot object
a ggplot graphic
plot_PCA()Plot a summary of the PLNPCAfit object
PLNPCAfit$plot_PCA(
nb_axes = min(3, self$rank),
ind_cols = "ind_cols",
var_cols = "var_cols",
plot = TRUE
)nb_axesscalar: the number of axes to be considered when map = "both". The default is min(3,rank).
ind_colsa character, factor or numeric to define the color associated with the individuals. By default, all variables receive the default color of the current palette.
var_colsa character, factor or numeric to define the color associated with the variables. By default, all variables receive the default color of the current palette.
plotlogical. Should the plot be displayed or sent back as ggplot object
a grob object
show()User friendly print method
PLNPCAfit$show()
clone()The objects of this class are cloneable with this method.
PLNPCAfit$clone(deep = FALSE)deepWhether to make a deep clone.
The function PLNPCA, the class PLNPCAfamily
data(trichoptera)
trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate)
myPCAs <- PLNPCA(Abundance ~ 1 + offset(log(Offset)), data = trichoptera, ranks = 1:5)
myPCA <- getBestModel(myPCAs)
class(myPCA)
print(myPCA)
Run the code above in your browser using DataLab