This function executes binning methods available in classInt i.e. "jenks", "kmeans", "sd", "pretty", "pam", "kmeans", "hclust", "bclust", "fisher", "dpih", "box", "headtails", and "maximum".
You may also bin directly on x-variable or alternatively specify "centers" or "breaks". For explanation of binning methods see classIntervals
.
binning(o, ...)
# S3 method for tidyvpcobj
binning(
o,
bin,
data = o$data,
xbin = "xmedian",
centers,
breaks,
nbins,
altx,
stratum = NULL,
by.strata = TRUE,
...
)
A tidyvpcobj
.
Other arguments to include for classIntervals
. See ...
usage for style
in ?classIntervals
.
Character string indicating binning method or unquoted variable name if binning on x-variable.
Observed data supplied in observed()
function.
Character string indicating midpoint type for binning.
Numeric vector of centers for binning. Use bin = "centers"
, if supplying centers.
Numeric vector of breaks for binning. Use bin = "breaks"
, if supplying breaks.
Numeric number indicating the number of bins to use.
Unquoted variable name in observed data for alternative x-variable binning.
List indicating the name of stratification variable and level, if using different binning methods by strata.
Logical indicating whether binning should be performed by strata.
Updates tidyvpcobj
with data.frame
containing bin information including left/right boundaries and midpoint, as specified in xbin
argument.
# \donttest{
require(magrittr)
# Binning on x-variable NTIME
vpc <- observed(obs_data, x=TIME, y=DV) %>%
simulated(sim_data, y=DV) %>%
binning(bin = NTIME) %>%
vpcstats()
# Binning using ntile and xmean for midpoint
vpc <- observed(obs_data, x=TIME, y=DV) %>%
simulated(sim_data, y=DV) %>%
binning(bin = "ntile", nbins = 8, xbin = "xmean") %>%
vpcstats()
# Binning using centers
vpc <- observed(obs_data, x=TIME, y=DV) %>%
simulated(sim_data, y=DV) %>%
binning(bin = "centers", centers = c(1,3,5,7)) %>%
vpcstats()
# Different Binning for each level of Strata
vpc <- observed(obs_data, x=TIME, y=DV) %>%
simulated(sim_data, y=DV) %>%
stratify(~ GENDER) %>%
binning(stratum = list(GENDER = "M"), bin = "jenks", nbins = 5, by.strata = TRUE) %>%
binning(stratum = list(GENDER = "F"), bin = "kmeans", nbins = 4, by.strata = TRUE) %>%
vpcstats()
# Binning Categorical DV using rounded time variable
vpc <- observed(obs_cat_data, x = agemonths, y = zlencat ) %>%
simulated(sim_cat_data, y = DV) %>%
binning(bin = round(agemonths, 0)) %>%
vpcstats(vpc.type = "categorical")
# }