Visualizes binned regression results from dbbinsreg. Plots dots at bin means with optional confidence intervals and/or confidence bands, and optionally overlays a smooth line if computed. Uses tinyplot for rendering but works with both plot() and tinyplot() generics.
Usage
## S3 method for class 'dbbinsreg'
plot(
x,
type = NULL,
ci = TRUE,
cb = TRUE,
line = TRUE,
lty = 1,
theme = "basic",
...
)
## S3 method for class 'dbbinsreg'
tinyplot(
x,
type = NULL,
ci = TRUE,
cb = TRUE,
line = TRUE,
lty = 1,
theme = "basic",
...
)
Arguments
x
A dbbinsreg object
type
The type of plot. If NULL (the default), then the type will be inferred based on the underlying object (e.g, “pointrange” for points with confidence intervals).
ci
Logical. Show confidence intervals for dots? Default is TRUE.
cb
Logical. Show confidence bands as a ribbon? Default is TRUE if available in the object.
line
Logical. Show the line overlay if available? Default is TRUE.
lty
Integer or character string. Line type for line overlay.
theme
Character string. One of the valid plot themes supported by tinytheme. The default “basic” theme is a light adaptation of the standard base graphics aesthetic, featuring filled points and a background grid. Various other themes are supported (e.g., “clean”, “minimal”, “classic”, etc.), while passing NULL switches the theme off entirely.
…
Additional arguments passed to tinyplot, e.g. main, sub, file, etc.
Examples
library("dbreg")### In-memory data ----# Like `dbreg`, we can pass in-memory R data frames to an ephemeral DuckDB# connection via the `data` argument. # Canonical binscatter: bin means (default)dbbinsreg(weight ~ Time, data = ChickWeight, nbins =10)
# You can pass additional plotting arguments via ... to (tiny)plot.dbbinsregdbbinsreg(weight ~ Time, data = ChickWeight, nbins =10,main ="A simple binscatter example", theme ="clean")
# Alternatively, save the object and plot laterbs =dbbinsreg(weight ~ Time, data = ChickWeight, nbins =10, plot =FALSE)plot(bs, main ="Same example, different theme", theme ="classic")
# Piecewise linear (p = 1), no smoothness (s = 0)dbbinsreg(weight ~ Time, data = ChickWeight, nbins =10, points =c(1, 0))
# Accounting for Diet "fixed effects" helps to resolve the situation# (We'll also add a line and change the theme for a nicer plot)dbbinsreg(weight ~ Time | Diet, data = ChickWeight, nbins =10, cb =TRUE,line =c(1, 1), theme ="clean")