Skip to contents

Module to analyze and identify outliers using different methods such as IQR, Z-score, and Percentiles, and offers visualizations including box plots, density plots, and cumulative distribution plots to help interpret the outliers.

Usage

tm_outliers(
  label = "Outliers Module",
  outlier_var,
  categorical_var = NULL,
  ggtheme = c("gray", "bw", "linedraw", "light", "dark", "minimal", "classic", "void"),
  ggplot2_args = teal.widgets::ggplot2_args(),
  plot_height = c(600, 200, 2000),
  plot_width = NULL,
  pre_output = NULL,
  post_output = NULL,
  transformators = list(),
  decorators = list()
)

Arguments

label

(character(1)) Label shown in the navigation item for the module or module group. For modules() defaults to "root". See Details.

outlier_var

(data_extract_spec or list of multiple data_extract_spec) Specifies variable(s) to be analyzed for outliers.

categorical_var

(data_extract_spec or list of multiple data_extract_spec) optional, specifies the categorical variable(s) to split the selected outlier variables on.

ggtheme

(character) optional, ggplot2 theme to be used by default. Defaults to "gray".

ggplot2_args

(ggplot2_args) optional, object created by teal.widgets::ggplot2_args() with settings for all the plots or named list of ggplot2_args objects for plot-specific settings. The argument is merged with options variable teal.ggplot2_args and default module setup.

List names should match the following: c("default", "Boxplot", "Density Plot", "Cumulative Distribution Plot").

For more details see the vignette: vignette("custom-ggplot2-arguments", package = "teal.widgets").

plot_height

(numeric) optional, specifies the plot height as a three-element vector of value, min, and max intended for use with a slider UI element.

plot_width

(numeric) optional, specifies the plot width as a three-element vector of value, min, and max for a slider encoding the plot width.

pre_output

(shiny.tag) optional, text or UI element to be displayed before the module's output, providing context or a title. with text placed before the output to put the output into context. For example a title.

post_output

(shiny.tag) optional, text or UI element to be displayed after the module's output, adding context or further instructions. Elements like shiny::helpText() are useful.

transformators

(list of teal_transform_module) that will be applied to transform module's data input. To learn more check vignette("data-transform-as-shiny-module", package = "teal").

decorators

[Experimental] (list of teal_transform_module, named list of teal_transform_module) optional, decorator for tables or plots included in the module output reported. When a named list of teal_transform_module, the decorators are applied to the respective output objects.

Otherwise, the decorators are applied to all objects, which is equivalent as using the name default.

See section "Decorating Module" below for more details.

Value

Object of class teal_module to be used in teal applications.

Decorating Module

This module generates the following objects, which can be modified in place using decorators:

  • box_plot (ggplot2)

  • density_plot (ggplot2)

  • cumulative_plot (ggplot2)

  • table (listing_df created with rlistings::as_listing())

Decorators can be applied to all outputs or only to specific objects using a named list of teal_transform_module objects. The "default" name is reserved for decorators that are applied to all outputs. See code snippet below:

tm_outliers(
   ..., # arguments for module
   decorators = list(
     default = list(teal_transform_module(...)), # applied to all outputs
     box_plot = list(teal_transform_module(...)), # applied only to `box_plot` output
     density_plot = list(teal_transform_module(...)) # applied only to `density_plot` output
     cumulative_plot = list(teal_transform_module(...)) # applied only to `cumulative_plot` output
     table = list(teal_transform_module(...)) # applied only to `table` output
   )
)

For additional details and examples of decorators, refer to the vignette vignette("decorate-modules-output", package = "teal") or the teal::teal_transform_module() documentation.

Examples in Shinylive

example-1

Open in Shinylive

example-2

Open in Shinylive

Examples


# general data example
data <- teal_data()
data <- within(data, {
  CO2 <- CO2
  CO2[["primary_key"]] <- seq_len(nrow(CO2))
})
join_keys(data) <- join_keys(join_key("CO2", "CO2", "primary_key"))

vars <- choices_selected(variable_choices(data[["CO2"]], c("Plant", "Type", "Treatment")))

app <- init(
  data = data,
  modules = modules(
    tm_outliers(
      outlier_var = list(
        data_extract_spec(
          dataname = "CO2",
          select = select_spec(
            label = "Select variable:",
            choices = variable_choices(data[["CO2"]], c("conc", "uptake")),
            selected = "uptake",
            multiple = FALSE,
            fixed = FALSE
          )
        )
      ),
      categorical_var = list(
        data_extract_spec(
          dataname = "CO2",
          filter = filter_spec(
            vars = vars,
            choices = value_choices(data[["CO2"]], vars$selected),
            selected = value_choices(data[["CO2"]], vars$selected),
            multiple = TRUE
          )
        )
      )
    )
  )
)
#> Initializing tm_outliers
if (interactive()) {
  shinyApp(app$ui, app$server)
}


# CDISC data example
data <- teal_data()
data <- within(data, {
  ADSL <- teal.data::rADSL
})
join_keys(data) <- default_cdisc_join_keys[names(data)]

fact_vars_adsl <- names(Filter(isTRUE, sapply(data[["ADSL"]], is.factor)))
vars <- choices_selected(variable_choices(data[["ADSL"]], fact_vars_adsl))



app <- init(
  data = data,
  modules = modules(
    tm_outliers(
      outlier_var = list(
        data_extract_spec(
          dataname = "ADSL",
          select = select_spec(
            label = "Select variable:",
            choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1")),
            selected = "AGE",
            multiple = FALSE,
            fixed = FALSE
          )
        )
      ),
      categorical_var = list(
        data_extract_spec(
          dataname = "ADSL",
          filter = filter_spec(
            vars = vars,
            choices = value_choices(data[["ADSL"]], vars$selected),
            selected = value_choices(data[["ADSL"]], vars$selected),
            multiple = TRUE
          )
        )
      )
    )
  )
)
#> Initializing tm_outliers
if (interactive()) {
  shinyApp(app$ui, app$server)
}