predict_MRF {MRFcov}R Documentation

Predict training observations from fitted MRFcov models

Description

This function calculates linear predictors for node observations using coefficients from an MRFcov or MRFcov_spatial object.

Usage

predict_MRF(
  data,
  MRF_mod,
  prep_covariates = TRUE,
  n_cores,
  progress_bar = FALSE
)

Arguments

data

Dataframe. The input data to be predicted, where the n_nodes left-most variables are are variables that are represented by nodes in the graph from the MRF_mod model. Colnames from this sample dataset must exactly match the colnames in the dataset that was used to fit the MRF_mod

MRF_mod

A fitted MRFcov or MRFcov_spatial model object

prep_covariates

Logical flag stating whether to prep the dataset by cross-multiplication (TRUE by default; FALSE when used in other functions)

n_cores

Positive integer stating the number of processing cores to split the job across. Default is 1 (no parallelisation)

progress_bar

Logical. Progress bar in pbapply is used if TRUE, but this slows estimation.

Details

Observations for nodes in data are predicted using linear predictions from MRF_mod. If family = "binomial", a second element containing binary predictions for nodes is returned. Note that predicting values for unobserved locations using a spatial MRF is not currently supported

Value

A matrix containing predictions for each observation in data. If family = "binomial", a second element containing binary predictions for nodes is returned.

References

Clark, NJ, Wells, K and Lindberg, O. Unravelling changing interspecific interactions across environmental gradients using Markov random fields. (2018). Ecology doi: 10.1002/ecy.2221 Full text here.

See Also

MRFcov, cv_MRF_diag

Examples


data("Bird.parasites")
# Fit a model to a subset of the data (training set)
CRFmod <- MRFcov(data = Bird.parasites[1:300, ], n_nodes = 4, family = "binomial")

# If covariates are included, prep the dataset for gathering predictions
prepped_pred <- prep_MRF_covariates(Bird.parasites[301:nrow(Bird.parasites), ], n_nodes = 4)

# Predict occurrences for the remaining subset (test set)
predictions <- predict_MRF(data = prepped_pred, MRF_mod = CRFmod)

# Visualise predicted occurrences for nodes in the test set
predictions$Binary_predictions

# Predicting spatial MRFs requires the user to supply the spatially augmented dataset
data("Bird.parasites")
Latitude <- sample(seq(120, 140, length.out = 100), nrow(Bird.parasites), TRUE)
Longitude <- sample(seq(-19, -22, length.out = 100), nrow(Bird.parasites), TRUE)
coords <- data.frame(Latitude = Latitude, Longitude = Longitude)
CRFmod_spatial <- MRFcov_spatial(data = Bird.parasites, n_nodes = 4,
                                family = 'binomial', coords = coords)
predictions <- predict_MRF(data = CRFmod_spatial$mrf_data,
                          prep_covariates  = FALSE,
                          MRF_mod = CRFmod_spatial)


[Package MRFcov version 1.0.39 Index]