predict_MRFnetworks: Extract predicted network metrics for observations in a given...

View source: R/predict_MRFnetworks.R

predict_MRFnetworksR Documentation

Extract predicted network metrics for observations in a given dataset using equations from a fitted MRFcov object

Description

This function uses outputs from fitted MRFcov and bootstrap_MRF models to generate linear predictions for each observation in data and calculate probabilistic network metrics from weighted adjacency matrices.

Usage

predict_MRFnetworks(
  data,
  MRF_mod,
  cutoff,
  omit_zeros,
  metric,
  cached_predictions = NULL,
  prep_covariates,
  n_cores,
  progress_bar = FALSE
)

Arguments

data

Dataframe. The sample data where the left-most variables are variables that are represented by nodes in the graph. 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 bootstrap_MRF object

cutoff

Single numeric value specifying the linear prediction threshold. Species whose linear prediction is below this level for a given observation in data will be considered absent, meaning they cannot participate in community networks. Default is 0.5 for family == 'binomial' or 0 for other families

omit_zeros

Logical. If TRUE, each species will not be considered to participate in community networks for observations in which that species was not observed in data. If FALSE, the species is still considered to have possibly occurred, based on the linear prediction for that observation. Default is FALSE

metric

The network metric to be calculated for each observation in data. Recognised values are : "degree", "eigencentrality", or "betweenness", or leave blank to instead return a list of adjacency matrices

cached_predictions

Use if providing stored predictions from predict_MRF to prevent unneccessary replication. Default is to calculate predictions first and then calculate network metrics

prep_covariates

Logical flag stating whether to prep the dataset by cross-multiplication (TRUE by default; use FALSE for predicting networks from MRFcov_spatial objects)

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

Interaction parameters are predicted for each observation in data and then converted into a weighted, undirected adjacency matrix using graph.adjacency. Note that the network is probabilistic, as node occurrences/abundances are predicted using fitted model equations from MRF_mod. If a linear prediction for a given observation falls below the user-specified cutoff, the node is considered absent from the community and cannot participate in the network. After correcting for the linear predictions, the specified network metric (degree centrality, eigencentrality, or betweenness) for each observation in data is then calculated and returned in a matrix. If metric is not supplied, the weighted, undirected adjacency matrices are returned in a list

Value

Either a matrix with nrow = nrow(data), containing each species' predicted network metric at each observation in data, or a list with length = nrow(data) containing the weighted, undirected adjacency matrix predicted at each observation in data

See Also

MRFcov, bootstrap_MRF, degree, eigen_centrality, betweenness

Examples

data("Bird.parasites")
CRFmod <- MRFcov(data = Bird.parasites, n_nodes = 4,
                family = "binomial")
predict_MRFnetworks(data = Bird.parasites[1:200, ],
                   MRF_mod = CRFmod, metric = "degree",
                   cutoff = 0.25)



MRFcov documentation built on April 6, 2023, 5:21 p.m.