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

# S3 method for 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

# \donttest{ 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")
#> Random alpha from normal (-1,0.5) distribution
fm1 <- species_mix(archetype_formula = sam_form,species_formula = sp_form, data = simulated_data, family = 'bernoulli', nArchetypes=3)
#> SAM modelling
#> There are 3 archetypes to group the species into
#> There are 100 site observations for 20 species
#> The model for the archetype (grouping) is ~x1 + x2
#> The model for the species is ~1
#> You are implementing a bernoulli Species Archetype Model.
#> Using ECM algorithm to find starting values; using 1 refits
#> ECM restart 1 of 1
#> Initialising starting values
#> Initial groups parameter estimates by K-means clustering
#> Iteration: 1 | New loglik -950.729 | Ratio loglik 0
#> Iteration: 2 | New loglik -829.843 | Ratio loglik 0.872849
#> Iteration: 3 | New loglik -820.246 | Ratio loglik 0.988434
#> Iteration: 4 | New loglik -819.839 | Ratio loglik 0.999504
#> initial value 819.837658 #> iter 10 value 819.706575 #> final value 819.703416 #> converged
preds_fm1 <- predict(fm1) # }