Skip to contents

Compute borrowed variance from successful model fits

Usage

compute_borrowed_variance(modelDF, method = c("sigma", "vcov"))

Arguments

modelDF

tibble from model_analyse

method

"sigma" borrows scalar sigma and uses per-protein (X'X)^-1, "vcov" borrows element-wise median of full vcov matrices

Value

list with sigma, df, method, and optionally vcov

Examples

mod <- sim_build_models_lm(model = "parallel3", weight_missing = 1)
#> creating sampleName from fileName column
#> completing cases
#> completing cases done
#> setup done
#> Joining with `by = join_by(protein_Id)`

# Sigma method (default): returns median sigma and df from donors
borrowed_s <- prolfqua:::compute_borrowed_variance(
  mod$modelDF, method = "sigma")
stopifnot(borrowed_s$method == "sigma")
stopifnot(is.numeric(borrowed_s$sigma) && borrowed_s$sigma > 0)
stopifnot(is.numeric(borrowed_s$df) && borrowed_s$df > 0)

# Vcov method: element-wise median vcov from donors.
# Falls back to sigma if donor models have different coefficient counts.
mod_no_missing <- sim_build_models_lm(model = "parallel3",
  Nprot = 10, with_missing = FALSE)
#> creating sampleName from fileName column
#> completing cases
#> completing cases done
#> setup done
#> Joining with `by = join_by(protein_Id)`
borrowed_v <- prolfqua:::compute_borrowed_variance(
  mod_no_missing$modelDF, method = "vcov")
stopifnot(borrowed_v$method == "vcov")
stopifnot(is.matrix(borrowed_v$vcov))