predict_cond: Predict counts conditionally

View source: R/PLNfit-S3methods.R

predict_condR Documentation

Predict counts conditionally

Description

Predict counts of a new sample conditionally on a (set of) observed variables

Usage

predict_cond(
  object,
  newdata,
  cond_responses,
  type = c("link", "response"),
  var_par = FALSE
)

## S3 method for class 'PLNfit'
predict_cond(
  object,
  newdata,
  cond_responses,
  type = c("link", "response"),
  var_par = FALSE
)

Arguments

object

an R6 object with class PLNfit

newdata

A data frame in which to look for variables and offsets with which to predict

cond_responses

a data frame containing the counts of the observed variables (matching the names provided as data in the PLN function)

type

The type of prediction required. The default is on the scale of the linear predictors (i.e. log average count)

var_par

Boolean. Should new estimations of the variational parameters of mean and variance be sent back, as attributes of the matrix of predictions. Default to FALSE.

Value

A list containing:

pred

A matrix of predicted log-counts (if type = "link") or predicted counts (if type = "response")

M

A matrix containing E(Z_uncond | Y_c) for each given site.

S

A matrix containing Var(Z_uncond | Y_c) for each given site (sites are the third dimension of the array)

Methods (by class)

  • predict_cond(PLNfit): Predict counts of a new sample conditionally on a (set of) observed variables for a PLNfit

Examples

data(trichoptera)
trichoptera_prep <- prepare_data(trichoptera$Abundance, trichoptera$Covariate)
myPLN <- PLN(Abundance ~ Temperature + Wind, trichoptera_prep)
#Condition on the set of the first two species in the dataset (Hym, Hys) at the ten first sites
Yc <- trichoptera$Abundance[1:10, c(1, 2), drop=FALSE]
newX <- cbind(1, trichoptera$Covariate[1:10, c("Temperature", "Wind")])
pred <- predict_cond(myPLN, newX, Yc, type = "response")

PLN-team/PLNmodels documentation built on Oct. 13, 2024, 4:01 a.m.