predict.gllvm: Predict Method for gllvm Fits

Description Usage Arguments Details Value Author(s) Examples

View source: R/predict.gllvm.R

Description

Obtains predictions from a fitted generalized linear latent variable model object.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## S3 method for class 'gllvm'
predict(
  object,
  newX = NULL,
  newTR = NULL,
  newLV = NULL,
  type = "link",
  level = 1,
  ...
)

Arguments

object

an object of class 'gllvm'.

newX

A new data frame of environmental variables. If omitted, the original matrix of environmental variables is used.

newTR

A new data frame of traits for each response taxon. If omitted, the original matrix of traits is used.

newLV

A new matrix of latent variables. If omitted, the original matrix of latent variables is used.

type

the type of prediction required. The default ("link") is on the scale of the linear predictors; the alternative "response" is on the scale of the response variable. that is, the predictions for the binomial model are predicted probabilities. In case of ordinal data, type = "response" gives predicted probabilities for each level of ordinal variable.

level

specification for how to predict. Level one attempts to use the predicted site scores from variational approximations of laplace approximation. Level 0 sets the latent variable to zero instead. Defaults to 1.

...

not used.

Details

If newX, newTR and newLV are omitted the predictions are based on the data used for fitting the model. Notice that newTR need to match with the number of species in the original data. Instead, new sites can be specified in newX. If predictors newX (and newTR) are given, and newLV is not, latent variables are not used in the predictions.

Value

A matrix containing requested predictor types.

Author(s)

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Load a dataset from the mvabund package
data(antTraits)
y <- as.matrix(antTraits$abund)
X <- scale(antTraits$env[, 1:3])
# Fit gllvm model
fit <- gllvm(y = y, X, family = poisson())
# fitted values
predfit <- predict(fit, type = "response")

# linear predictors
predlin <- predict(fit)
# Predict new sites:
# Generate matrix of environmental variables for 10 new sites
xnew <- cbind(rnorm(10), rnorm(10), rnorm(10))
colnames(xnew) <- colnames(X)
predfit <- predict(fit, newX = xnew, type = "response", level = 0)

TR <- (antTraits$tr[, 1:3])
fitt <- gllvm(y = y, X, TR, family = poisson())
# linear predictors
predlin <- predict(fitt)
# Predict new sites:
# Generate matrix of environmental variables for 10 new sites
xnew <- cbind(rnorm(10), rnorm(10), rnorm(10))
colnames(xnew) <- colnames(X)
# Generate matrix of traits for species
trnew <- data.frame(Femur.length = rnorm(41), No.spines = rnorm(41),
 Pilosity = factor(sample(0:3, 41, replace = TRUE)))
predfit <- predict(fitt, newX = xnew, newTR = trnew, type = "response", level = 0)

gllvm documentation built on July 29, 2021, 1:06 a.m.