
Linear Mixed Model Inference for KK Designs with Continuous Response
Source:R/inference_continuous_KK_glmm.R
InferenceContinKKGLMM.RdFits 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.
| Procedure | Regime | Error order | Effective n | Regularity | Basis | References |
rand | finite sample | exact | pairs + reservoir | regular | theory | [Fisher1935], [LehmannRomano2005] |
wald | asymptotic | unknown | pairs + reservoir | variance component | unknown | [SelfLiang1987], [StramLee1994] |
jackknife | asymptotic | unknown | pairs + reservoir | variance component | unknown | [SelfLiang1987], [StramLee1994] |
score | asymptotic | unknown | pairs + reservoir | variance component | unknown | [SelfLiang1987], [StramLee1994] |
lik_ratio | asymptotic | unknown | pairs + reservoir | variance component | unknown | [SelfLiang1987], [StramLee1994] |
gradient | asymptotic | unknown | pairs + reservoir | variance component | unknown | [SelfLiang1987], [StramLee1994] |
lik_ratio_bartlett_approx | asymptotic | unknown | pairs + reservoir | variance component | unknown | [SelfLiang1987], [StramLee1994] |
lik_ratio_bartlett_exact | asymptotic | unknown | pairs + reservoir | variance component | unknown | [SelfLiang1987], [StramLee1994] |
param_boot | asymptotic | unknown | pairs + reservoir | variance component | unknown | [SelfLiang1987], [StramLee1994] |
param_boot_direct | asymptotic | unknown | pairs + reservoir | variance component | unknown | [SelfLiang1987], [StramLee1994] |
bootstrap | asymptotic | unknown | pairs + reservoir | variance component | unknown | [SelfLiang1987], [StramLee1994] |
bayes_boot | asymptotic | unknown | pairs + reservoir | variance component | unknown | [SelfLiang1987], [StramLee1994] |
rand_bootstrap | asymptotic | unknown | pairs + reservoir | variance component | unknown | [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
Inference$capabilities()Inference$clear_randomization_cache()Inference$compute_exact_confidence_interval()Inference$compute_exact_two_sided_pval_for_treatment_effect()Inference$duplicate()Inference$get_analysis_data()Inference$get_covariates()Inference$get_design_object()Inference$get_estimand()Inference$get_model_formula()Inference$get_nonestimable_reason()Inference$get_nonestimable_stage()Inference$get_optimization_alg()Inference$get_procedure_validity()Inference$get_response()Inference$get_response_type()Inference$get_summary()Inference$get_supported_estimands()Inference$get_treatment()Inference$is_nonestimable()Inference$set_estimand()Inference$set_optimization_alg()Inference$set_seed()Inference$supports()
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_objA completed
Designobject with a continuous response.model_formulaOptional 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_rcppLogical. If
TRUE(default), use the optimized Rcpp Gaussian LMM implementation (no external package required). IfFALSE, use glmmTMB.use_gls_fast_pathLogical. If
TRUE(default), use a fast GLS estimator (no optimization) forestimate_onlycalls 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. SetFALSEto always run full L-BFGS.use_gls_fast_path_bootstrapLogical. If
TRUE, also use the fast GLS estimator for non-studentized bootstrap draws (estimate_only = TRUEweighted calls). Asymptotically valid by the plug-in principle (VC orthogonal to beta_T in the Fisher information), but not exact in finite samples. DefaultFALSE.verboseWhether to print progress messages.
smart_cold_start_defaultWhether to use smart cold start values.
optimization_algThe 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.
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
)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.
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.
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
# }