vcov.species_mix: Estimate the Variance-covariance matrix for a species_mix...

vcov.species_mixR Documentation

Estimate the Variance-covariance matrix for a species_mix object.

Description

Calculates variance-covariance matrix from a species_mix object

Usage

## S3 method for class 'species_mix'
vcov(
  object,
  object2 = NULL,
  method = "BayesBoot",
  nboot = 10,
  mc.cores = 1,
  ...
)

Arguments

object

an object obtained from fitting a RCP (for region of common profile) mixture model. Such as that generated from a call to species_mix(qv).

object2

an object of class species_mix containing bootstrap samples of the parameter estimates (see species_mix_boot(qv)). If NULL (default) the bootstrapping is performed from within the vcov function. If not null, then the vcov estimate is obtained from these bootstrap samples.

method

the method to calculate the variance-covariance matrix. Options are:'FiniteDifference' (default), BayesBoot, SimpleBoot, and EmpiricalInfo. The two bootstrap methods (BayesBoot and SimpleBoot, see species_mix_boot(qv)) should be more general and may possibly be more robust. The EmpiricalInfo method implements an empirical estimate of the Fisher information matrix, I can not recommend it however. It seems to behave poorly, even in well behaved simulations. It is computationally thrifty though.

nboot

the number of bootstrap samples to take for the bootstrap estimation. Argument is ignored if !method %in% c(FiniteDifference,'EmpiricalInfo').

mc.cores

the number of cores to distribute the calculations on. Default is 4. Set to 1 if the computer is running Windows (as it cannot handle forking – see mclapply(qv)). Ignored if method=='EmpiricalInfo'.

\dots

Ignored

Details

If method is FiniteDifference, then the estimates variance matrix is based on a finite difference approximation to the observed information matrix. If method is either "BayesBoot" or "SimpleBoot", then the estimated variance matrix is calculated from bootstrap samples of the parameter estimates. See Foster et al (in prep) for details of how the bootstrapping is actually done, and species_mix_boot(qv) for its implementation.

Value

A square matrix of size equal to the number of parameters. It contains the variance matrix of the parameter estimates.

Examples


# Estimate the variance-covariance matrix.
# This will provide estimates of uncertainty for model parameters.

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)
vcov(fm1)

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