Bins a feature variable, computes exposure-weighted means of one or more observed variables per bin, and returns a dual-axis plotly chart (bars = exposure, lines = weighted means). Optionally splits by a second variable.
Arguments
- data
A
data.frameordata.table.- ...
Arguments passed to methods.
- var
Column to plot on the x-axis. Bare name or string.
- obs
One or more columns to summarise on the y-axis (right axis). Bare name,
c(a, b), or character vector. Default"target".- exposure
Column of exposure weights. If the column does not exist in
data, every row is given weight 1. Bare name or string. Default"exposure".- split
Optional column to split lines by. Bare name, string, or
NA/NULLfor no split. DefaultNA.- bins
[integer(1)]Number of equal-exposure bins for numeric variables with more thanbinsunique values. Default 35.- time_unit
[character(1)]For Date / POSIXct variables, the width of each bin. Passed directly tobase::cut.POSIXt(), so any string it accepts works:"month","week","2 weeks","12 hours","quarter","year", etc. Ignored for non-date columns. DefaultNA(no date binning — dates are shown as individual values).- type_agg
[character(1)]Binning strategy for numeric variables:"equal_exposure"(default) or"equal_range".- ret
[character(1)]"plot"(default) returns a plotly object;"data"returns the aggregated data.table.- verbose
[logical(1)]Report how many NA values ofvarwere moved to the trailing"NA"category? DefaultFALSE.
Value
A plotly object, or a data.table when ret = "data", or NULL
with a warning if the plot cannot be produced.