View source: R/bias.test.custom.R
| bias.test.custom | R Documentation |
Summarize the alignment of fitted random effects with the weights of a fixed-effect estimate or contrast, following Karl and Zimmerman (2021). This internal diagnostic addresses one contribution to bias; it does not estimate the complete repeated-sampling bias or provide a bias correction.
bias.test.custom(
result,
k_vectors = NULL,
n_perms = 1e+05,
plot = TRUE,
verbose = TRUE
)
result |
A fitted |
k_vectors |
A numeric contrast vector, or a list of such vectors.
Each vector must have one finite coefficient per column of |
n_perms |
Positive integer number of random permutations for each
contrast. The default is |
plot |
Logical; display the permutation histograms and their combined
plot. Histogram objects are returned even when |
verbose |
Logical; print progress and the results table. |
For a contrast k, the observed diagnostic is \nu'\hat\eta, with
\nu' = k'(X'V^{-1}X)^{-1}X'V^{-1}Z.
Here X and Z are the fixed- and random-effects design matrices,
V is the fitted marginal covariance, and \hat\eta is the vector
of predicted random effects.
Write A = (X'V^{-1}X)^{-1}X'V^{-1} for the fitted GLS weights.
Under y = X\beta + Z\eta + \epsilon, the pointwise identity is
k'(\hat\beta-\beta) = k'AZ\eta + k'A\epsilon.
Expectations therefore give a random-effects contribution and a residual
contribution C_k = E[k'A\epsilon]. Covariance fitting makes A
depend on the response, so mean-zero errors independent of the design do
not, by themselves, imply C_k=0. The returned diagnostic substitutes
predicted effects for \eta in the first contribution and omits
C_k. Shrinkage and estimation also separate this plug-in value from
the expectation of the first contribution. For random X, the
pointwise identity still holds for full-rank realized designs, but its
expectation must use the specified joint law of the designs and effects.
None of these expectations is identified from a single fitted model alone.
Teacher effects are permuted among teachers from the same originating year. For generalized and reduced generalized persistence models, each teacher's whole vector of current and future effects moves together, preserving the within-teacher covariance structure. Random student intercepts in G-side models are permuted separately among students. This block permutation specializes the diagnostic to GPvam's covariance structure; it does not implement the rank-based sampler in Karl and Zimmerman (2021).
The main directional summary is Permutation_Percentile, on a scale
from 0 to 100. It is 100 times the proportion of simulated diagnostics below
the observed diagnostic, plus half the proportion tied with it (a midrank
convention). Thus a completely degenerate distribution has percentile 50.
Numerical ties use a tolerance of 16 machine epsilons times the largest
absolute observed or simulated diagnostic. Small and large percentiles
indicate the lower and upper tails, respectively; this percentile is not
a p-value. Permutation_Mean reports the Monte Carlo reference mean.
Inspect it together with the signed diagnostic: the reference distribution
need not be centered at zero. Percentiles can be 0 or 100 with finite
simulation and do not establish zero tail probability.
The reported two-sided Monte Carlo p-value is
(1+B)/(1+\mathtt{n\_perms}), where B counts permutations whose
absolute diagnostic is at least as large as the observed value. Including
the observed arrangement avoids zero p-values from a finite random sample
of permutations (Phipson and Smyth, 2010). Because covariance parameters
and random effects are estimated, these are approximate fitted-model
diagnostics, not exact finite-sample tests of fixed-effect bias. Fitted
predictions can have different precisions and need not be exchangeable
even when the latent teacher effects are exchangeable. The absolute-value
tail probability is measured about zero, not the reference mean; retain
the signed diagnostic, percentile and reference mean when interpreting it.
Permutations use R's current random-number generator. Call
set.seed() before the diagnostic to reproduce the results.
A list with:
permutation_results |
A data frame with columns |
plot_list |
A list of |
simulate_bias implements this conditional response-refit
experiment for every supported GPvam persistence/student-side structure.
It requires the original input data and a current converged fitted object.
A simulation that includes the residual contribution must generate a new
response and re-estimate the covariance parameters in each replication.
For a specified generating \beta, retain the generated vectors
Z\eta and \epsilon. After refitting, calculate k'AZ\eta
and k'A\epsilon; their sum must equal the simulated estimation error.
Average each component and report its Monte Carlo standard error, together
with convergence failures. The internal diagnostic k'AZ\hat\eta
can be recorded separately but cannot replace the generated latent term.
Holding the fitted designs and predicted teacher effects fixed and drawing
errors from a chosen residual covariance gives a conditional plug-in
sensitivity analysis. It does not recover an unknown classroom-assignment
mechanism or establish the unconditional bias. To examine stochastic or
endogenous covariates or assignments, generate their joint relationship
with the latent effects before generating responses and refitting.
Increasing n_perms only improves the existing permutation reference;
it does not carry out these simulations or estimate C_k.
In custom simulations use result$observation to align generated
observation-level vectors with the internal fitting order, and inspect
result$converged before using a refit. With response-dependent
persistence estimates, distinguish the generating random-effect design
from the design estimated in the refit.
Karl, A. and Zimmerman, D. (2021). A diagnostic for bias in linear mixed model estimators induced by dependence between the random effects and the corresponding model matrix. Journal of Statistical Planning and Inference 211, 107–118. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1016/j.jspi.2020.06.004")}. Corrected author preprint: https://arxiv.org/abs/2003.08087.
Phipson, B. and Smyth, G. K. (2010). Permutation P-values Should Never Be Zero: Calculating Exact P-values When Permutations Are Randomly Drawn. Statistical Applications in Genetics and Molecular Biology 9(1), Article 39. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.2202/1544-6115.1585")}.
GPvam
data(vam_data)
result <- GPvam(vam_data, persistence = "CP",
fixed_effects = ~ as.factor(year) + cont_var + 0,
verbose = FALSE)
set.seed(2026)
bias <- bias.test.custom(result, k_vectors = c(0, 0, 0, 1),
n_perms = 999, plot = FALSE, verbose = FALSE)
bias$permutation_results
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.