computePredictedValues {Hmsc}R Documentation

computePredictedValues

Description

Computes predicted values from the fitted Hmsc model

Usage

computePredictedValues(
  hM,
  partition = NULL,
  partition.sp = NULL,
  start = 1,
  thin = 1,
  Yc = NULL,
  mcmcStep = 1,
  expected = TRUE,
  initPar = NULL,
  nParallel = 1,
  nChains = length(hM$postList),
  updater = list(),
  verbose = hM$verbose,
  alignPost = TRUE
)

pcomputePredictedValues(
  hM,
  partition = NULL,
  partition.sp = NULL,
  start = 1,
  thin = 1,
  Yc = NULL,
  mcmcStep = 1,
  expected = TRUE,
  initPar = NULL,
  nParallel = 1,
  useSocket = .Platform$OS.type == "windows",
  nChains = length(hM$postList),
  updater = list(),
  verbose = nParallel == 1,
  alignPost = TRUE
)

Arguments

hM

a fitted Hmsc model object

partition

partition vector for cross-validation created by createPartition

partition.sp

species partitioning vector for conditional cross-validation

start

index of first MCMC sample included

thin

thinning interval of posterior distribution

Yc

response matrix on which the predictions are to be conditioned

mcmcStep

number of MCMC steps used to make conditional predictions

expected

whether expected values (TRUE) or realizations (FALSE) are to be predicted

initPar

a named list of parameter values used for initialization of MCMC states

nParallel

number of parallel processes by which the chains are executed

nChains

number of independent MCMC chains to be run

updater

a named list, specifying which conditional updaters should be omitted

verbose

the interval between MCMC steps printed to the console

alignPost

boolean flag indicating whether the posterior of each chains should be aligned

useSocket

(logical) use socket clusters in parallel processing; these can be used in all operating systems, but they are usually slower than forking which can only be used in non-Windows operating systems (macOS, Linux, unix-like systems).

Details

There are two alternative functions computePredictedValues and pcomputePredictedValues. Function pcomputePredictedValues uses more aggressive parallelization and can be much faster when partition is used. Function computePredictedValues can run chains of each sampleMcmc partition in parallel, but pcomputePredictedValues can run each partition fold times chain in parallel (if hardware and operating systems permit). Function pcomputePredictedValues is still experimental, and therefore we provide both the old and new functions, but the old functions is scheduled to be removed in the future. Species partitions are not yet parallelized, and they can be very slow, especially with many mcmcSteps.

If the option partition is not used, the posterior predictive distribution is based on the model fitted to the full data. If the option partition is used but partition.sp is not used, the posterior predictive distribution is based on cross-validation over the sampling units. If partition.sp is additionally used, then, when predictions are made for each fold of the sampling units, the predictions are done separately for each fold of species. When making the predictions for one fold of species, the predictions are conditional on known occurrences (those observed in the data) of the species belonging to the other folds. If partition.sp is used, the parameter mcmcStep should be set high enough to obtain appropriate conditional predictions. The option Yc can be used alternatively to partition.sp if the conditioning is to be done based on a fixed set of data (independently of which sampling unit and species the predictions are made for).

Value

an array of model predictions, made for each posterior sample

See Also

predict.Hmsc

Examples

# Compute predicted values using a previously fitted HMSC model
preds = computePredictedValues(TD$m)

## Not run: 
# Compute predicted values for a previously fitted HMSC model using 2 folds
partition = createPartition(TD$m, nfolds = 2)
predsCV1 = computePredictedValues(TD$m,partition=partition)

# Compute conditional predictions for a previously fitted HMSC model using 2 folds
partition = createPartition(TD$m, nfolds = 2)
predsCV2 = computePredictedValues(TD$m, partition = partition,
partition.sp = 1:TD$m$ns, mcmcStep = 100)

## End(Not run)


[Package Hmsc version 3.0-13 Index]