Last data update: 2014.03.03

R: Allows to transform a continuous variable into a categorical...
var.binR Documentation

Allows to transform a continuous variable into a categorical ordinal one by applying a modified version of the k-means clustering function in the 'stats' package.

Description

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.

Usage

var.bin(x,
		bins=3,
		iter.max=100)

Arguments

x

Continuous variable to be transformed into a categorical one

bins

Number of values of the resulting categorical variable

iter.max

Maximum number of iterations of the clustering algorithm

Value

Binned variable

Examples


library(SamplingStrata)
data(swissmunicipalities)
data(swissframe)
swissframe$X1 <- var.bin(swissmunicipalities$POPTOT,bins = 18)
table(swissframe$X1)
tapply(swissmunicipalities$POPTOT,swissframe$X1,mean)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(SamplingStrata)
Loading required package: memoise
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/SamplingStrata/var.bin.Rd_%03d_medium.png", width=480, height=480)
> ### Name: var.bin
> ### Title: Allows to transform a continuous variable into a categorical
> ###   ordinal one by applying a modified version of the k-means clustering
> ###   function in the 'stats' package.
> ### Aliases: var.bin
> ### Keywords: survey
> 
> ### ** Examples
> 
> ## No test: 
> 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 
> ## End(No test)
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>