lv_correlations: Calculate trend correlations based on latent factor loadings...

View source: R/lv_correlations.R

lv_correlationsR Documentation

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)

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.

Value

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

See Also

residual_cor(), plot.mvgam_residcor()

Examples


# 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 using lv_correlations()
lvcors <- lv_correlations(mod)
names(lvcors)
lapply(lvcors, class)

# The above works, but it is now recommended to use the more
# flexible and informative residual_cor() function to
# calculate and work with these correlations
lvcors <- residual_cor(mod)
names(lvcors)
lvcors$cor

# For those correlations whose credible intervals did not include
# zero, plot them as a correlation matrix (all other correlations
# are shown as zero on this plot)
plot(lvcors, cluster = TRUE)




nicholasjclark/mvgam documentation built on April 17, 2025, 9:39 p.m.