Skip to contents

Wraps an lm object with borrowed covariance information. S3 generics vcov(), sigma(), and df.residual() dispatch to the borrowed values instead of the original model's.

Usage

new_lm_imputed(model, borrowed_vcov, borrowed_sigma, borrowed_df, n_observed)

Arguments

model

lm object fitted on imputed data

borrowed_vcov

matrix, borrowed variance-covariance matrix

borrowed_sigma

numeric, borrowed residual standard error

borrowed_df

numeric, borrowed residual degrees of freedom

n_observed

integer, number of non-imputed observations

Value

lm_imputed object

Examples

# Fit a normal lm, then wrap it with borrowed covariance
dat <- data.frame(group_ = rep(c("A", "B"), each = 4),
                  y = c(20.1, 20.5, 19.8, 20.3, 22.1, 22.4, 21.9, 22.2))
fit <- lm(y ~ group_, data = dat)

# Wrap with borrowed variance (in practice these come from donor pool)
wrapped <- prolfqua:::new_lm_imputed(fit,
  borrowed_vcov = vcov(fit),
  borrowed_sigma = 0.8,
  borrowed_df = 6,
  n_observed = 5)

# S3 dispatch returns borrowed values
stopifnot(inherits(wrapped, "lm_imputed"))
stopifnot(sigma(wrapped) == 0.8)
stopifnot(df.residual(wrapped) == 6)
# coefficients() still dispatches to underlying lm
stopifnot(identical(coefficients(wrapped), coefficients(fit)))