predict.species_mix: Predict a species_mix model.

predict.species_mixR Documentation

Predict a species_mix model.

Description

Predict species archetypes from a species_mix model. You can also predict the conditional species predictions using "prediction.type='species'".

Usage

## S3 method for class 'species_mix'
predict(
  object,
  object2 = NULL,
  newdata = NULL,
  offset = NULL,
  nboot = 0,
  alpha = 0.95,
  mc.cores = 1,
  type = "response",
  prediction.type = "archetype",
  na.action = "na.pass",
  ...
)

Arguments

object

is a matrix model returned from the species_mix model.

object2

is a species mix bootstrap object.

newdata

a matrix of new observations for prediction.

offset

an offset for prediction

nboot

Number of bootstraps (or simulations if using IPPM) to run if no object2 is provided.

alpha

confidence level. default is 0.95

mc.cores

number of cores to use in prediction. default is 1.

type

Do you want to predict the 'response' or the 'link'; ala glm style predictions.

prediction.type

Do you want to produce 'archetype' or 'species' level predictions. default is 'archetype'.

na.action

The type of action to apply to NA data. Default is "na.pass" see predict.lm for more details.

\dots

Ignored

Examples


library(ecomix)
set.seed(42)
sam_form <- stats::as.formula(paste0('cbind(',paste(paste0('spp',1:20),
collapse = ','),")~x1+x2"))
sp_form <- ~ 1
beta <- matrix(c(-2.9,-3.6,-0.9,1,.9,1.9),3,2,byrow=TRUE)
dat <- data.frame(y=rep(1,100),x1=stats::runif(100,0,2.5),
x2=stats::rnorm(100,0,2.5))
dat[,-1] <- scale(dat[,-1])
simulated_data <- species_mix.simulate(archetype_formula = sam_form,species_formula = sp_form,
data = dat,beta=beta,family="bernoulli")
fm1 <- species_mix(archetype_formula = sam_form,species_formula = sp_form,
data = simulated_data, family = 'bernoulli',  nArchetypes=3)
preds_fm1 <- predict(fm1)


skiptoniam/ecomix documentation built on Sept. 14, 2023, 6:04 a.m.