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)
)
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
.
Note
For more examples, please see the vignette "Using regression plots" via
vignette("using-regression-plots", package = "teal.modules.general")
.
Examples
# general data example
library(teal.widgets)
data <- teal_data()
data <- within(data, {
require(nestcolor)
CO2 <- CO2
})
datanames(data) <- c("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
)
),
ggplot2_args = ggplot2_args(
labs = list(subtitle = "Plot generated by Regression Module")
)
)
)
)
#> [INFO] 2024-03-05 18:46:03.3278 pid:1279 token:[] teal.modules.general Initializing tm_a_regression
if (interactive()) {
shinyApp(app$ui, app$server)
}
# CDISC data example
library(teal.widgets)
data <- teal_data()
data <- within(data, {
require(nestcolor)
ADSL <- rADSL
})
datanames(data) <- "ADSL"
join_keys(data) <- default_cdisc_join_keys[datanames(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
)
),
ggplot2_args = ggplot2_args(
labs = list(subtitle = "Plot generated by Regression Module")
)
)
)
)
#> [INFO] 2024-03-05 18:46:03.4280 pid:1279 token:[] teal.modules.general Initializing tm_a_regression
if (interactive()) {
shinyApp(app$ui, app$server)
}