Analyses of Deviance Summarising Fits of Univariable GLMs
univ_anova.Rd
univ_anova()
provides a succinct summary of the analyses of deviance for all univariable GLMs based on each
possible categorical independent variable in a Bernoulli or binomial data set.
Usage
univ_anova(
data,
.dep_var,
.family = binomial,
.test = c("none", "Rao", "LRT", "Chisq", "F")
)
Arguments
- data
a data frame, or a data frame extension (e.g. a
tibble
).- .dep_var
<
data-masking
> quoted name of the binary dependent variable, which should benumeric
with values of 0 and 1, or a two-column matrix with the columns giving the numbers of successes and failures e.g.,cbind(pn, qn)
.- .family
a family function; default
"binomial"
. (Seefamily
for details of family functions.)- .test
a character string, (partially) matching one of
"none"
,"Chisq"
,"LRT"
,"Rao"
,"F"
or"Cp"
; default"none"
.
Value
An object of class c("univ_anova" "announce")
, inheriting from "anova"
and "data.frame"
as for add1()
,
summarising the differences between the fitted univariable GLMs and the null model.
Details
univ_anova()
uses add1()
in the stats package to compare univariable
GLMs for each possible categorical independent variable (i.e., "factor"
columns) in .data
with
the null model. Other data types e.g. "character"
vectors will be ignored and should be converted to
"factor"
to be included in this analysis.
Examples
(d <- list(
iv2 = list(g = c("a", "c", "e"), h = c("b", "d", "f")),
iv3 = list(i = c("a", "b", "c"), j = c("d", "e", "f")),
iv4 = list(k = c("a", "b"), l = c("c", "d"), m = c("e", "f"))
) |> add_grps(bernoulli_data(levels = 6), iv, .key = _))
#> ___________________________
#> Simulated Bernoulli Data: -
#>
#> # A tibble: 396 × 5
#> iv iv2 iv3 iv4 dv
#> <fct> <fct> <fct> <fct> <int>
#> 1 a g i k 1
#> 2 a g i k 0
#> 3 a g i k 0
#> 4 a g i k 1
#> 5 a g i k 1
#> 6 a g i k 0
#> 7 a g i k 1
#> 8 a g i k 0
#> 9 a g i k 1
#> 10 a g i k 1
#> # ℹ 386 more rows
d |> univ_anova(dv, .test = "LRT")
#> ___________________________________
#> Univariable Analysis of Deviance: -
#>
#> Single term additions
#>
#> Model:
#> dv ~ 1
#> Df Deviance AIC LRT Pr(>Chi)
#> <none> 477.19 479.19
#> iv 5 423.91 435.91 53.284 2.941e-10 ***
#> iv2 1 470.67 474.67 6.516 0.01069 *
#> iv3 1 432.95 436.95 44.241 2.903e-11 ***
#> iv4 2 433.06 439.06 44.125 2.620e-10 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
d |> binom_contingency(dv, starts_with("iv")) |> print() |>
univ_anova(cbind(pn, qn), .test = "LRT")
#> _____________________________
#> Binomial Contingency Table: -
#>
#> # A tibble: 6 × 6
#> iv iv2 iv3 iv4 pn qn
#> * <fct> <fct> <fct> <fct> <int> <int>
#> 1 a g i k 38 28
#> 2 b h i k 26 40
#> 3 c g i l 23 43
#> 4 d h j l 12 54
#> 5 e g j m 8 58
#> 6 f h j m 8 58
#> ___________________________________
#> Univariable Analysis of Deviance: -
#>
#> Single term additions
#>
#> Model:
#> cbind(pn, qn) ~ 1
#> Df Deviance AIC LRT Pr(>Chi)
#> <none> 53.284 80.822
#> iv 5 0.000 37.538 53.284 2.941e-10 ***
#> iv2 1 46.768 76.306 6.516 0.01069 *
#> iv3 1 9.043 38.580 44.241 2.903e-11 ***
#> iv4 2 9.159 40.696 44.125 2.620e-10 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
rm(d)