Skip to contents

coef() returns the fixed-effect point estimates; vcov() returns their covariance matrix, taken from the fit's TMB sdreport().

Usage

# S3 method for class 'gllvmTMB_multi'
coef(object, ...)

# S3 method for class 'gllvmTMB_multi'
vcov(object, ...)

Arguments

object

A fitted multivariate model returned by gllvmTMB().

...

Ignored, present for S3 consistency.

Value

coef(): a named numeric vector, one entry per fixed-effect term (object$X_fix_names).

vcov(): a square numeric matrix with those same names on both margins. Rows and columns for coefficients held fixed via Xcoef_fixed are NA – a fixed parameter was not estimated, so it has no sampling covariance.

Point estimates need no standard errors

coef() works on any fit, including one made with gllvmTMBcontrol(se = FALSE) – point estimates are this package's supported claim and do not depend on sdreport(). vcov() does depend on it, and raises the same typed errors confint() does when it is missing (gllvmTMB_confint_no_sdreport) or non-finite (gllvmTMB_confint_nonfinite_se), naming standard_errors() as the remedy in the first case. The conditions are shared deliberately: a caller that handles one should handle the other.

What this covariance is

The fixed-effect block of the single TMB sdreport() the fit already carries – a Wald covariance, with exactly the caveats any Wald quantity from this package carries. It is not a resampled or profiled quantity, and no interval built from it has certified coverage. vcov() refuses a fit with non-unit likelihood weights: that fit targets a weighted estimating objective and has no certified sandwich covariance.

See also

standard_errors() to compute the sdreport() after fitting; confint() for intervals; summary() for a coefficient table.

Examples

## Simulate 40 sites, each visited twice. Four traits share one latent
## site axis, each trait also has its own site-level variation, and
## three of them respond to temperature.
set.seed(2)
n_site <- 40
dat <- data.frame(
  site = factor(rep(seq_len(n_site), each = 2)),
  temp = rnorm(2 * n_site)
)
z <- rnorm(n_site)                # latent site scores
lambda <- c(0.9, 0.7, 0.6, -0.5)  # loadings on that axis
slope <- c(0.5, 0, -0.3, 0.2)     # true temperature effects
for (j in 1:4) {
  site_eff <- lambda[j] * z + rnorm(n_site, sd = 0.6)
  dat[[paste0("y", j)]] <- slope[j] * dat$temp +
    site_eff[dat$site] + rnorm(nrow(dat), sd = 0.5)
}

fit <- gllvmTMB(
  traits(y1, y2, y3, y4) ~ 1 + temp +
    latent(1 | site, d = 1, unique = TRUE),
  data = dat, family = gaussian(), unit = "site"
)

## coef(): the fixed effects only -- an intercept and a temperature
## slope for each trait. Loadings and variances are not included.
coef(fit)
#>      traity1      traity2      traity3      traity4 traity1:temp traity2:temp 
#>   0.08552877   0.24793317   0.11304890   0.09116777   0.38923248   0.06571131 
#> traity3:temp traity4:temp 
#>  -0.24442357   0.24721701 

## vcov(): the covariance of those estimates. It is read from the
## standard-error step (TMB's sdreport()) that gllvmTMB() runs by
## default. A fit made with gllvmTMBcontrol(se = FALSE) skips that
## step: coef() still works there, but vcov() stops until you run
## fit <- standard_errors(fit).
V <- vcov(fit)
## The intercepts of different traits covary, because the traits share
## site effects; the temperature slopes barely covary.
round(V, 3)
#>              traity1 traity2 traity3 traity4 traity1:temp traity2:temp
#> traity1        0.040   0.017   0.019  -0.016        0.000        0.000
#> traity2        0.017   0.024   0.011  -0.010        0.000        0.000
#> traity3        0.019   0.011   0.025  -0.011        0.000        0.000
#> traity4       -0.016  -0.010  -0.011   0.018        0.000        0.000
#> traity1:temp   0.000   0.000   0.000   0.000        0.004        0.000
#> traity2:temp   0.000   0.000   0.000   0.000        0.000        0.004
#> traity3:temp   0.000   0.000   0.000   0.000        0.000        0.000
#> traity4:temp   0.000   0.000   0.000   0.000        0.000        0.000
#>              traity3:temp traity4:temp
#> traity1             0.000        0.000
#> traity2             0.000        0.000
#> traity3             0.000        0.000
#> traity4             0.000        0.000
#> traity1:temp        0.000        0.000
#> traity2:temp        0.000        0.000
#> traity3:temp        0.004        0.000
#> traity4:temp        0.000        0.004

## The square roots of the diagonal are the Wald standard errors shown
## by summary(fit). Intervals built from them are approximate; their
## coverage is not certified.
sqrt(diag(V))
#>      traity1      traity2      traity3      traity4 traity1:temp traity2:temp 
#>   0.19904952   0.15373715   0.15851182   0.13481023   0.06382101   0.06310660 
#> traity3:temp traity4:temp 
#>   0.06263114   0.06108775