# \donttest{
data("Bird.parasites")
# Generate boxplots of model predictive metrics
cv_MRF_diag(data = Bird.parasites, n_nodes = 4,
n_cores = 1, family = 'binomial')
# Generate boxplots comparing the CRF to an MRF model (no covariates)
cv_MRF_diag(data = Bird.parasites, n_nodes = 4,
n_cores = 1, family = 'binomial',
compare_null = TRUE)
# Replicate 10-fold cross-validation 10 times
cv.preds <- cv_MRF_diag_rep(data = Bird.parasites, n_nodes = 4,
n_cores = 1, family = 'binomial',
compare_null = TRUE,
plot = FALSE, n_fold_runs = 10)
# Plot model sensitivity and % true predictions
library(ggplot2)
gridExtra::grid.arrange(
ggplot(data = cv.preds, aes(y = mean_sensitivity, x = model)) +
geom_boxplot() + theme(axis.text.x = ggplot2::element_blank()) +
labs(x = ''),
ggplot(data = cv.preds, aes(y = mean_tot_pred, x = model)) +
geom_boxplot(),
ncol = 1,
heights = c(1, 1))
# Create some sample Poisson data with strong correlations
cov <- rnorm(500, 0.2)
cov2 <- rnorm(500, 1)
sp.2 <- rpois(500, lambda = exp(1.5 + (cov * 0.9)))
poiss.dat <- data.frame(sp.1 = rpois(500, lambda = exp(0.5 + (cov * 0.3))),
sp.2 = sp.2,
sp.3 = rpois(500, lambda = exp(log(sp.2 + 1) + (cov * -0.5))),
cov = cov,
cov2 = cov2)
# A CRF should produce a better fit (lower deviance, lower MSE)
cvMRF.poiss <- cv_MRF_diag(data = poiss.dat, n_nodes = 3,
n_folds = 10,
family = 'poisson',
compare_null = TRUE, plot = TRUE)
# }
Run the code above in your browser using DataLab