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),
decorators = NULL
)
Arguments
- label
(
character(1)
) Label shown in the navigation item for the module or module group. Formodules()
defaults to"root"
. SeeDetails
.- regressor
(
data_extract_spec
orlist
of multipledata_extract_spec
) Regressor variables from an incoming dataset with filtering and selecting.- response
(
data_extract_spec
orlist
of 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
, andmax
intended for use with a slider UI element.- plot_width
(
numeric
) optional, specifies the plot width as a three-element vector ofvalue
,min
, andmax
for a slider encoding the plot width.- alpha
-
(
integer(1)
orinteger(3)
) optional, specifies point opacity.When the length of
alpha
is one: the plot points will have a fixed opacity.When the length of
alpha
is 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
size
is one: the plot point sizes will have a fixed size.When the length of
size
is three: the plot points size are dynamically adjusted based on vector ofvalue
,min
, andmax
.
- ggtheme
(
character
) optional,ggplot2
theme 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_args
objects for plot-specific settings. The argument is merged with options variableteal.ggplot2_args
and 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.length
parameter 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_max
argument inteal.widgets::optionalSliderInputValMinMax
.
- decorators
-
(
list
ofteal_transform_module
, namedlist
ofteal_transform_module
orNULL
) optional, if notNULL
, decorator for tables or plots included in the module. When a named list ofteal_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
tm_a_regression
" 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 tm_a_regression
This module generates the following objects, which can be modified in place using decorators:
plot
(ggplot2
)
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
# 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
#> Initializing reporter_previewer_module
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
#> Initializing reporter_previewer_module
if (interactive()) {
shinyApp(app$ui, app$server)
}