List of Summary and Analysis of Deviance Objects for Related Univariable GLMs
summanov.Rdsummanov() provides a list of the summary and analysis of deviance objects for a series of related univariable
GLMs of data with a binary dependent variable or a (two-column) dependent variable of binomial proportions.
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 to be used as the LHS of the model formula; should be numeric 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).- ...
<
tidy-select> quoted name(s) of one or more factors or character vectors in.data, to be included (or excluded) as independent variables in the list of GLM analyses.- .family
a description of the error distribution and link function to be used in the model. Can be a character string naming a family function, a family function or the result of a call to a family function; default
binomial.- .test
a character string, (partially) matching one of
"Chisq","LRT","Rao","F"or"Cp"; default"Chisq".
Value
A list of summ_anov objects of length equal to the number of factors or character vectors selected
using the ... arguments. A summ_anov object is simply a list with class "summ_anov", comprising the
following two elements: -
- summary
Summary of the generalised linear model fit given by
summary.glm.- anova
Analysis of deviance for the generalised linear model fit given by
anova.glm.
Details
Variables in .data to be included (or excluded) as independent variables in the list of GLM
analyses may be selected using the ... argument with the<tidy-select> syntax
of package dplyr, including use of selection helpers.
The structure of the output list may be changed from a list of pairs into pair of lists conveniently using
list_transpose. The univariable GLMs may then be easily compared and likewise
the univariable GLM anovas (analysis of deviance).
univ_anova provides a succinct summmary of the univariable analyses of deviance for all potential
categorical independent variables in data. anova_tbl also provides a succinct summmary from
the list of anovas.
See also
anova.glm(), list_transpose(), glm() and
summary.glm(); Print_Methods for S3 method for printing objects of class
"summ_anov".
Other comp_glm:
anova_tbl(),
comp_glm(),
univ_anova()
Examples
## Simulate Bernoulli data
(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 0
#> 2 a g i k 1
#> 3 a g i k 0
#> 4 a g i k 1
#> 5 a g i k 0
#> 6 a g i k 0
#> 7 a g i k 1
#> 8 a g i k 0
#> 9 a g i k 0
#> 10 a g i k 0
#> # ℹ 386 more rows
## Binary dependent variable
d |> summanov(dv, starts_with("iv"))
#> _______________________________________
#> GLM Summary and Analysis of Deviance: -
#>
#> $iv
#> ______________
#> GLM Summary: -
#>
#>
#> Call:
#> glm(formula = inject(!!.dep_var ~ !!sym(x)), family = .family,
#> data = data)
#>
#> Coefficients:
#> Estimate Std. Error z value Pr(>|z|)
#> (Intercept) -0.06062 0.24630 -0.246 0.805570
#> ivb 0.12125 0.34832 0.348 0.727764
#> ivc -0.37016 0.35231 -1.051 0.293416
#> ivd -0.77228 0.36387 -2.122 0.033802 *
#> ive -1.44345 0.40313 -3.581 0.000343 ***
#> ivf -2.98390 0.64015 -4.661 3.14e-06 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> (Dispersion parameter for binomial family taken to be 1)
#>
#> Null deviance: 496.90 on 395 degrees of freedom
#> Residual deviance: 439.34 on 390 degrees of freedom
#> AIC: 451.34
#>
#> Number of Fisher Scoring iterations: 5
#>
#> ____________
#> GLM Anova: -
#>
#> Analysis of Deviance Table
#>
#> Model: binomial, link: logit
#>
#> Response: dv
#>
#> Terms added sequentially (first to last)
#>
#>
#> Df Deviance Resid. Df Resid. Dev Pr(>Chi)
#> NULL 395 496.90
#> iv 5 57.565 390 439.34 3.868e-11 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> $iv2
#> ______________
#> GLM Summary: -
#>
#>
#> Call:
#> glm(formula = inject(!!.dep_var ~ !!sym(x)), family = .family,
#> data = data)
#>
#> Coefficients:
#> Estimate Std. Error z value Pr(>|z|)
#> (Intercept) -0.6035 0.1487 -4.060 4.91e-05 ***
#> iv2h -0.3022 0.2162 -1.398 0.162
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> (Dispersion parameter for binomial family taken to be 1)
#>
#> Null deviance: 496.90 on 395 degrees of freedom
#> Residual deviance: 494.94 on 394 degrees of freedom
#> AIC: 498.94
#>
#> Number of Fisher Scoring iterations: 4
#>
#> ____________
#> GLM Anova: -
#>
#> Analysis of Deviance Table
#>
#> Model: binomial, link: logit
#>
#> Response: dv
#>
#> Terms added sequentially (first to last)
#>
#>
#> Df Deviance Resid. Df Resid. Dev Pr(>Chi)
#> NULL 395 496.90
#> iv2 1 1.9615 394 494.94 0.1613
#>
#> $iv3
#> ______________
#> GLM Summary: -
#>
#>
#> Call:
#> glm(formula = inject(!!.dep_var ~ !!sym(x)), family = .family,
#> data = data)
#>
#> Coefficients:
#> Estimate Std. Error z value Pr(>|z|)
#> (Intercept) -0.1417 0.1425 -0.994 0.32
#> iv3j -1.3968 0.2345 -5.956 2.59e-09 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> (Dispersion parameter for binomial family taken to be 1)
#>
#> Null deviance: 496.90 on 395 degrees of freedom
#> Residual deviance: 458.21 on 394 degrees of freedom
#> AIC: 462.21
#>
#> Number of Fisher Scoring iterations: 3
#>
#> ____________
#> GLM Anova: -
#>
#> Analysis of Deviance Table
#>
#> Model: binomial, link: logit
#>
#> Response: dv
#>
#> Terms added sequentially (first to last)
#>
#>
#> Df Deviance Resid. Df Resid. Dev Pr(>Chi)
#> NULL 395 496.90
#> iv3 1 38.689 394 458.21 4.969e-10 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> $iv4
#> ______________
#> GLM Summary: -
#>
#>
#> Call:
#> glm(formula = inject(!!.dep_var ~ !!sym(x)), family = .family,
#> data = data)
#>
#> Coefficients:
#> Estimate Std. Error z value Pr(>|z|)
#> (Intercept) 5.085e-16 1.741e-01 0.000 1.0000
#> iv4l -6.257e-01 2.523e-01 -2.480 0.0131 *
#> iv4m -2.054e+00 3.248e-01 -6.324 2.55e-10 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> (Dispersion parameter for binomial family taken to be 1)
#>
#> Null deviance: 496.90 on 395 degrees of freedom
#> Residual deviance: 447.14 on 393 degrees of freedom
#> AIC: 453.14
#>
#> Number of Fisher Scoring iterations: 4
#>
#> ____________
#> GLM Anova: -
#>
#> Analysis of Deviance Table
#>
#> Model: binomial, link: logit
#>
#> Response: dv
#>
#> Terms added sequentially (first to last)
#>
#>
#> Df Deviance Resid. Df Resid. Dev Pr(>Chi)
#> NULL 395 496.90
#> iv4 2 49.764 393 447.14 1.562e-11 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
d |> summanov(dv, starts_with("iv") & !iv2)
#> _______________________________________
#> GLM Summary and Analysis of Deviance: -
#>
#> $iv
#> ______________
#> GLM Summary: -
#>
#>
#> Call:
#> glm(formula = inject(!!.dep_var ~ !!sym(x)), family = .family,
#> data = data)
#>
#> Coefficients:
#> Estimate Std. Error z value Pr(>|z|)
#> (Intercept) -0.06062 0.24630 -0.246 0.805570
#> ivb 0.12125 0.34832 0.348 0.727764
#> ivc -0.37016 0.35231 -1.051 0.293416
#> ivd -0.77228 0.36387 -2.122 0.033802 *
#> ive -1.44345 0.40313 -3.581 0.000343 ***
#> ivf -2.98390 0.64015 -4.661 3.14e-06 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> (Dispersion parameter for binomial family taken to be 1)
#>
#> Null deviance: 496.90 on 395 degrees of freedom
#> Residual deviance: 439.34 on 390 degrees of freedom
#> AIC: 451.34
#>
#> Number of Fisher Scoring iterations: 5
#>
#> ____________
#> GLM Anova: -
#>
#> Analysis of Deviance Table
#>
#> Model: binomial, link: logit
#>
#> Response: dv
#>
#> Terms added sequentially (first to last)
#>
#>
#> Df Deviance Resid. Df Resid. Dev Pr(>Chi)
#> NULL 395 496.90
#> iv 5 57.565 390 439.34 3.868e-11 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> $iv3
#> ______________
#> GLM Summary: -
#>
#>
#> Call:
#> glm(formula = inject(!!.dep_var ~ !!sym(x)), family = .family,
#> data = data)
#>
#> Coefficients:
#> Estimate Std. Error z value Pr(>|z|)
#> (Intercept) -0.1417 0.1425 -0.994 0.32
#> iv3j -1.3968 0.2345 -5.956 2.59e-09 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> (Dispersion parameter for binomial family taken to be 1)
#>
#> Null deviance: 496.90 on 395 degrees of freedom
#> Residual deviance: 458.21 on 394 degrees of freedom
#> AIC: 462.21
#>
#> Number of Fisher Scoring iterations: 3
#>
#> ____________
#> GLM Anova: -
#>
#> Analysis of Deviance Table
#>
#> Model: binomial, link: logit
#>
#> Response: dv
#>
#> Terms added sequentially (first to last)
#>
#>
#> Df Deviance Resid. Df Resid. Dev Pr(>Chi)
#> NULL 395 496.90
#> iv3 1 38.689 394 458.21 4.969e-10 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> $iv4
#> ______________
#> GLM Summary: -
#>
#>
#> Call:
#> glm(formula = inject(!!.dep_var ~ !!sym(x)), family = .family,
#> data = data)
#>
#> Coefficients:
#> Estimate Std. Error z value Pr(>|z|)
#> (Intercept) 5.085e-16 1.741e-01 0.000 1.0000
#> iv4l -6.257e-01 2.523e-01 -2.480 0.0131 *
#> iv4m -2.054e+00 3.248e-01 -6.324 2.55e-10 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> (Dispersion parameter for binomial family taken to be 1)
#>
#> Null deviance: 496.90 on 395 degrees of freedom
#> Residual deviance: 447.14 on 393 degrees of freedom
#> AIC: 453.14
#>
#> Number of Fisher Scoring iterations: 4
#>
#> ____________
#> GLM Anova: -
#>
#> Analysis of Deviance Table
#>
#> Model: binomial, link: logit
#>
#> Response: dv
#>
#> Terms added sequentially (first to last)
#>
#>
#> Df Deviance Resid. Df Resid. Dev Pr(>Chi)
#> NULL 395 496.90
#> iv4 2 49.764 393 447.14 1.562e-11 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
## Binomial proportions
(d <- d |> binom_contingency(dv, starts_with("iv")))
#> _____________________________
#> Binomial Contingency Table: -
#>
#> # A tibble: 6 × 6
#> iv iv2 iv3 iv4 pn qn
#> * <fct> <fct> <fct> <fct> <int> <int>
#> 1 a g i k 32 34
#> 2 b h i k 34 32
#> 3 c g i l 26 40
#> 4 d h j l 20 46
#> 5 e g j m 12 54
#> 6 f h j m 3 63
(uva <- d |> summanov(cbind(pn, qn), num_range("iv", 2:4)))
#> _______________________________________
#> GLM Summary and Analysis of Deviance: -
#>
#> $iv2
#> ______________
#> GLM Summary: -
#>
#>
#> Call:
#> glm(formula = inject(!!.dep_var ~ !!sym(x)), family = .family,
#> data = data)
#>
#> Coefficients:
#> Estimate Std. Error z value Pr(>|z|)
#> (Intercept) -0.6035 0.1487 -4.060 4.91e-05 ***
#> iv2h -0.3022 0.2162 -1.398 0.162
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> (Dispersion parameter for binomial family taken to be 1)
#>
#> Null deviance: 57.565 on 5 degrees of freedom
#> Residual deviance: 55.603 on 4 degrees of freedom
#> AIC: 85.066
#>
#> Number of Fisher Scoring iterations: 4
#>
#> ____________
#> GLM Anova: -
#>
#> Analysis of Deviance Table
#>
#> Model: binomial, link: logit
#>
#> Response: cbind(pn, qn)
#>
#> Terms added sequentially (first to last)
#>
#>
#> Df Deviance Resid. Df Resid. Dev Pr(>Chi)
#> NULL 5 57.565
#> iv2 1 1.9615 4 55.603 0.1613
#>
#> $iv3
#> ______________
#> GLM Summary: -
#>
#>
#> Call:
#> glm(formula = inject(!!.dep_var ~ !!sym(x)), family = .family,
#> data = data)
#>
#> Coefficients:
#> Estimate Std. Error z value Pr(>|z|)
#> (Intercept) -0.1417 0.1425 -0.994 0.32
#> iv3j -1.3968 0.2345 -5.955 2.6e-09 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> (Dispersion parameter for binomial family taken to be 1)
#>
#> Null deviance: 57.565 on 5 degrees of freedom
#> Residual deviance: 18.875 on 4 degrees of freedom
#> AIC: 48.338
#>
#> Number of Fisher Scoring iterations: 4
#>
#> ____________
#> GLM Anova: -
#>
#> Analysis of Deviance Table
#>
#> Model: binomial, link: logit
#>
#> Response: cbind(pn, qn)
#>
#> Terms added sequentially (first to last)
#>
#>
#> Df Deviance Resid. Df Resid. Dev Pr(>Chi)
#> NULL 5 57.565
#> iv3 1 38.689 4 18.875 4.969e-10 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> $iv4
#> ______________
#> GLM Summary: -
#>
#>
#> Call:
#> glm(formula = inject(!!.dep_var ~ !!sym(x)), family = .family,
#> data = data)
#>
#> Coefficients:
#> Estimate Std. Error z value Pr(>|z|)
#> (Intercept) 1.017e-16 1.741e-01 0.000 1.0000
#> iv4l -6.257e-01 2.523e-01 -2.480 0.0131 *
#> iv4m -2.054e+00 3.248e-01 -6.324 2.55e-10 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> (Dispersion parameter for binomial family taken to be 1)
#>
#> Null deviance: 57.5648 on 5 degrees of freedom
#> Residual deviance: 7.8004 on 3 degrees of freedom
#> AIC: 39.263
#>
#> Number of Fisher Scoring iterations: 4
#>
#> ____________
#> GLM Anova: -
#>
#> Analysis of Deviance Table
#>
#> Model: binomial, link: logit
#>
#> Response: cbind(pn, qn)
#>
#> Terms added sequentially (first to last)
#>
#>
#> Df Deviance Resid. Df Resid. Dev Pr(>Chi)
#> NULL 5 57.565
#> iv4 2 49.764 3 7.800 1.562e-11 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
## Change list of pairs into a pair of lists using {purrr} list_transpose()
list_transpose(uva)$summary
#> $iv2
#> ______________
#> GLM Summary: -
#>
#>
#> Call:
#> glm(formula = inject(!!.dep_var ~ !!sym(x)), family = .family,
#> data = data)
#>
#> Coefficients:
#> Estimate Std. Error z value Pr(>|z|)
#> (Intercept) -0.6035 0.1487 -4.060 4.91e-05 ***
#> iv2h -0.3022 0.2162 -1.398 0.162
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> (Dispersion parameter for binomial family taken to be 1)
#>
#> Null deviance: 57.565 on 5 degrees of freedom
#> Residual deviance: 55.603 on 4 degrees of freedom
#> AIC: 85.066
#>
#> Number of Fisher Scoring iterations: 4
#>
#>
#> $iv3
#> ______________
#> GLM Summary: -
#>
#>
#> Call:
#> glm(formula = inject(!!.dep_var ~ !!sym(x)), family = .family,
#> data = data)
#>
#> Coefficients:
#> Estimate Std. Error z value Pr(>|z|)
#> (Intercept) -0.1417 0.1425 -0.994 0.32
#> iv3j -1.3968 0.2345 -5.955 2.6e-09 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> (Dispersion parameter for binomial family taken to be 1)
#>
#> Null deviance: 57.565 on 5 degrees of freedom
#> Residual deviance: 18.875 on 4 degrees of freedom
#> AIC: 48.338
#>
#> Number of Fisher Scoring iterations: 4
#>
#>
#> $iv4
#> ______________
#> GLM Summary: -
#>
#>
#> Call:
#> glm(formula = inject(!!.dep_var ~ !!sym(x)), family = .family,
#> data = data)
#>
#> Coefficients:
#> Estimate Std. Error z value Pr(>|z|)
#> (Intercept) 1.017e-16 1.741e-01 0.000 1.0000
#> iv4l -6.257e-01 2.523e-01 -2.480 0.0131 *
#> iv4m -2.054e+00 3.248e-01 -6.324 2.55e-10 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> (Dispersion parameter for binomial family taken to be 1)
#>
#> Null deviance: 57.5648 on 5 degrees of freedom
#> Residual deviance: 7.8004 on 3 degrees of freedom
#> AIC: 39.263
#>
#> Number of Fisher Scoring iterations: 4
#>
#>
list_transpose(uva)$anova
#> $iv2
#> ____________
#> GLM Anova: -
#>
#> Analysis of Deviance Table
#>
#> Model: binomial, link: logit
#>
#> Response: cbind(pn, qn)
#>
#> Terms added sequentially (first to last)
#>
#>
#> Df Deviance Resid. Df Resid. Dev Pr(>Chi)
#> NULL 5 57.565
#> iv2 1 1.9615 4 55.603 0.1613
#>
#> $iv3
#> ____________
#> GLM Anova: -
#>
#> Analysis of Deviance Table
#>
#> Model: binomial, link: logit
#>
#> Response: cbind(pn, qn)
#>
#> Terms added sequentially (first to last)
#>
#>
#> Df Deviance Resid. Df Resid. Dev Pr(>Chi)
#> NULL 5 57.565
#> iv3 1 38.689 4 18.875 4.969e-10 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> $iv4
#> ____________
#> GLM Anova: -
#>
#> Analysis of Deviance Table
#>
#> Model: binomial, link: logit
#>
#> Response: cbind(pn, qn)
#>
#> Terms added sequentially (first to last)
#>
#>
#> Df Deviance Resid. Df Resid. Dev Pr(>Chi)
#> NULL 5 57.565
#> iv4 2 49.764 3 7.800 1.562e-11 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
rm(d, uva)