Module for visualizing regression analysis, including scatterplots and various regression diagnostics plots. It allows users to explore the relationship between a set of regressors and a response variable, visualize residuals, and identify outliers.
Usage
tm_a_regression(
label = "Regression Analysis",
regressor,
response,
plot_height = c(600, 200, 2000),
plot_width = NULL,
alpha = c(1, 0, 1),
size = c(2, 1, 8),
ggtheme = c("gray", "bw", "linedraw", "light", "dark", "minimal", "classic", "void"),
ggplot2_args = teal.widgets::ggplot2_args(),
pre_output = NULL,
post_output = NULL,
default_plot_type = 1,
default_outlier_label = "USUBJID",
label_segment_threshold = c(0.5, 0, 10),
transformators = list(),
decorators = list()
)Arguments
- label
(
character(1)) Label shown in the navigation item for the module or module group. Formodules()defaults to"root". SeeDetails.- regressor
(
data_extract_specorlistof multipledata_extract_spec) Regressor variables from an incoming dataset with filtering and selecting.- response
(
data_extract_specorlistof multipledata_extract_spec) Response variables from an incoming dataset with filtering and selecting.- plot_height
(
numeric) optional, specifies the plot height as a three-element vector ofvalue,min, andmaxintended for use with a slider UI element.- plot_width
(
numeric) optional, specifies the plot width as a three-element vector ofvalue,min, andmaxfor a slider encoding the plot width.- alpha
-
(
integer(1)orinteger(3)) optional, specifies point opacity.When the length of
alphais one: the plot points will have a fixed opacity.When the length of
alphais three: the plot points opacity are dynamically adjusted based on vector ofvalue,min, andmax.
- size
-
(
integer(1)orinteger(3)) optional, specifies point size.When the length of
sizeis one: the plot point sizes will have a fixed size.When the length of
sizeis three: the plot points size are dynamically adjusted based on vector ofvalue,min, andmax.
- ggtheme
(
character) optional,ggplot2theme to be used by default. Defaults to"gray".- ggplot2_args
-
(
ggplot2_args) optional, object created byteal.widgets::ggplot2_args()with settings for all the plots or named list ofggplot2_argsobjects for plot-specific settings. The argument is merged with options variableteal.ggplot2_argsand default module setup.List names should match the following:
c("default", "Response vs Regressor", "Residuals vs Fitted", "Scale-Location", "Cook's distance", "Residuals vs Leverage", "Cook's dist vs Leverage").For more details see the vignette:
vignette("custom-ggplot2-arguments", package = "teal.widgets"). - 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 likeshiny::helpText()are useful.- default_plot_type
-
(
numeric) optional, defaults to "Response vs Regressor".Response vs Regressor
Residuals vs Fitted
Normal Q-Q
Scale-Location
Cook's distance
Residuals vs Leverage
Cook's dist vs Leverage
- default_outlier_label
(
character) optional, default column selected to label outliers.- label_segment_threshold
-
(
numeric(1)ornumeric(3)) Minimum distance between label and point on the plot that triggers the creation of a line segment between the two. This may happen when the label cannot be placed next to the point as it overlaps another label or point. The value is used as themin.segment.lengthparameter to theggrepel::geom_text_repel()function.It can take the following forms:
numeric(1): Fixed value used for the minimum distance and the slider is not presented in the UI.-
numeric(3): A slider is presented in the UI (under "Plot settings") to adjust the minimum distance dynamically.It takes the form of
c(value, min, max)and it is passed to thevalue_min_maxargument inteal.widgets::optionalSliderInputValMinMax.
- transformators
(
listofteal_transform_module) that will be applied to transform module's data input. To learn more checkvignette("transform-input-data", package = "teal").- decorators
-
(named
listof lists ofteal_transform_module) optional, decorator for tables or plots included in the module output reported. The decorators are applied to the respective output objects.See section "Decorating Module" below for more details.
Note
For more examples, please see the vignette "Using regression plots" via
vignette("using-regression-plots", package = "teal.modules.general").
Decorating Module
This module generates the following objects, which can be modified in place using decorators:
plot(ggplot)
A Decorator is applied to the specific output using a named list of teal_transform_module objects.
The name of this list corresponds to the name of the output to which the decorator is applied.
See code snippet below:
tm_a_regression(
..., # arguments for module
decorators = list(
plot = teal_transform_module(...) # applied to the `plot` output
)
)
For additional details and examples of decorators, refer to the vignette
vignette("decorate-module-output", package = "teal.modules.general").
To learn more please refer to the vignette
vignette("transform-module-output", package = "teal") or the teal::teal_transform_module() documentation.
Examples
# general data example
data <- teal_data()
data <- within(data, {
require(nestcolor)
CO2 <- CO2
})
app <- init(
data = data,
modules = modules(
tm_a_regression(
label = "Regression",
response = data_extract_spec(
dataname = "CO2",
select = select_spec(
label = "Select variable:",
choices = "uptake",
selected = "uptake",
multiple = FALSE,
fixed = TRUE
)
),
regressor = data_extract_spec(
dataname = "CO2",
select = select_spec(
label = "Select variables:",
choices = variable_choices(data[["CO2"]], c("conc", "Treatment")),
selected = "conc",
multiple = TRUE,
fixed = FALSE
)
)
)
)
)
#> Initializing tm_a_regression
if (interactive()) {
shinyApp(app$ui, app$server)
}
# CDISC data example
data <- teal_data()
data <- within(data, {
require(nestcolor)
ADSL <- teal.data::rADSL
})
join_keys(data) <- default_cdisc_join_keys[names(data)]
app <- init(
data = data,
modules = modules(
tm_a_regression(
label = "Regression",
response = data_extract_spec(
dataname = "ADSL",
select = select_spec(
label = "Select variable:",
choices = "BMRKR1",
selected = "BMRKR1",
multiple = FALSE,
fixed = TRUE
)
),
regressor = data_extract_spec(
dataname = "ADSL",
select = select_spec(
label = "Select variables:",
choices = variable_choices(data[["ADSL"]], c("AGE", "SEX", "RACE")),
selected = "AGE",
multiple = TRUE,
fixed = FALSE
)
)
)
)
)
#> Initializing tm_a_regression
if (interactive()) {
shinyApp(app$ui, app$server)
}