Learn R Programming

plotor (version 0.8.0)

table_or: Table OR

Description

Produces a formatted table displaying the outputs from the Odds Ratio analysis, including details on covariate characteristics and model results.

Usage

table_or(
  glm_model_results,
  conf_level = 0.95,
  output = c("tibble", "gt"),
  output_type = c("multivariable", "uni_and_multi"),
  confint_fast_estimate = FALSE,
  assumption_checks = TRUE,
  anonymise_counts = FALSE,
  use_model_data_only = TRUE
)

Value

The returned object depends on the output parameter:

  • If output = 'tibble', the function returns an object of class "tbl_df", "tbl", and "data.frame".

  • If output = 'gt', the function returns an object of class "gt_tbl" and "list".

Arguments

glm_model_results

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

conf_level

Numeric value between 0.001 and 0.999 (default = 0.95) specifying the confidence level for the confidence interval.

output

String describing the output type (default = "tibble"). Options include "tibble" and "gt".

output_type

String description of the output type (default = "multivariable"). Options include "multivariable" and "uni_and_multi". Selecting "multivariable" will produce a summary table of the supplied multivariable model. Selecting "uni_and_multi" will produce a summary table showing estimates of the Odds Ratio, Confidence Intervals and p-values produced using a univariable logistic regression model for each predctor along with the adjusted Odds Ratio, Confidence Intervals and p-values from the supplied multivariable model.

confint_fast_estimate

Boolean (default = FALSE) indicating whether to use a faster estimate of the confidence interval. Note: this assumes normally distributed data, which may not be suitable for your data.

assumption_checks

Boolean (default = TRUE) indicating whether to conduct checks to ensure that the assumptions of logistic regression are met.

anonymise_counts

Boolean (default = FALSE) indicating whether to anonymise counts in the output table. If TRUE, counts less than 10 are suppressed and otherwise rounded to the nearest multiple of 5.

use_model_data_only

Boolean (default = FALSE) indicating whether to use only the subset of data that was used as part of the multivariable model, or set to TRUE to use the full set of data provided to the multivariable model. Note, any records containing missing values for any of the outcome or predictor variables are automatically excluded from the multivariable model by stats::glm, so the overall number of records used in multivariable models can be much lower than the total number of records supplied to the function. Set to TRUE to increase comparability between the univariable and multivariable models, set to FALSE to gain a more holistic view of the invididual relationships between predictors and outcome.

Details

The table includes the following information:

  • Covariate Characteristics:

    • Number of observations for each characteristic

    • Number of observations resulting in the outcome of interest

    • Conversion rate of the outcome based on the number of observations

  • Model Results:

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

    • Calculated confidence interval for the specified confidence level

A visualisation of the Odds Ratio plot is also provided for an at-a-glance view of the model results.

If anonymise_counts is set to TRUE, counts below 10 are suppressed as <10, and other counts are rounded to the nearest multiple of 5. This feature is helpful when working with sensitive data.

Examples

Run this code
# Load the Titanic dataset
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 as a tibble
table_or(lr)

# Produce the Odds Ratio table as a gt object
table_or(lr, output = 'gt')

Run the code above in your browser using DataLab