if (FALSE) {
#--------------------------------------------------
# Fit a model that uses two AR(1) dynamic factors to model
# the temporal dynamics of the four rodent species in the portal_data
#--------------------------------------------------
mod <- mvgam(
captures ~ series,
trend_model = AR(),
use_lv = TRUE,
n_lv = 2,
data = portal_data,
chains = 2,
silent = 2
)
# Plot the two dynamic factors
plot(mod, type = 'factors')
# Calculate correlations among the series
lvcors <- lv_correlations(mod)
names(lvcors)
lapply(lvcors, class)
# Recommended: use residual_cor() instead
lvcors <- residual_cor(mod)
names(lvcors)
lvcors$cor
# Plot credible correlations as a matrix
plot(lvcors, cluster = TRUE)
# Not needed for general use; cleans up connections for automated testing
closeAllConnections()
}
Run the code above in your browser using DataLab