Skip to contents

Plot coefficients of an aba model summary

Usage

aba_plot_coef(
  model_summary,
  term_labels = NULL,
  axis = c("term", "predictor", "outcome", "group"),
  coord_flip = FALSE,
  include_covariates = TRUE,
  sort = FALSE,
  facet_labels = TRUE,
  facet_axis = TRUE,
  palette = c("jama", "nature", "lancet", "none"),
  plotly = FALSE
)

Arguments

model_summary

an aba model summary. The object to plot - this should be the result of an aba_summary() call.

term_labels

list. A list where name is equal to a term variable and value is equal to the label you want to replace it with in the plot. Useful to exchange variable names with labels. Rememeber that terms are the data variables/columns which make up predictors.

axis

string. Specifies the x axis variable, color/fill variable, and facet variable in that order. Should be a vector of length three that includes only "predictor", "outcome", and "group" as values.

coord_flip

logical. Whether to flip the x and y axes. This can be useful when there are a large amount of predictor sets and you want to view metrics vertically.

include_covariates

logical. Whether to include covariates

sort

logical. Whether to sort axis labels by coefficient value

facet_labels

logical. Whether to include facet labels.

facet_axis

logical. Whether to keep axis segment/labels for all facets or whether to remove them for facets.

palette

string. Which ggpubr palette to use. See ggpubr::set_palette.

plotly

logical. Whether to use plot.ly instead of standard ggplot. Defaults to false. Using ggplotly can be useful if you want interactivity on web pages.

Value

a ggplot of the specified aba model summary coefficients

Examples


# fit aba model
model <- aba_model() %>%
  set_data(adnimerge %>% dplyr::filter(VISCODE == 'bl')) %>%
  set_groups(everyone()) %>%
  set_outcomes(ConvertedToAlzheimers, CSF_ABETA_STATUS_bl,
               .labels=c('Conversion to AD', 'CSF Abeta Status')) %>%
  set_predictors(
    PLASMA_ABETA_bl, PLASMA_PTAU181_bl, PLASMA_NFL_bl,
    c(PLASMA_ABETA_bl, PLASMA_PTAU181_bl, PLASMA_NFL_bl),
    .labels = c('A','T','N','ATN')
  ) %>%
  set_stats(stat_glm(std.beta=TRUE)) %>%
  fit()
#> Error in !is.null(.labels) && (.labels == "self"): 'length = 4' in coercion to 'logical(1)'

# summarise aba model to calculate metrics
model_summary <- model %>% aba_summary()
#> Error in eval(expr, envir, enclos): object 'model' not found

# plot the coefficients using default
coef_plot <- model_summary %>% aba_plot_coef(coord_flip = TRUE)
#> Error in eval(expr, envir, enclos): object 'model_summary' not found

# add term labels
term_labels <- list(
  'PLASMA_ABETA_bl' = 'Plasma Abeta',
  'PLASMA_PTAU181_bl' = 'Plasma P-tau',
  'PLASMA_NFL_bl' = 'Plasma NfL'
)
coef_plot2 <- model_summary %>% aba_plot_coef(coord_flip = TRUE,
                                              term_labels = term_labels)
#> Error in eval(expr, envir, enclos): object 'model_summary' not found

# compare predictor coefficients across outcomes
coef_plot3 <- model_summary %>%
  aba_plot_coef(
    axis = c('outcome', 'predictor','term','group'), coord_flip=TRUE
  )
#> Error in eval(expr, envir, enclos): object 'model_summary' not found