Skip to contents

Fit response-column-specific random intercepts and/or slopes with source covariance K_rho = rho * K + (1 - rho) * diag(diag(K)). Supply a numeric rho in [0, 1] to fix the mixture or use rho = NULL (the default) to estimate one interior value. The supplied labelled dense kernel retains its marginal scale. The fitted covariance across the coefficient basis is full for | and diagonal for ||.

Usage

kernel_coef(formula, K, name = "kernel", rho = NULL)

Arguments

formula

A coefficient-basis bar expression such as 1 + x | trait, 0 + x | trait, or 1 + x || trait.

K

A labelled dense numeric positive-definite covariance matrix whose row and column names exactly match the response columns.

name

One non-empty name for the kernel source.

rho

NULL to estimate one interior source-strength value, or one numeric value in [0, 1] to fix it.

Value

A formula marker; never evaluated directly.

Details

This point-model route is covered for Gaussian multivariate data in long or traits(...) wide form, with one dense positive-definite kernel and bare numeric row predictors. Interval inference, non-Gaussian coefficient models, simultaneous coefficient sources, and sparse kernel inputs are not available. Existing kernel_slope() remains current and warning-free.

A no-intercept rho = 1 fit uses the released kernel_slope() route exactly and therefore uses raw K without the dense phylogenetic ridge.

Examples

set.seed(4)
dat <- expand.grid(unit = factor(1:12), trait = factor(paste0("sp", 1:4)))
dat$x <- rnorm(12)[dat$unit]
dat$value <- rnorm(nrow(dat))
K <- 0.4 ^ abs(outer(1:4, 1:4, "-"))
dimnames(K) <- list(levels(dat$trait), levels(dat$trait))
fit <- gllvmTMB(value ~ 1 + kernel_coef(1 + x | trait, K = K, rho = 0.5),
  data = dat, trait = "trait", unit = "unit", family = gaussian(),
  control = gllvmTMBcontrol(se = FALSE), silent = TRUE)
extract_Sigma(fit, level = "column_coef")
#> $Sigma
#>              (Intercept)          x
#> (Intercept) 0.0005871454 0.00495747
#> x           0.0049574702 0.04185765
#> 
#> $R
#>             (Intercept)         x
#> (Intercept)   1.0000000 0.9999997
#> x             0.9999997 1.0000000
#> 
#> $level
#> [1] "column_coef"
#> 
#> $part
#> [1] "dep"
#> 
#> $basis
#> [1] "(Intercept)" "x"          
#> 
#> $source
#> $source$type
#> [1] "kernel"
#> 
#> $source$grouping
#> [1] "trait"
#> 
#> $source$labels
#> [1] "sp1" "sp2" "sp3" "sp4"
#> 
#> $source$name
#> [1] "kernel"
#> 
#> $source$scale
#> [1] "as_supplied"
#> 
#> 
#> $rho
#> [1] 0.5
#> 
#> $rho_status
#> [1] "fixed"
#> 
#> $K_rho
#>       sp1  sp2  sp3   sp4
#> sp1 1.000 0.20 0.08 0.032
#> sp2 0.200 1.00 0.20 0.080
#> sp3 0.080 0.20 1.00 0.200
#> sp4 0.032 0.08 0.20 1.000
#> 
#> $note
#> [1] "Response-column coefficient covariance; the response-column source supplies the other Kronecker factor."
#>