Learn R Programming

gllvm (version 2.0.5)

goodnessOfFit: Goodness of fit measures for a gllvm

Description

Several goodness-of-fit measure are currently available and can be calculated for a gllvm model fit and predicted values.

Usage

goodnessOfFit(
  y = NULL,
  pred = NULL,
  object = NULL,
  measure = c("cor", "RMSE", "MAE", "MARNE"),
  species = FALSE
)

Arguments

y

a response matrix

pred

predicted values for response matrix y

object

an object of class 'gllvm'.

measure

a goodness-of-fit measure to be calculated. Options are "cor" (correlation between observed and predicted values), "scor" (Spearman correlation between observed and predicted values), "RMSE" (root mean squared error of prediction), "MAE" (Mean Absolute Error), "MARNE" (Mean Absolute Range Normalized Error), "TjurR2" (Tjur's R2 measure, only for binary data), "R2" (R-squared as the square of the correlation) and "sR2" (R-squared as the square of the spearman correlation)

species

logical, if TRUE, goodness-of-fit measures are calculated for each species separately. If FALSE, goodness-of-fit measures are calculated for all species together.

Author

Jenni Niku <jenni.m.e.niku@jyu.fi>

Details

goodnessOfFit is used for evaluating the goodness-of-fit of a model or predictions. Available goodness-of-fit measures are correlation, RMSE, MARNE, and R2 measures. Definitions are below. Denote an observed response j (species) at sample i, \(i=1,...,n\), as \(y_{ij}\), and predicted value as \(\hat y_{ij}\).

$$RMSE(\boldsymbol{y_{j}}, \boldsymbol{\hat y_{j}}) = \sqrt{\frac{1}{n}\Sigma_{i=1}^{n} {(y_{ij} - \hat y_{ij})^2}} $$

$$MAE(\boldsymbol{y_{j}}, \boldsymbol{\hat y_{j}}) = \frac{1}{n}\Sigma_{i=1}^{n} |y_{ij} - \hat y_{ij}| $$

$$MARNE(\boldsymbol{y_{j}}, \boldsymbol{\hat y_{j}}) = \frac{1}{n}\Sigma_{i=1}^{n} \frac{|y_{ij} - \hat y_{ij}|}{max(\boldsymbol{y_{j}}) - min(\boldsymbol{y_{j}})} $$

$$Tjur's R2(\boldsymbol{y_{j}}, \boldsymbol{\hat y_{j}}) = \frac{1}{n_1}\Sigma \hat y_{ij}\boldsymbol{1}_{y=1}(y_{ij}) - \frac{1}{n_0}\Sigma \hat y_{ij}\boldsymbol{1}_{y=0}(y_{ij}) $$

See Also

gllvm, predict.gllvm

Examples

Run this code
if (FALSE) {
# Fit gllvm model with Poisson family
data(microbialdata)
X <- microbialdata$Xenv
y <- microbialdata$Y[, order(colMeans(microbialdata$Y > 0), 
                     decreasing = TRUE)[21:40]]
fit <- gllvm(y, X, formula = ~ pH + Phosp, family = poisson())
# Calculate metrics
goodnessOfFit(object = fit, measure = c("cor", "RMSE"))

}

Run the code above in your browser using DataLab