Skip to contents

Produces a formatted table showing the outputs from the Odds Ratio analysis.

Usage

table_or(glm_model_results, conf_level = 0.95, output = "tibble")

Arguments

glm_model_results

Results from a binomial Generalised Linear Model (GLM), as produced by stats::glm().

conf_level

Numeric between 0.001 and 0.999 (default = 0.95). The confidence level to use when setting the confidence interval, most commonly will be 0.95 or 0.99 but can be set otherwise.

output

String description of the output type. Default = 'tibble'. Options include 'tibble' and 'gt'.

Value

object returned depends on output parameter - output = 'tibble' returns an object of "tbl_df", "tbl", "data.frame" class, whilst output = 'gt' returns an object of class "gt_tbl" and "list".

Details

Includes details on the characteristics of the covariates, such as:

  • the number of observations for each characteristic,

  • the number of observations resulting in the outcome of interest,

  • the conversion rate of outcome by the number of observations,

Details are calculated showing the:

  • estimated Odds Ratio, standard error and p-value,

  • calculated confidence interval for the confidence level,

Also included is a visualisation of the OR plot to provide an at-a-glance view of the model results.

Examples

# get some data
df <- datasets::Titanic |>
  dplyr::as_tibble() |>
  # convert aggregated counts to individual observations
  dplyr::filter(n > 0) |>
  tidyr::uncount(weights = n) |>
  # convert character variables to factors
  dplyr::mutate(dplyr::across(dplyr::where(is.character), as.factor))

# perform logistic regression using `glm`
lr <- stats::glm(
  data = df,
  family = 'binomial',
  formula = Survived ~ Class + Sex + Age
)

# produce the Odds Ratio table, first as a tibble then as gt object
table_or(lr)
#> # A tibble: 8 × 14
#>   label level   rows outcome outcome_rate class  estimate std.error statistic
#>   <fct> <fct>  <int>   <int>        <dbl> <chr>     <dbl>     <dbl>     <dbl>
#> 1 Class 3rd      706     178        0.252 factor   0.169      0.172    -10.4 
#> 2 Class 1st      325     203        0.625 factor  NA         NA         NA   
#> 3 Class 2nd      285     118        0.414 factor   0.361      0.196     -5.19
#> 4 Class Crew     885     212        0.240 factor   0.424      0.157     -5.45
#> 5 Sex   Male    1731     367        0.212 factor   0.0889     0.140    -17.2 
#> 6 Sex   Female   470     344        0.732 factor  NA         NA         NA   
#> 7 Age   Child    109      57        0.523 factor   2.89       0.244      4.35
#> 8 Age   Adult   2092     654        0.313 factor  NA         NA         NA   
#> # ℹ 5 more variables: p.value <dbl>, conf.low <dbl>, conf.high <dbl>,
#> #   significance <chr>, comparator <dbl>
table_or(lr, output = 'gt')
Survived
Odds Ratio summary table with 95% Confidence Interval
Characteristic1
Odds Ratio (OR)2
95% Confidence Interval (CI)3
OR Plot
Level N n Rate Class OR SE p Lower Upper Significance
Class 3rd 706 178 25.21% factor 0.1690 0.1716 3.69 × 10−25 0.1203 0.2358 Significant 0-1-2
1st 325 203 62.46% factor Comparator  
2nd 285 118 41.4% factor 0.3613 0.1960 2.05 × 10−7 0.2453 0.5292 Significant 0-1-1
Crew 885 212 23.95% factor 0.4241 0.1573 5.00 × 10−8 0.3115 0.5775 Significant 0-1-1
Sex Male 1,731 367 21.2% factor 0.08892 0.1404 1.43 × 10−66 0.06725 0.1166 Significant 0-2-3
Female 470 344 73.19% factor Comparator  
Age Child 109 57 52.29% factor 2.891 0.2440 1.36 × 10−5 1.792 4.671 Significant 021
Adult 2,092 654 31.26% factor Comparator  
1 Characteristics are the explanatory variables in the logistic regression analysis. For categorical variables the first characteristic is designated as a reference against which the others are compared. For numeric variables the results indicate a change per single unit increase.

Level - the name or the description of the explanatory variable.

N - the number of observations examined.

n - the number of observations resulting in the outcome of interest.

Rate - the proportion of observations resulting in the outcome of interest (n / N).

Class - description of the data type.

2 Odds Ratios estimate the relative odds of an outcome with reference to the Characteristic. For categorical data the first level is the reference against which the odds of other levels are compared. Numerical characteristics indicate the change in OR for each additional increase of one unit in the variable.

OR - The Odds Ratio point estimate - values below 1 indicate an inverse relationship whereas values above 1 indicate a positive relationship. Values shown to 4 significant figures.

SE - Standard Error of the point estimate. Values shown to 4 significant figures.

p - The p-value estimate based on the residual Chi-squared statistic.

3 Confidence Interval - the range of values likely to contain the OR in 95% of cases if this study were to be repeated multiple times. If the CI touches or crosses the value 1 then it is unlikely the Characteristic is significantly associated with the outcome.

Lower & Upper - The range of values comprising the CI, shown to 4 significant figures.

Significance - The statistical significance indicated by the CI, Significant where the CI does not touch or cross the value 1.