var.bin.Rd
The optimization of a frame stratification is applicable only in presence of all categorical auxiliary variables in the frame. If one or more continuous auxiliary variables are in the frame, it is necessary to pre-process in order to convert them into categorical (ordinal) variables. The applied method is the "k-means" clustering method contained in the in "stats" package. This function ensures that the final result is in an ordered categorical variable.
var.bin(x,
bins=3,
iter.max=100)
Continuous variable to be transformed into a categorical one
Number of values of the resulting categorical variable
Maximum number of iterations of the clustering algorithm
Binned variable
# \donttest{
library(SamplingStrata)
data(swissmunicipalities)
data(swissframe)
swissframe$X1 <- var.bin(swissmunicipalities$POPTOT,bins = 18)
table(swissframe$X1)
#>
#> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#> 774 554 374 308 234 180 123 96 58 55 49 30 32 13 8 3 4 1
tapply(swissmunicipalities$POPTOT,swissframe$X1,mean)
#> 1 2 3 4 5 6
#> 195.9845 534.9928 947.1310 1436.1331 2106.8291 2936.9667
#> 7 8 9 10 11 12
#> 3918.9756 5010.8229 6308.8276 7881.3818 10244.9184 13467.1333
#> 13 14 15 16 17 18
#> 17059.0625 24961.6923 37363.5000 74201.6667 149517.5000 363273.0000
# }