Skip to contents

Fits Lin's (2013) covariate-adjusted linear estimator for continuous responses: OLS of \(Y_i\) on \([1, W_i, X_i^c, W_i X_i^c]\), where \(X_i^c = X_i - \bar X\) are covariates centered at their sample means and \(W_i X_i^c\) are treatment-by-centered-covariate interactions (omitted when there are no covariates, reducing to plain OLS with \(\hat\beta_T\) the simple mean difference). Centering makes \(\hat\beta_T\) interpretable as the average treatment effect regardless of whether interactions are included, following the design-based reinterpretation of Freedman's critique of ANCOVA in randomized experiments. Standard errors use the HC2 heteroskedasticity-consistent (Huber-White-type) covariance estimator (ols_hc2_post_fit_cpp), not classical OLS SEs assuming homoskedasticity — this is the estimator Lin (2013) recommends since it remains conservative under treatment-effect heterogeneity, unlike the classical or HC0 sandwich variants. likelihood_tier = "full": Wald, score, gradient, and likelihood-ratio tests are all available, with the parametric-likelihood bootstrap using the OLS Gaussian-errors model (\(Y_i \mid x_i \sim N(x_i^\top \beta, \sigma^2)\)) as the generative null even though the design-based HC2 standard error does not itself assume homoskedastic Gaussian errors — the likelihood-ratio/score/gradient machinery is a secondary, model-based inference path alongside the primary HC2-Wald and randomization paths. Validity of \(\hat\beta_T\) as an average-treatment-effect estimator relies on randomization (of \(W\)), not on any particular outcome model; the working linear model need not be correctly specified.

References

Lin, W. (2013). "Agnostic notes on regression adjustments to experimental data: Reexamining Freedman's critique." The Annals of Applied Statistics, 7(1), 295-318, doi:10.1214/12-AOAS583 .

See also

InferenceContinOLS for the uncentered, non-interacted OLS estimator this class generalizes.

Super class

Inference -> InferenceContinLin

Methods

+ inherited public methods from Inference


InferenceContinLin$new()

Initialize inference for Lin's (2013) covariate-adjusted OLS estimator (intercept, treatment, centered covariates, and treatment-by-centered-covariate interactions); see InferenceContinLin for the model form. Does not fit the model; the fit is deferred to the first call to compute_estimate() or a method that requires it.

Usage

InferenceContinLin$new(
  des_obj,
  model_formula = NULL,
  verbose = FALSE,
  harden = TRUE,
  smart_cold_start_default = NULL
)

Arguments

des_obj

A completed Design object with a continuous response.

model_formula

Optional formula for covariate adjustment. If NULL (default), the formula from the design object is used and its pre-computed design matrix is reused. If a formula is provided, a new design matrix is constructed from the design's imputed covariates.

verbose

Whether to print progress messages.

harden

Flag for consistent API.

smart_cold_start_default

Flag for consistent API.


InferenceContinLin$compute_estimate()

Fits Lin's covariate-adjusted OLS model (stats's lm.fit on the centered-covariate design matrix) and returns \(\hat\beta_T\), the estimated average treatment effect. A design matrix that is rank-deficient or has fewer usable rows than columns, or a fit with non-finite coefficients, is cached as nonestimable rather than returned.

Usage

InferenceContinLin$compute_estimate(estimate_only = FALSE)

Arguments

estimate_only

If TRUE, skip HC2 variance computation and cache only the point estimate; used by randomization and bootstrap resampling paths.


InferenceContinLin$compute_estimate_with_bootstrap_weights()

Refits Lin's model with subject/block-level weights applied to a weighted least-squares fit (stats::lm.wfit) — Bayesian-bootstrap or nonparametric-bootstrap draw weights, expanded to row level via private$expand_subject_or_block_weights_to_row_weights() — and returns the reweighted estimate \(\hat\beta_T^{(w)}\). When estimate_only = FALSE, also computes a weighted-residual variance estimate (not the HC2 estimator used by compute_asymp_confidence_interval()) for internal bootstrap diagnostics. Rows with non-finite or non-positive weight, or non-finite response, are dropped from the weighted fit; if no rows remain, or the fit fails, the estimate is NA.

Usage

InferenceContinLin$compute_estimate_with_bootstrap_weights(
  subject_or_block_weights,
  estimate_only = FALSE
)

Arguments

subject_or_block_weights

Bootstrap weights at the subject or block level.

estimate_only

If TRUE, skip variance calculations.


InferenceContinLin$compute_asymp_confidence_interval()

Wald confidence interval for \(\beta_T\) using the HC2 heteroskedasticity-robust standard error (ols_hc2_post_fit_cpp); see InferenceAsymp for the shared \(t\)/\(z\) interval contract. Fits the model first if not already cached.

Usage

InferenceContinLin$compute_asymp_confidence_interval(alpha = 0.05)

Arguments

alpha

The confidence level. The default is 0.05.


InferenceContinLin$compute_asymp_two_sided_pval()

Two-sided Wald test of \(H_0: \beta_T = \code{delta}\) using the HC2 heteroskedasticity-robust standard error; see InferenceAsymp for the shared \(t\)/\(z\) test contract. Fits the model first if not already cached.

Usage

InferenceContinLin$compute_asymp_two_sided_pval(delta = 0)

Arguments

delta

The null treatment effect. Defaults to 0.


InferenceContinLin$clone()

The objects of this class are cloneable with this method.

Usage

InferenceContinLin$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

# \donttest{
seq_des = DesignSeqOneByOneBernoulli$new(n = 10, response_type = 'continuous')
for (i in 1:10) {
  seq_des$add_one_subject_to_experiment_and_assign(data.frame(x1 = rnorm(1)))
}
seq_des$add_all_subject_responses(rnorm(10))
inf = InferenceContinLin$new(seq_des)
inf$compute_estimate()
#> [1] 0.1163216
# }