Learn R Programming

sdcMicro (version 4.6.0)

mafast: Fast and Simple Microaggregation

Description

Function to perform a fast and simple (primitive) method of microaggregation. (for large datasets)

Usage

mafast(obj, variables = NULL, by = NULL, aggr = 3, measure = mean)

Arguments

obj
either an object of class sdcMicroObj or a data frame or matrix
variables
variables to microaggregate. If obj is of class sdcMicroObj the numerical key variables are chosen per default.
by
grouping variable for microaggregation. If obj is of class sdcMicroObj the strata variables are chosen per default.
aggr
aggregation level (default=3)
measure
aggregation statistic, mean, median, trim, onestep (default = mean)

Value

If ‘obj’ was of class sdcMicroObj-class the corresponding slots are filled, like manipNumVars, risk and utility. If ‘obj’ was of class “data.frame” or “matrix” an object of the same class is returned.

Methods

list("signature(obj = \"ANY\")")
list("signature(obj = \"data.frame\")")
list("signature(obj = \"matrix\")")
list("signature(obj = \"sdcMicroObj\")")

See Also

microaggregation

Examples

Run this code
data(Tarragona)
m1 <- mafast(Tarragona, variables=c("GROSS.PROFIT","OPERATING.PROFIT","SALES"),aggr=3)
data(testdata)
m2 <- mafast(testdata,variables=c("expend","income","savings"),aggr=50,by="sex")
summary(m2)

## for objects of class sdcMicro:
data(testdata2)
sdc <- createSdcObj(testdata2,
  keyVars=c('urbrur','roof','walls','water','electcon','relat','sex'),
  numVars=c('expend','income','savings'), w='sampling_weight')
sdc <- dRisk(sdc)
sdc@risk$numeric
sdc1 <- mafast(sdc,aggr=4)
sdc1@risk$numeric

sdc2 <- mafast(sdc,aggr=10)
sdc2@risk$numeric
## Not run: 
# ### Performance tests
# x <- testdata
# for(i in 1:20){
#   x <- rbind(x,testdata)
# }
# system.time(xx <- mafast(x,variables=c("expend","income","savings"),aggr=50,by="sex"))
# ## End(Not run)

Run the code above in your browser using DataLab