Creates a fixed group-level covariance kernel for use with random_effects_formula(). The kernel is a random-effect design property: it describes covariance across grouping levels and is separate from column-level random-effect covariance structures such as random_covariance(). The associated fitted block scale remains the public sd quantity (with var as its square). It multiplies the supplied kernel; it is not an sd_mult. Consequently, when an unscaled kernel has a non-unit diagonal, the fitted sd need not equal every grouping level's marginal standard deviation.

Before fitting, the kernel is restricted to the fitted grouping levels and transformed according to scale. Its positive definiteness must be resolvable at working precision. Validation uses correlation units and preserves the chosen scaled kernel; unresolved near-singular kernels are unavailable.

random_group_covariance(covariance, scale = c("cor", "none", "cor0", "cov0"))

Arguments

covariance

numeric square matrix with row and column names identifying grouping levels. Columns are aligned to the supplied row-name order before checking symmetry or completing a single supplied triangle. A partial triangle is interpreted in that row order: column permutations are allowed, but row permutations that scatter entries across both triangles can be refused. Complete symmetric matrices allow independent axis permutations.

scale

how to scale the kernel before fitting. "cor" converts the reordered matrix to a correlation matrix, "none" uses the matrix as supplied, "cor0" forms C = stats::cov2cor(K) and applies (C - min(C)) / (1 - min(C)), and "cov0" applies K - min(K).

Value

A random_group_covariance object.