Adjust a functional response for covariate effects
Source:R/adjust_covariates.R
mf_adjust_for_covariates.RdReturns Y_adjusted = Y - Z %*% fitted_func where fitted_func
is a K x T matrix of per-position covariate effects fit by one
of two methods:
Usage
mf_adjust_for_covariates(
Y,
Z,
X = NULL,
method = c("wavelet_eb", "ols"),
wavelet_basis_order = 10L,
wavelet_family = "DaubLeAsymm",
max_iter = 50L,
tol = 0.001,
null_prior_weight = 10,
init_pi0_w = 1,
control_mixsqp = list(verbose = FALSE, eps = 1e-06, numiter.em = 4L),
grid_mult = sqrt(2),
wavelet_magnitude_cutoff = 0
)Arguments
- Y
n x Tnumeric matrix; the functional response.Tmust be a power of two formethod = "wavelet_eb".- Z
n x Knumeric matrix; covariates to adjust away.- X
optional
n x pnumeric matrix; the genotype matrix to FWL-residualize. DefaultNULL.- method
"wavelet_eb"(default) or"ols".- wavelet_basis_order
integer, selects the wavelet basis member within
wavelet_family(number of vanishing moments for Daubechies families). Forwarded towavethresh::wd'sfilter.number. Default10L.- wavelet_family
character, the
familyargument towd. Default"DaubExPhase".- max_iter
integer, maximum outer iterations for the wavelet-EB path. Default
50.- tol
numeric, convergence tolerance on the per-scale prior weights
||pi - pi_prev|| / log(K) < tol. Default1e-3.- null_prior_weight
numeric, penalty on the null component (passed through to the EB prior init). Default
10.- init_pi0_w
numeric, starting null-component mass for mixsqp. Default
1.- control_mixsqp
optional named list of
mixsqpcontrol args. Defaultlist(verbose = FALSE, eps = 1e-6, numiter.em = 4L).- grid_mult
numeric, multiplier for the ash mixture grid. Default
sqrt(2).- wavelet_magnitude_cutoff
non-negative numeric. Wavelet columns whose
median(|column|)is at or below this cutoff are zeroed and treated as uninformative (Bhat = 0,Shat = 1) at every outer iteration. Default0.
Value
A named list with:
Y_adjustedn x Tmatrix, the residualized response.X_adjustedn x pmatrix whenXwas supplied, elseNULL.fitted_funcK x Tmatrix of fitted covariate effects.sigma2numeric, residual variance estimate.
niterinteger, number of outer iterations (wavelet-EB only).
convergedlogical, convergence status (wavelet-EB only).
methodcharacter, the method used.
Details
"wavelet_eb"(default): wavelet-domain empirical-Bayes regression with a per-scale mixture-of-normals prior. Suitable when the covariate effects are smooth functions of position."ols": closed-form Frisch-Waugh-Lovell residualization. The no-shrinkage limit of the wavelet-EB path; suitable when the covariate effects can vary arbitrarily across positions.
When X is supplied, the function also returns
X_adjusted = (I - Z (Z'Z)^{-1} Z') X to handle covariate-
genotype correlation. Upstream covariate-adjustment workflows
typically do not residualize X; the option is provided for
downstream fine-mapping users who need it.