# generate micro-data
N <- 2500
set.seed(123)
V1 <- sample(c("011","012","013","021","022"), N, replace=TRUE)
V2 <- sample(c("m","w"), N, replace=TRUE)
V3 <- sample(c("01","02"), N, replace=TRUE)
V4 <- sample(c("Aa","Ab", "Ac","Ba","Ca","Da","Db", "Ea","Fa","Fb",
"Ga","Gb","Ha","Ia","Ja","Jb","Ka","Kb"), N, replace=TRUE)
microDat <- data.frame(V1=V1,V2=V2,V3=V3,V4=V4)
microDat$numVal <- abs(round(rnorm(N, 500, 200),2))
sInd <- sample(floor(N/20))
microDat$numVal[sInd] <- abs(round(rnorm(sInd, 100000, 200),2))
# dimension 1
h1 <- c("@@", "@@@","@@@","@@@","@@", "@@@","@@@")
l1 <- c("010", "011", "012","013","020", "021","022")
df1 <- data.frame(h=h1, l=l1)
hier1 <- calcDimInfos(microDat, file=NULL, dataframe=df1, vName="V1")
# Level 2
h2 <- c("@@", "@@")
l2 <- c("m", "w")
df2 <- data.frame(h=h2, l=l2)
hier2 <- calcDimInfos(microDat, file=NULL, dataframe=df2, vName="V2")
# Level 3
h3 <- c("@@", "@@")
l3 <- c("A", "B")
df3 <- data.frame(h=h3, l=l3)
hier3 <- calcDimInfos(microDat, file=NULL, dataframe=df3, vName="V3")
# Level 4
h4 <- c("@@","@@@","@@@","@@@","@@","@@@","@@","@@@","@@","@@@","@@@",
"@@","@@@","@@","@@@","@@@","@@","@@@","@@@","@@","@@@",
"@@","@@@","@@","@@@","@@@","@@","@@@","@@@")
l4 <- c("A","Aa","Ab","Ac","B","Ba","C","Ca","D","Da","Db",
"E","Ea","F","Fa","Fb","G","Ga","Gb","H","Ha",
"I","Ia","J","Ja","Jb","K","Ka","Kb")
df4 <- data.frame(h=h4, l=l4)
hier4 <- calcDimInfos(microDat, file=NULL, dataframe=df4, vName="V4")
# the complete levelObject
levelObj <- list(hier1, hier2, hier3, hier4)
outObj <- calcFullTable(microDat, levelObj, numVar="numVal")
outObj <- primarySuppression(outObj, suppRule_Freq=c(3,0))
LPL <- rep(1, length(outObj$fullTabObj$strID)) # non negative
UPL <- rep(1, length(outObj$fullTabObj$strID)) # non negative
SPL <- rep(0, length(outObj$fullTabObj$strID)) # non negative
outObj <- setBounds(outObj, type="UPL", UPL)
outObj <- setBounds(outObj, type="LPL", LPL)
outObj <- setBounds(outObj, type="SPL", SPL)
outHITAS <- protectTable(outObj, solver="glpk", method="HITAS")
print(str(outHITAS))
Run the code above in your browser using DataLab