View source: R/balancedSampsize.R
balancedSampsize | R Documentation |
Create a vector of balanced (equal) sample sizes for use in
the sampsize
argument of rfPermute
or
randomForest
for a classification model. The
values are derived from a percentage of the smallest class sample size.
balancedSampsize(y, pct = 0.5)
y |
character, numeric, or factor vector containing classes of response variable. Values will be treated as unique for computing class frequencies. |
pct |
percent of smallest class frequency for |
a named vector of sample sizes as long as the number of classes.
Eric Archer eric.archer@noaa.gov
data(mtcars)
# A balanced model with default half of smallest class size
sampsize_0.5 <- balancedSampsize(mtcars$am)
sampsize_0.5
rfPermute(factor(am) ~ ., mtcars, replace = FALSE, sampsize = sampsize_0.5)
# A balanced model with one quarter of smallest class size
sampsize_0.25 <- balancedSampsize(mtcars$am, pct = 0.25)
sampsize_0.25
rfPermute(factor(am) ~ ., mtcars, replace = FALSE, sampsize = sampsize_0.25)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.