Learn R Programming

mvgam (version 1.1.594)

lv_correlations: Calculate trend correlations based on latent factor loadings for mvgam models

Description

This function uses factor loadings from a fitted dynamic factor mvgam model to calculate temporal correlations among series' trends.

Usage

lv_correlations(object)

Value

A list object containing the mean posterior correlations and the full array of posterior correlations.

Arguments

object

list object of class mvgam that used latent factors, either with use_lv = TRUE or by supplying a trend_map. See mvgam() for details and for an example.

Details

Although this function will still work, it is now recommended to use residual_cor() to obtain residual correlation information in a more user-friendly format that allows for a deeper investigation of relationships among the time series.

See Also

residual_cor(), plot.mvgam_residcor()

Examples

Run this code
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