Flattens the IV specification tests stored on a fitted model into a single
tibble, one row per test, so they can be filtered, joined, or printed like
any other tidyverse output instead of navigated as a nested list
(x$diagnostics$overid$stat and friends).
Value
A tibble::tibble() with one row per diagnostic test present on
the model and the following columns:
testCharacter. A stable machine-readable key, meant for
filter(test == ...)-style selection (e.g."overid","weak_id_robust","endogeneity").test_nameCharacter. The display name printed by
summary().statisticDouble. The test statistic, or — for the Stock-Yogo rows — the critical value rather than a statistic.
dfInteger. Degrees of freedom,
NAwhen not applicable.df2Integer. Denominator degrees of freedom,
NAunless the statistic is F-distributed.p_valueDouble.
NAwhen not defined (e.g. Stock-Yogo critical values, or an exactly identified overidentification row).tested_varsCharacter. The variable(s) tested; populated only for the endogeneity, orthogonality, and redundancy rows.
noteCharacter. A Stata-parity disclosure, or
NAwhen none applies. A note appears when an explicit option the user set is silently not honored inside an automatically computed diagnostic, matching Stata'sivreg2: a non-Bartlettkernelon the identification and redundancy tests (Stata'sranktesthard-codes Bartlett);kieferon the identification tests (the Kiefer VCE structure is dropped);psdon the identification and redundancy tests (ranktestnever receives it);centeron the endogeneity test; andmethod = "cue"(or"liml", for orthogonality) on the endogeneity and orthogonality C-statistics, which come from a recursive re-estimation that does not use those estimators. When more than one disclosure applies to the same test, the note column joins the sentences with a space; each note is a complete sentence, so splitting on sentence boundaries recovers the individual disclosures programmatically.
Rows appear only for the tests actually computed on the model: an IV
fit reports underidentification, weak identification,
overidentification, and — for every endogenous regressor, unless
narrowed to a subset via endog = — the endogeneity test by default,
while orthog = and redundant = add the corresponding orthogonality
and redundancy rows only when the user requests them.
The Stock-Yogo rows (keys of the form "sy_iv_size_10") report critical
values, not test statistics, so their p_value is always NA. An OLS
fit (single-part formula) has no diagnostics at all and returns a
zero-row tibble with the columns above.
The note column is unique to this accessor: tidy() and glance()
keep their numeric-only tidy semantics and carry no disclosure text, so
diagnostics() is the surface that exposes a note programmatically. The
same notes are printed by summary() as footnotes below the diagnostics
block.
Small-sample correction
the overidentification row
(Sargan/Hansen J) and the endogeneity row (C-statistic) are never
small-sample corrected, regardless of the main model's small argument.
The first-stage F-statistics are always small-sample corrected,
regardless of small; they are not columns of this tibble but are
reached via first_stage(). All three match Stata's ivreg2. See
ivreg2r-conventions for the full statement of which corrections
small controls.
See also
first_stage(), glance.ivreg2()
Other ivreg2 methods:
coef.ivreg2(),
confint.ivreg2(),
first_stage(),
fitted.ivreg2(),
formula.ivreg2(),
ivreg2(),
model.matrix.ivreg2(),
nobs.ivreg2(),
predict.ivreg2(),
print.ivreg2(),
print.summary.ivreg2(),
residuals.ivreg2(),
summary.ivreg2(),
terms.ivreg2(),
update.ivreg2(),
vcov.ivreg2()
Examples
data(card)
fit <- ivreg2(
lwage ~ exper + expersq + black + south | educ | nearc4 + nearc2,
data = card, vcov = "robust"
)
diagnostics(fit)
#> # A tibble: 12 × 8
#> test test_name statistic df df2 p_value tested_vars note
#> <chr> <chr> <dbl> <int> <int> <dbl> <chr> <chr>
#> 1 underid Kleiberg… 40.1 2 NA 1.98e- 9 NA NA
#> 2 weak_id Cragg-Do… 19.7 NA NA NA NA NA
#> 3 weak_id_robust Kleiberg… 20.4 NA NA NA NA NA
#> 4 sy_iv_size_10 Stock-Yo… 19.9 NA NA NA NA NA
#> 5 sy_iv_size_15 Stock-Yo… 11.6 NA NA NA NA NA
#> 6 sy_iv_size_20 Stock-Yo… 8.75 NA NA NA NA NA
#> 7 sy_iv_size_25 Stock-Yo… 7.25 NA NA NA NA NA
#> 8 overid Hansen J 1.86 1 NA 1.72e- 1 NA NA
#> 9 anderson_rubin_f Anderson… 27.9 2 3003 1.04e-12 NA NA
#> 10 anderson_rubin_c… Anderson… 55.8 2 NA 7.52e-13 NA NA
#> 11 stock_wright Stock-Wr… 54.0 2 NA 1.92e-12 NA NA
#> 12 endogeneity Endogene… 27.0 1 NA 2.04e- 7 educ NA