binning: binning

Description Usage Arguments Details Value See Also Examples

View source: R/vpcstats.R

Description

Binning methods for Visual Predictive Check (VPC)

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
binning(o, ...)

## S3 method for class 'tidyvpcobj'
binning(
  o,
  bin,
  data = o$data,
  xbin = "xmedian",
  centers,
  breaks,
  nbins,
  altx,
  stratum = NULL,
  by.strata = TRUE,
  ...
)

Arguments

o

tidyvpc object

...

Other arguments to include

bin

Character string indicating binning method or unquoted variable name if binning on x-variable.

data

Observed data supplied in observed() function

xbin

Character string indicating midpoint type for binning

centers

Numeric vector of centers for binning. Use bin = "centers" if supplying centers

breaks

Numeric vector of breaks for binning. Use bin = "breaks" if supplying breaks

nbins

Numeric number indicating the number of bins to use

altx

Unquoted variable name in observed data for elternative x-variable binning

stratum

List indicating the name of stratification variable and level if using different binning methods by strata

by.strata

Logical indicating whether binning should be performed by strata

Details

This function executes binning methods available in classInt i.e. "jenks", "kmeans", "sd", "pretty", "pam", "kmeans", "hclust", "bclust", "fisher", and "dpih". You may also bin directly on x-variable or alternatively specify "centers" or "breaks". For explanation of binning methods see classIntervals

Value

Updates tidyvpcobj with data.frame containing bin information including left/right boundaries and midpoint as specified in xbin argument

See Also

observed simulated censoring predcorrect stratify binless vpcstats

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 # 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 = "pam", nbins = 4, by.strata = TRUE) %>%
    vpcstats()

tidyvpc documentation built on Jan. 13, 2021, 6:31 a.m.