Learn R Programming

sdcMicro (version 5.6.1)

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)

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.

Arguments

obj

either a sdcMicroObj-class-object or a data.frame

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)

Author

Alexander Kowarik

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
if (FALSE) {
### 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"))
}

Run the code above in your browser using DataLab