Produces a formatted table showing the outputs from the Odds Ratio analysis.
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
Level
N
n
Rate
Class
OR
SE
p
Lower
Upper
Significance
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.