| cdef.gof | R Documentation |
A directed goodness-of-fit test for binary logistic regression whose direction
lives in covariate space (functions of the predictors) rather than in
fitted-probability space like def.gof. It projects the
standardized residuals onto a covariate-space basis (polynomials and pairwise
products, natural splines, or a combination that also includes
fitted-probability bends) and calibrates the quadratic form with the
Farrington estimation-adjusted projection, exactly as in def.gof. This
makes it sensitive to omitted interactions and to local / oscillatory
departures that fitted-probability grouping can miss.
cdef.gof(
object,
predicted_probs = NULL,
X = NULL,
basis = c("poly", "spline", "combined"),
method = c("satterthwaite", "imhof")
)
object |
A fitted binary logistic |
predicted_probs |
Numeric predicted probabilities; required when
|
X |
Design/covariate matrix (with or without an intercept column);
required when |
basis |
One of |
method |
One of |
Let \tilde r_i=(y_i-\hat p_i)/\sqrt{\hat p_i(1-\hat p_i)} be the
standardized residuals and Z a covariate-space basis matrix. The
statistic is S=(Z'\tilde r)'(Z'Z)^{-1}(Z'\tilde r), whose null
distribution is a weighted sum of \chi^2_1 variables with weights the
eigenvalues of (Z'Z)^{-1}Z'\Omega Z, where
\Omega=I-V^{1/2}X(X'VX)^{-1}X'V^{1/2} adjusts for estimating
\hat\beta. The p-value uses a Satterthwaite scaled-\chi^2
approximation (default) or Imhof's method (CompQuadForm). Rank-deficient
bases are reduced automatically.
A one-row data.frame with Test, Basis,
Test_Statistic, df, Method, and p_value.
Farrington, C. P. (1996). On Assessing Goodness of Fit of Generalized Linear Models to Sparse Data. JRSS-B 58(2), 349-360.
def.gof, ef.gof, run.all.gof.
set.seed(1)
n <- 600; x1 <- runif(n, -3, 3); x2 <- rnorm(n)
# truth has an omitted interaction; fit the additive model
y <- rbinom(n, 1, plogis(0.3 + 0.8 * x1 - 0.5 * x2 + 0.4 * x1 * x2))
fit <- glm(y ~ x1 + x2, family = binomial())
cdef.gof(fit) # covariate-space directed test (poly basis)
cdef.gof(fit, basis = "spline") # for local / oscillatory misfit
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.