Skip to contents

Fits a linear mixed model for continuous responses under a KK matching-on-the-fly design. The matched-pair strata enter as a subject-level random intercept (1 | group_id), accounting for within-pair correlation.

When use_rcpp = TRUE (default) the likelihood is maximised by an internal Rcpp/L-BFGS routine that requires no external packages. Set use_rcpp = FALSE to fall back to glmmTMB.

The treatment coefficient \(\beta_T\) is on the response's natural (untransformed) scale — a mean difference, not a ratio or log-scale effect. likelihood_tier = "full": with use_rcpp = TRUE, likelihood-ratio, score, and Wald tests are all available when the model converges (this class overrides $get_likelihood_test_spec() to supply the Rcpp likelihood); with the glmmTMB fallback (use_rcpp = FALSE) only the Wald test is available. Validity requires the random-intercept-per-pair structure to correctly capture the design's matching dependence and the usual linear mixed model assumptions (conditional normality of responses and pair effects, correctly specified fixed-effects formula).

Wald standard error. With use_rcpp = TRUE the Wald standard error is from the inverse of the full observed information (the analytic negative Hessian of the marginal log-likelihood in \((\beta, \log\sigma_e, \log\sigma_b)\) at the MLE), including the \(\beta\)-by-variance-parameter terms. It can be larger than the lme4::lmer(REML = FALSE) value, which conditions on the variance parameters (\((X^\top V^{-1} X)^{-1}\)); the two agree when \(\hat\sigma_b\) is away from 0 and differed by about 5% in a fit with \(\hat\sigma_b\) near 0. The score test uses the block-diagonal (expected) information instead. With the glmmTMB fallback the standard error is glmmTMB's. The same standard error is used by every Wald interval and p-value (compute_asymp_*() and compute_wald_*()) and by InferenceSuite's se column.

Small samples. With covariate adjustment at n = 50, the Wald test can reject a true null up to about 8.5% of the time at a nominal 5% level (intervals can cover as little as about 91.5%), since its normal reference is only an asymptotic approximation. The excess shrinks as n grows and is close to nominal by n = 200. With samples this small, use a larger sample or a randomization or bootstrap test.

Small-sample behaviour

How fast the size (and coverage) error of each procedure is expected to vanish as the effective sample size \(n_{eff}\) grows, from EDI's convergence-rate registry (inference_convergence_expectation()). Exact procedures are valid at every n by construction; the others are asymptotic, so a small-sample excess is expected, and its constant is not given by an order. The table is the expectation for a balanced complete-randomization design; it is not a measured size. Reference keys are explained under References.

ProcedureRegimeError orderEffective nRegularityBasisReferences
randfinite sampleexactpairs + reservoirregulartheory[Fisher1935], [LehmannRomano2005]
waldasymptoticunknownpairs + reservoirvariance componentunknown[SelfLiang1987], [StramLee1994]
jackknifeasymptoticunknownpairs + reservoirvariance componentunknown[SelfLiang1987], [StramLee1994]
scoreasymptoticunknownpairs + reservoirvariance componentunknown[SelfLiang1987], [StramLee1994]
lik_ratioasymptoticunknownpairs + reservoirvariance componentunknown[SelfLiang1987], [StramLee1994]
gradientasymptoticunknownpairs + reservoirvariance componentunknown[SelfLiang1987], [StramLee1994]
lik_ratio_bartlett_approxasymptoticunknownpairs + reservoirvariance componentunknown[SelfLiang1987], [StramLee1994]
lik_ratio_bartlett_exactasymptoticunknownpairs + reservoirvariance componentunknown[SelfLiang1987], [StramLee1994]
param_bootasymptoticunknownpairs + reservoirvariance componentunknown[SelfLiang1987], [StramLee1994]
param_boot_directasymptoticunknownpairs + reservoirvariance componentunknown[SelfLiang1987], [StramLee1994]
bootstrapasymptoticunknownpairs + reservoirvariance componentunknown[SelfLiang1987], [StramLee1994]
bayes_bootasymptoticunknownpairs + reservoirvariance componentunknown[SelfLiang1987], [StramLee1994]
rand_bootstrapasymptoticunknownpairs + reservoirvariance componentunknown[SelfLiang1987], [StramLee1994]

The point estimate's bias is of order \(O(n_{eff}^{-1})\) (assumed default: [CoxSnell1968]).

Rows with order unknown: no rate is known for this class and procedure, so none is claimed; the cited works describe the non-standard limit, not a rate. Expect a small-sample excess of unquantified size.

Regularity variance component: a random-effect variance near zero is a non-standard limit that affects the standard tests.

The procedure list is by declared capability; an object can still report a procedure (for example a Bartlett correction) as unavailable through get_supported_testing_types().

References

[Fisher1935] Fisher, R. A. (1935). The Design of Experiments. Oliver and Boyd.

[LehmannRomano2005] Lehmann, E. L., and Romano, J. P. (2005). Testing Statistical Hypotheses (3rd ed.). Springer.

[SelfLiang1987] Self, S. G., and Liang, K.-Y. (1987). "Asymptotic Properties of Maximum Likelihood Estimators and Likelihood Ratio Tests under Nonstandard Conditions." Journal of the American Statistical Association, 82(398), 605-610.

[StramLee1994] Stram, D. O., and Lee, J. W. (1994). "Variance Components Testing in the Longitudinal Mixed Effects Model." Biometrics, 50(4), 1171-1177.

[CoxSnell1968] Cox, D. R., and Snell, E. J. (1968). "A General Definition of Residuals." Journal of the Royal Statistical Society: Series B, 30(2), 248-265 (discussion 265-275).

See also

Comparable Python API: statsmodels MixedLM. See also: Mixed model (Wikipedia).

Super class

Inference -> InferenceContinKKGLMM

Methods

+ inherited public methods from Inference


InferenceContinKKGLMM$new()

Initialize inference for the linear mixed model \(Y_i = \beta_0 + \beta_T W_i + X_i^\top \gamma + b_{g(i)} + \epsilon_i\), \(b_g \sim N(0, \sigma_b^2)\), \(\epsilon_i \sim N(0, \sigma_e^2)\), where \(g(i)\) is subject \(i\)'s matched-pair group id, \(W_i\) is the treatment indicator, \(X_i\) are covariates, and \(\beta_T\) is the treatment effect (mean difference on the response's natural scale). The random intercept \(b_g\) absorbs the within-pair correlation induced by matching, so \(\beta_T\)'s standard error correctly reflects the design.

Usage

InferenceContinKKGLMM$new(
  des_obj,
  model_formula = NULL,
  use_rcpp = TRUE,
  use_gls_fast_path = TRUE,
  use_gls_fast_path_bootstrap = FALSE,
  verbose = FALSE,
  smart_cold_start_default = NULL,
  optimization_alg = 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.

use_rcpp

Logical. If TRUE (default), use the optimized Rcpp Gaussian LMM implementation (no external package required). If FALSE, use glmmTMB.

use_gls_fast_path

Logical. If TRUE (default), use a fast GLS estimator (no optimization) for estimate_only calls during randomisation inference once variance components are cached from a prior full fit. Statistically exact: fixing VC at the null-fit MLE and permuting only the treatment assignment gives a valid permutation test by exchangeability. Set FALSE to always run full L-BFGS.

use_gls_fast_path_bootstrap

Logical. If TRUE, also use the fast GLS estimator for non-studentized bootstrap draws (estimate_only = TRUE weighted calls). Asymptotically valid by the plug-in principle (VC orthogonal to beta_T in the Fisher information), but not exact in finite samples. Default FALSE.

verbose

Whether to print progress messages.

smart_cold_start_default

Whether to use smart cold start values.

optimization_alg

The optimization algorithm to use. Default is dispatched via policy.


InferenceContinKKGLMM$compute_estimate()

Fits the linear mixed model by maximum likelihood and returns \(\hat\beta_T\). When use_rcpp = TRUE (the default), the log-likelihood \(\ell(\beta, \sigma_b^2, \sigma_e^2)\) is maximized directly by an internal Rcpp/L-BFGS routine over \(\beta\) and the log-variance components; otherwise glmmTMB performs the fit. If use_gls_fast_path = TRUE and variance components are already cached from a prior full fit (used during randomization inference, where only the treatment column changes across permutations), estimate_only = TRUE calls instead solve the generalized least-squares problem at the cached variance components — exact under exchangeability of the permuted treatment assignment, since fixing the variance components at their null-fit MLE and permuting only \(W\) preserves the permutation test's validity.

Usage

InferenceContinKKGLMM$compute_estimate(estimate_only = FALSE)

Arguments

estimate_only

If TRUE, skip variance component calculations (standard error, degrees of freedom) needed for confidence intervals or p-values; only \(\hat\beta_T\) is returned.


InferenceContinKKGLMM$compute_estimate_with_bootstrap_weights()

Refits the linear mixed model with subject/block-level weights applied to each row's contribution to the likelihood (Bayesian-bootstrap or nonparametric-bootstrap draw weights, expanded from subject/block level to individual rows via private$expand_subject_or_block_weights_to_row_weights()), and returns the reweighted estimate \(\hat\beta_T^{(w)}\). When weights are effectively constant, this collapses to the unweighted compute_estimate() call and returns the unweighted estimate without refitting (the cached df is set to Inf and the cached summary table is cleared). When use_rcpp = TRUE, a weighted Rcpp fast path is tried first via private$weighted_rcpp_estimate(); otherwise private$compute_weighted_glmm_bootstrap_estimate() refits via glmmTMB-based machinery.

Usage

InferenceContinKKGLMM$compute_estimate_with_bootstrap_weights(
  subject_or_block_weights,
  estimate_only = FALSE
)

Arguments

subject_or_block_weights

Numeric vector of nonnegative weights, one per matched-pair group or reservoir subject (bootstrap draw weights), expanded to per-row weights before fitting.

estimate_only

Logical. If TRUE, skip standard-error computation.

Returns

The reweighted treatment estimate \(\hat\beta_T^{(w)}\).


InferenceContinKKGLMM$compute_asymp_confidence_interval()

Computes a \(1-\alpha\) confidence interval for \(\beta_T\) using the active testing type (see set_testing_type()). Under the default Wald type it uses the fitted-model standard error with a normal or \(t\) critical value depending on the resolved degrees of freedom; the score, gradient, likelihood-ratio and Bartlett-corrected types invert the matching test.

Usage

InferenceContinKKGLMM$compute_asymp_confidence_interval(alpha = 0.05)

Arguments

alpha

The confidence level of the interval is \(1 - \code{alpha}\). Default 0.05.


InferenceContinKKGLMM$compute_asymp_two_sided_pval()

Computes a two-sided p-value for \(H_0: \beta_T = \code{delta}\) using the active testing type (Wald by default; score, gradient, likelihood-ratio and Bartlett-corrected types are also supported), the same test that $compute_asymp_confidence_interval() inverts.

Usage

InferenceContinKKGLMM$compute_asymp_two_sided_pval(delta = 0)

Arguments

delta

The null treatment-effect value. Default 0.


InferenceContinKKGLMM$clone()

The objects of this class are cloneable with this method.

Usage

InferenceContinKKGLMM$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

# \donttest{
seq_des = DesignSeqOneByOneKK14$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), x2 = rnorm(1)))
}
seq_des$add_all_subject_responses(rnorm(10))
inf = InferenceContinKKGLMM$new(seq_des)
inf$compute_estimate()
#> [1] 0.3560926
# }