Per-Position Marginal OLS Regression of `Y` on Each Column of `X`
Source:R/univariate_regression.R
compute_marginal_bhat_shat.RdComputes the marginal OLS regression coefficient and standard error for each `(X column, Y column)` pair, treating the regressions as independent. `X` is assumed column-centred (no intercept term in the per-pair regression); each `Y` column is treated independently. Returns the J x T matrices `Bhat` and `Shat`.
Used internally by single-effect-regression style routines that need a per-position marginal estimate. Vectorised across columns of `Y` so callers can pass either a numeric vector (T = 1) or a numeric matrix (T > 1) without looping at the call site.
Arguments
- X
numeric matrix `n x J`, expected column-centred.
- Y
numeric matrix `n x T` or numeric vector of length `n`. When a vector, is treated as a one-column matrix.
- predictor_weights
optional numeric vector of length `J` giving `colSums(X^2)`. Computed internally when `NULL`. Callers that have this cached on the data object pass it through to avoid recomputation.
- sigma2
optional numeric scalar giving a known residual variance. When supplied, `Shat[j, t] = sqrt(sigma2 / predictor_weights[j])` (single-effect-residual form). When `NULL`, `Shat` is the per-pair empirical residual standard error: for each `(j, t)` pair, the sample SD of `Y[, t] - X[, j] * Bhat[j, t]` divided by `sqrt(n - 1)`. The latter matches the form used by data-driven prior init routines (e.g., for fitting a normal-mixture prior via `ashr::ash`).