Skip to contents

summanov() 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.

Usage

summanov(data, .dep_var, ..., .family = binomial, .test = "Chisq")

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         0
#>  8 a     g     i     k         0
#>  9 a     g     i     k         1
#> 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.12136    0.24664   0.492 0.622674    
#> ivb         -0.06074    0.34856  -0.174 0.861668    
#> ivc         -0.74707    0.35716  -2.092 0.036467 *  
#> ivd         -0.95427    0.36410  -2.621 0.008770 ** 
#> ive         -1.34514    0.38354  -3.507 0.000453 ***
#> ivf         -2.86220    0.57180  -5.006 5.57e-07 ***
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> (Dispersion parameter for binomial family taken to be 1)
#> 
#>     Null deviance: 502.72  on 395  degrees of freedom
#> Residual deviance: 449.92  on 390  degrees of freedom
#> AIC: 461.92
#> 
#> 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     502.72              
#> iv    5   52.799       390     449.92 3.698e-10 ***
#> ---
#> 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.5379     0.1473  -3.651 0.000261 ***
#> iv2h         -0.3433     0.2147  -1.599 0.109728    
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> (Dispersion parameter for binomial family taken to be 1)
#> 
#>     Null deviance: 502.72  on 395  degrees of freedom
#> Residual deviance: 500.15  on 394  degrees of freedom
#> AIC: 504.15
#> 
#> 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     502.72         
#> iv2   1   2.5708       394     500.15   0.1088
#> 
#> $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.2637     0.2285  -5.529 3.22e-08 ***
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> (Dispersion parameter for binomial family taken to be 1)
#> 
#>     Null deviance: 502.72  on 395  degrees of freedom
#> Residual deviance: 469.98  on 394  degrees of freedom
#> AIC: 473.98
#> 
#> 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     502.72              
#> iv3   1   32.742       394     469.98 1.053e-08 ***
#> ---
#> 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)  0.09097    0.17426   0.522  0.60163    
#> iv4l        -0.81841    0.25467  -3.214  0.00131 ** 
#> iv4m        -1.87392    0.30306  -6.183 6.28e-10 ***
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> (Dispersion parameter for binomial family taken to be 1)
#> 
#>     Null deviance: 502.72  on 395  degrees of freedom
#> Residual deviance: 458.12  on 393  degrees of freedom
#> AIC: 464.12
#> 
#> 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     502.72              
#> iv4   2   44.603       393     458.12 2.063e-10 ***
#> ---
#> 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.12136    0.24664   0.492 0.622674    
#> ivb         -0.06074    0.34856  -0.174 0.861668    
#> ivc         -0.74707    0.35716  -2.092 0.036467 *  
#> ivd         -0.95427    0.36410  -2.621 0.008770 ** 
#> ive         -1.34514    0.38354  -3.507 0.000453 ***
#> ivf         -2.86220    0.57180  -5.006 5.57e-07 ***
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> (Dispersion parameter for binomial family taken to be 1)
#> 
#>     Null deviance: 502.72  on 395  degrees of freedom
#> Residual deviance: 449.92  on 390  degrees of freedom
#> AIC: 461.92
#> 
#> 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     502.72              
#> iv    5   52.799       390     449.92 3.698e-10 ***
#> ---
#> 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.2637     0.2285  -5.529 3.22e-08 ***
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> (Dispersion parameter for binomial family taken to be 1)
#> 
#>     Null deviance: 502.72  on 395  degrees of freedom
#> Residual deviance: 469.98  on 394  degrees of freedom
#> AIC: 473.98
#> 
#> 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     502.72              
#> iv3   1   32.742       394     469.98 1.053e-08 ***
#> ---
#> 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)  0.09097    0.17426   0.522  0.60163    
#> iv4l        -0.81841    0.25467  -3.214  0.00131 ** 
#> iv4m        -1.87392    0.30306  -6.183 6.28e-10 ***
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> (Dispersion parameter for binomial family taken to be 1)
#> 
#>     Null deviance: 502.72  on 395  degrees of freedom
#> Residual deviance: 458.12  on 393  degrees of freedom
#> AIC: 464.12
#> 
#> 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     502.72              
#> iv4   2   44.603       393     458.12 2.063e-10 ***
#> ---
#> 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        35    31
#> 2 b     h     i     k        34    32
#> 3 c     g     i     l        23    43
#> 4 d     h     j     l        20    46
#> 5 e     g     j     m        15    51
#> 6 f     h     j     m         4    62

(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.5379     0.1473  -3.651 0.000261 ***
#> iv2h         -0.3433     0.2147  -1.599 0.109728    
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> (Dispersion parameter for binomial family taken to be 1)
#> 
#>     Null deviance: 52.799  on 5  degrees of freedom
#> Residual deviance: 50.228  on 4  degrees of freedom
#> AIC: 80.06
#> 
#> 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     52.799         
#> iv2   1   2.5708         4     50.228   0.1088
#> 
#> $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.2637     0.2285  -5.529 3.22e-08 ***
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> (Dispersion parameter for binomial family taken to be 1)
#> 
#>     Null deviance: 52.799  on 5  degrees of freedom
#> Residual deviance: 20.058  on 4  degrees of freedom
#> AIC: 49.89
#> 
#> 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     52.799              
#> iv3   1   32.742         4     20.058 1.053e-08 ***
#> ---
#> 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)  0.09097    0.17426   0.522  0.60163    
#> iv4l        -0.81841    0.25467  -3.214  0.00131 ** 
#> iv4m        -1.87392    0.30306  -6.183 6.28e-10 ***
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> (Dispersion parameter for binomial family taken to be 1)
#> 
#>     Null deviance: 52.7992  on 5  degrees of freedom
#> Residual deviance:  8.1962  on 3  degrees of freedom
#> AIC: 40.028
#> 
#> 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     52.799              
#> iv4   2   44.603         3      8.196 2.063e-10 ***
#> ---
#> 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.5379     0.1473  -3.651 0.000261 ***
#> iv2h         -0.3433     0.2147  -1.599 0.109728    
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> (Dispersion parameter for binomial family taken to be 1)
#> 
#>     Null deviance: 52.799  on 5  degrees of freedom
#> Residual deviance: 50.228  on 4  degrees of freedom
#> AIC: 80.06
#> 
#> 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.2637     0.2285  -5.529 3.22e-08 ***
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> (Dispersion parameter for binomial family taken to be 1)
#> 
#>     Null deviance: 52.799  on 5  degrees of freedom
#> Residual deviance: 20.058  on 4  degrees of freedom
#> AIC: 49.89
#> 
#> 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)  0.09097    0.17426   0.522  0.60163    
#> iv4l        -0.81841    0.25467  -3.214  0.00131 ** 
#> iv4m        -1.87392    0.30306  -6.183 6.28e-10 ***
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> (Dispersion parameter for binomial family taken to be 1)
#> 
#>     Null deviance: 52.7992  on 5  degrees of freedom
#> Residual deviance:  8.1962  on 3  degrees of freedom
#> AIC: 40.028
#> 
#> 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     52.799         
#> iv2   1   2.5708         4     50.228   0.1088
#> 
#> $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     52.799              
#> iv3   1   32.742         4     20.058 1.053e-08 ***
#> ---
#> 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     52.799              
#> iv4   2   44.603         3      8.196 2.063e-10 ***
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 

rm(d, uva)