Adds slope-only deviations across the response columns of a long-format
Gaussian model. If B is the response-column by predictor coefficient
matrix and Sigma is the fitted covariance among its predictor columns,
this helper uses
$$\mathrm{Cov}(\mathrm{vec}(B^\mathsf{T})) = I \otimes \Sigma.$$
Write x1 + x2 | trait for a full predictor covariance or
x1 + x2 || trait for a diagonal predictor covariance. Both spellings
give the same one-variance model when there is only one predictor. The
term never adds a random intercept; keep response-column intercepts in the
main formula with 0 + trait.
Examples
set.seed(1)
dat <- expand.grid(unit = factor(1:20), trait = factor(paste0("sp", 1:8)))
dat$lat <- rnorm(nrow(dat)); dat$temp <- rnorm(nrow(dat))
# Each response column has its own slopes on lat and temp.
b_lat <- rnorm(8, sd = 0.5); b_temp <- rnorm(8, sd = 0.3)
k <- as.integer(dat$trait)
dat$value <- 0.2 * k + b_lat[k] * dat$lat + b_temp[k] * dat$temp +
rnorm(nrow(dat), sd = 0.3)
# \donttest{
fit <- gllvmTMB(value ~ 0 + trait + slope(lat + temp | trait), data = dat,
trait = "trait", unit = "unit", family = gaussian())
extract_Sigma(fit, level = "column_slope")
#> $Sigma
#> lat temp
#> lat 0.24382368 0.05533166
#> temp 0.05533166 0.05792642
#>
#> $R
#> lat temp
#> lat 1.0000000 0.4655834
#> temp 0.4655834 1.0000000
#>
#> $level
#> [1] "column_slope"
#>
#> $part
#> [1] "dep"
#>
#> $source
#> $source$type
#> [1] "ordinary"
#>
#> $source$grouping
#> [1] "trait"
#>
#> $source$labels
#> [1] "sp1" "sp2" "sp3" "sp4" "sp5" "sp6" "sp7" "sp8"
#>
#>
#> $predictors
#> [1] "lat" "temp"
#>
#> $column_labels
#> [1] "sp1" "sp2" "sp3" "sp4" "sp5" "sp6" "sp7" "sp8"
#>
#> $note
#> [1] "Slope-only response-column coefficients from the ordinary source with a full predictor covariance. The response-column source covariance supplies the other Kronecker factor; this is not a trait-level Sigma."
#>
# }
