Giter VIP home page Giter VIP logo

cellkey's People

Contributors

bernhard-da avatar gregordecillia avatar staudtlex avatar tenderle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cellkey's Issues

Error because of NA

Dear all,

I am testing the cellKey package version 0.18.11.
I generated my microdata, set up a table and tried to perturb it.
But I was not successful, because I get an error when I run the line
table1$perturb(v = c("data201801"))
The error is:
Error in if (abs_xj < zs) { : missing value where TRUE/FALSE needed

In the console, I get:

table1$perturb(v = c("data201801"))
j: 1 | ck: 0.578000000000021
xj: 2425.36 | x_delta: 670.62411134 | a: 216.69950057 | v: 0.5
x_hat: 335.312055670429
updating original value: old: 145323.91 | new: 145659.22205567
j: 2 | ck: 0.780000000000215
xj: 2360.2 | x_delta: 330.63591421 | a: 440.54265068 | v: 1
x_hat: 330.63591420704
updating original value: old: 145659.22205567 | new: 145989.857969877
j: 3 | ck: 0.800000000002157
xj: 2266.28 | x_delta: 129.38364013 | a: 1128.34866774 | v: 1
x_hat: 129.383640131454
updating original value: old: 145989.857969877 | new: 146119.241610009
j: 1 | ck: 0.645859999999998
xj: 2240.27 | x_delta: 642.75233248 | a: 30.16858753 | v: 0.5
x_hat: 321.37616624032
updating original value: old: 19390.93 | new: 19712.3061662403
j: 2 | ck: 0.458599999999986
xj: 2210.32 | x_delta: 318.92455918 | a: 61.80868045 | v: 0
x_hat: 0
updating original value: old: 19712.3061662403 | new: 19712.3061662403
j: 3 | ck: 0.585999999999864
xj: 2194.02 | x_delta: 127.02638778 | a: 155.18276565 | v: 0.5
x_hat: 63.5131938919976
updating original value: old: 19712.3061662403 | new: 19775.8193601323
j: 1 | ck: 0.198620000000032
xj: 2425.36 | x_delta: 670.62411134 | a: 117.75359499 | v: -1
x_hat: -670.624111340859
updating original value: old: 78968.4 | new: 78297.7758886591
j: 2 | ck: 0.986200000000321
xj: 2360.2 | x_delta: 330.63591421 | a: 236.80965232 | v: 3
x_hat: 991.907742621119
updating original value: old: 78297.7758886591 | new: 79289.6836312802
j: 3 | ck: 0.862000000003219
xj: 2154.16 | x_delta: 125.66797549 | a: 630.94581832 | v: 1.5
x_hat: 188.501963232935
updating original value: old: 79289.6836312802 | new: 79478.1855945132
j: 1 | ck: 0.770638
xj: 2177.65 | x_delta: 632.36805511 | a: 26.24076258 | v: 1
x_hat: 632.368055107586
updating original value: old: 16593.82 | new: 17226.1880551076
j: 2 | ck: 0.706387
xj: 2122.29 | x_delta: 311.37775407 | a: 55.32247513 | v: 1
x_hat: 311.377754065495
updating original value: old: 17226.1880551076 | new: 17537.5658091731
j: 3 | ck: 0.063877
xj: 1880.89 | x_delta: 564.267 | a: 31.08026131 | v: -2
x_hat: -1128.534
updating original value: old: 17537.5658091731 | new: 16409.0318091731
j: 1 | ck: 0.457950000000015
xj: 2266.28 | x_delta: 646.91820066 | a: 29.42940851 | v: 0
x_hat: 0
updating original value: old: 19038.42 | new: 19038.42
j: 2 | ck: 0.579500000000154
xj: 2213.59 | x_delta: 319.19503243 | a: 59.64510116 | v: 0.5
x_hat: 159.597516217141
updating original value: old: 19038.42 | new: 19198.0175162171
j: 3 | ck: 0.795000000001545
xj: 2194.55 | x_delta: 127.04416685 | a: 151.11293963 | v: 1
x_hat: 127.044166851882
updating original value: old: 19198.0175162171 | new: 19325.061683069
j: 1 | ck: 0.504946
xj: 1977.81 | x_delta: 593.343 | a: 19.09913827 | v: 0
x_hat: 0
updating original value: old: 11332.34 | new: 11332.34
j: 2 | ck: 0.049465
xj: 1708.81 | x_delta: 512.643 | a: 22.10571489 | v: -2.5
x_hat: -1281.6075
updating original value: old: 11332.34 | new: 10050.7325
j: 3 | ck: 0.49465
xj: 1450.57 | x_delta: 435.171 | a: 23.09605305 | v: 0
x_hat: 0
updating original value: old: 10050.7325 | new: 10050.7325
j: 1 | ck: 0.975329999999999
xj: 2425.36 | x_delta: 670.62411134 | a: 36.06030501 | v: 3
x_hat: 2011.87233402258
updating original value: old: 24182.91 | new: 26194.7823340226
j: 2 | ck: 0.753299999999999
xj: 1856.37 | x_delta: 556.911 | a: 47.03585013 | v: 1
x_hat: 556.911
updating original value: old: 26194.7823340226 | new: 26751.6933340226
j: 3 | ck: 0.532999999999997
xj: 1842.58 | x_delta: 552.774 | a: 48.39535386 | v: 0
x_hat: 0
updating original value: old: 26751.6933340226 | new: 26751.6933340226
j: 1 | ck: 0.7735
xj: 1314.92 | x_delta: 394.476 | a: 5.85870877 | v: 1
x_hat: 1183.428
updating original value: old: 2311.12 | new: 3494.548
j: 2 | ck: 0.73507
xj: 996.2 | x_delta: 298.86 | a: 11.69292645 | v: 1
x_hat: 896.58
updating original value: old: 3494.548 | new: 4391.128
j: 3 | ck: 0.35077
Error in if (abs_xj < zs) { : missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In if (ck == 0) { :
the condition has length > 1 and only the first element will be used
2: In if (ck == 0) { :
the condition has length > 1 and only the first element will be used
3: In if (ck == 0) { :
the condition has length > 1 and only the first element will be used
4: In if (ck == 0) { :
the condition has length > 1 and only the first element will be used
5: In if (ck == 0) { :
the condition has length > 1 and only the first element will be used
6: In if (ck == 0) { :
the condition has length > 1 and only the first element will be used
7: In if (ck == 0) { :
the condition has length > 1 and only the first element will be used
8: In if (ck == 0) { :
the condition has length > 1 and only the first element will be used

What should I do?
I enclose my code (to run it, folder path0 has to be created with subsolders path1, path2, path3).
use_of_ckm_v1.txt

Best regards,
Manca

error with reaching library(cellKey)

Hi,
I've worked with the cellkey package last week and it was OK. Today, I cannot use the package:

library(cellKey)
Error: package or namespace load failed for ‘cellKey’:
object ‘add_nodes’ is not exported by 'namespace:sdcTable'
I found this error but I don't know the date:
https://www.gitmemory.com/issue/sdcTools/UserSupport/113/488066782
Thanks

devtools::session_info()

  • Session info -----------------------------------------------------------------------------------------------------------------------
    setting value
    version R version 3.5.3 (2019-03-11)
    os Windows 7 x64 SP 1
    system x86_64, mingw32
    ui RStudio
    language (EN)
    collate Hungarian_Hungary.1250
    ctype Hungarian_Hungary.1250
    tz Europe/Prague
    date 2019-05-20

  • Packages ---------------------------------------------------------------------------------------------------------------------------
    package * version date lib source
    assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.5.3)
    backports 1.1.4 2019-04-10 [1] CRAN (R 3.5.3)
    callr 3.2.0 2019-03-15 [1] CRAN (R 3.5.3)
    cli 1.1.0 2019-03-19 [1] CRAN (R 3.5.3)
    colorspace 1.4-1 2019-03-18 [1] CRAN (R 3.5.3)
    crayon 1.3.4 2017-09-16 [1] CRAN (R 3.5.3)
    data.table * 1.12.2 2019-04-07 [1] CRAN (R 3.5.3)
    desc 1.2.0 2018-05-01 [1] CRAN (R 3.5.3)
    devtools 2.0.2 2019-04-08 [1] CRAN (R 3.5.3)
    digest 0.6.18 2018-10-10 [1] CRAN (R 3.5.3)
    dplyr 0.8.1 2019-05-14 [1] CRAN (R 3.5.3)
    evaluate 0.13 2019-02-12 [1] CRAN (R 3.5.3)
    flexdashboard 0.5.1.1 2018-06-29 [1] CRAN (R 3.5.1)
    fs 1.3.1 2019-05-06 [1] CRAN (R 3.5.3)
    ggplot2 3.1.1 2019-04-07 [1] CRAN (R 3.5.3)
    glue 1.3.1 2019-03-12 [1] CRAN (R 3.5.3)
    gtable 0.3.0 2019-03-25 [1] CRAN (R 3.5.3)
    htmltools 0.3.6 2017-04-28 [1] CRAN (R 3.5.1)
    httpuv 1.5.1 2019-04-05 [1] CRAN (R 3.5.3)
    jsonlite 1.6 2018-12-07 [1] CRAN (R 3.5.3)
    knitr 1.23 2019-05-18 [1] CRAN (R 3.5.3)
    later 0.8.0 2019-02-11 [1] CRAN (R 3.5.3)
    lattice 0.20-38 2018-11-04 [1] CRAN (R 3.5.3)
    lazyeval 0.2.2 2019-03-15 [1] CRAN (R 3.5.3)
    lpSolveAPI 5.5.2.0-17 2016-01-13 [1] CRAN (R 3.5.0)
    magrittr 1.5 2014-11-22 [1] CRAN (R 3.5.3)
    memoise 1.1.0 2017-04-21 [1] CRAN (R 3.5.3)
    mime 0.6 2018-10-05 [1] CRAN (R 3.5.2)
    munsell 0.5.0 2018-06-12 [1] CRAN (R 3.5.1)
    nloptr 1.2.1 2018-10-03 [1] CRAN (R 3.5.1)
    pillar 1.4.0 2019-05-11 [1] CRAN (R 3.5.3)
    pkgbuild 1.0.3 2019-03-20 [1] CRAN (R 3.5.3)
    pkgconfig 2.0.2 2018-08-16 [1] CRAN (R 3.5.1)
    pkgload 1.0.2 2018-10-29 [1] CRAN (R 3.5.3)
    plyr 1.8.4 2016-06-08 [1] CRAN (R 3.5.1)
    prettyunits 1.0.2 2015-07-13 [1] CRAN (R 3.5.3)
    primes 0.1.0 2015-06-22 [1] CRAN (R 3.5.1)
    processx 3.3.1 2019-05-08 [1] CRAN (R 3.5.3)
    promises 1.0.1 2018-04-13 [1] CRAN (R 3.5.1)
    ps 1.3.0 2018-12-21 [1] CRAN (R 3.5.3)
    ptable 0.2.0 2018-12-11 [1] Github (sdcTools/ptable@5651991)
    purrr 0.3.2 2019-03-15 [1] CRAN (R 3.5.3)
    R6 2.4.0 2019-02-14 [1] CRAN (R 3.5.3)
    RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 3.5.0)
    Rcpp 1.0.1 2019-03-17 [1] CRAN (R 3.5.3)
    remotes 2.0.4 2019-04-10 [1] CRAN (R 3.5.3)
    Rglpk 0.6-4 2019-02-09 [1] CRAN (R 3.5.2)
    rlang 0.3.4 2019-04-07 [1] CRAN (R 3.5.3)
    rmarkdown 1.12 2019-03-14 [1] CRAN (R 3.5.3)
    rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.5.3)
    rstudioapi 0.10 2019-03-19 [1] CRAN (R 3.5.3)
    scales 1.0.0 2018-08-09 [1] CRAN (R 3.5.1)
    sdcHierarchies 0.18 2019-04-23 [1] CRAN (R 3.5.3)
    sdcTable 0.27 2019-02-28 [1] CRAN (R 3.5.3)
    sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.5.3)
    shiny 1.3.2 2019-04-22 [1] CRAN (R 3.5.3)
    shinyjs 1.0 2018-01-08 [1] CRAN (R 3.5.3)
    shinythemes 1.1.2 2018-11-06 [1] CRAN (R 3.5.3)
    shinyTree 0.2.6 2018-10-05 [1] CRAN (R 3.5.3)
    slam 0.1-45 2019-02-26 [1] CRAN (R 3.5.2)
    stringi 1.4.3 2019-03-12 [1] CRAN (R 3.5.3)
    stringr 1.4.0 2019-02-10 [1] CRAN (R 3.5.3)
    tibble 2.1.1 2019-03-16 [1] CRAN (R 3.5.3)
    tidyselect 0.2.5 2018-10-11 [1] CRAN (R 3.5.1)
    usethis 1.5.0 2019-04-07 [1] CRAN (R 3.5.3)
    withr 2.1.2 2018-03-15 [1] CRAN (R 3.5.3)
    xfun 0.7 2019-05-14 [1] CRAN (R 3.5.3)
    xtable 1.8-4 2019-04-21 [1] CRAN (R 3.5.3)
    yaml 2.2.0 2018-07-25 [1] CRAN (R 3.5.2)

ck_setup() - Long execution time - Unable to generate hypercubes with more than 6 dimensions

Hi,

I am currently extracting Census hypercubes using the function ck_setup() from the package cellKey. The issue I am facing is that the execution time is excessively long. I would like to understand whether I am working inefficiently or missing something.

The code in the extract below ran for 5 hours, at which point I decided to stop the process and therefore was unable to generate this hypercube. The same thing happens with any other hypercube of similar size (8 dimensions).

# Defining the dimensions of hypercube 6
dims6 <- list(GEO.L = dim_geo.l, SEX=dim_sex, AGE.M=dim_age.m, LPW.N=dim_lpw.n, OCC=dim_occ, IND.L=dim_ind.l, SIE=dim_sie, EDU=dim_edu)

# Setting up a table instance for hypercube 6
hc_6 <- cellKey::ck_setup(x = data, rkey = "r_keys", dims = dims6, w = NULL) 

For comparison, the following code took around 15 minutes to execute and I was able to generate the hypercube. Therefore, at the moment, I am only able to generate hypercubes having 6 dimensions or less.

# Defining the dimensions of hypercube 1
dims1 <- list(GEO.N = dim_geo.n, SEX = dim_sex, AGE.H = dim_age.h, LMS.H=dim_lms.h, HST.H=dim_hst.h, FST.H=dim_fst.h)                             				      

# Setting up a table instance for hypercube 1
hc_1 <- cellKey::ck_setup(x = data, rkey = "r_keys", dims = dims1, w = NULL)

Is it normal for the execution to take so long or am I doing something which is slowing the process down? What can I do to be able to generate the hypercubes having more than 6 dimensions?

To provide further detail on the problem, I am attaching the R workspace image file containing the hierarchies I am using (WorkspaceImage_VA.zip). The data itself is not provided but it is in the format of a data frame with 59 variables and 413267 observations. One of the variables (r_keys) contains the record keys. There are no weights.

Looking forward to your feedback.

Cell Key Method - Error in y$is_rootnode : $ operator is invalid for atomic vectors

Hi,

I'm trying out the Cell Key Method using the R packages cellKey and sdcHierarchies by following the documentation (https://sdctools.github.io/cellKey/articles/introduction.html). I encountered the following error when running the command:

hc_1.1 <- cellKey::ck_setup(x = data,
                   rkey = "r_keys",
                   dims = dims,
                   w = NULL)

Capture

I tried debugging using: debug(ck_setup) but was unable to reach the lines where the error is being generated. There was a warning saying 'Debug location is approximate because the source is not available'.

Am I missing something? @bernhard-da @tenderle any help would be appreciated :) I am attaching the workspace image and R script for reference. Since I cannot provide the microdata, I am providing the output to str(data):

Capture_3

I am using the following package versions:

Capture_2

CKM_RScript_WorkspaceImage.zip

table input

allow a table with given cell-keys as input to perform the perturbation

Dependency on ptable

I am preparing the ptable-package for a CRAN publication and changed some functions to internal ones. A push request with some suggested changes in cellKey will follow.

Consistent perturbation

Hi @bernhard-da,

attached you will find a short example of the perturbation tests on consistency we did. I produced several results using the data set dat <- dat[,c("sex","age","income"),].

I ran the perturbation four times. On the one hand, I distinguished between a complete data set dat1 <- dat and a reduced data set dat2 <- dat[income>0,,]. Then, I compared the built-in key generation (a) ck_create_input(..., def_rkey=9, ...) vs. (b) pre-drawn keys ck_create_input(..., def_rkey="rkeys_predrawn",...).

Now we have the following two issues:

  • Perturbation of frequencies: When removing units from the data, the built-in key generation results in different cell keys and, hence, different perturbation for unaffected frequencies (compare res_destatis_1a@tab with res_destatis_2a@tab). However, if we use externally pre-drawn record key option of your function, we get consistent perturbations (compare res_destatis_1b@tab with res_destatis_2b@tab).

  • Perturbation of continuous variables: As Sarah mentioned in her mail, the ABS approach for continuous data produces some inconsistencies if a user removes units with zero contribution to a continuous variable (e.g. income = 0). Therefore, I removed the one unit (sex==1 & age==3 & income==0) and received dat2. Let's compare the column income.pert in res_destatis_1a@tab and res_destatis_2a@tab As expected (because of the abs approach), there are different cell keys and perturbed incomes for sex==1 & age==3 as well as for higher aggregates. However, there are also different cell keys and results for other cells such as sex==1 & age==1. In case of the externally pre-drawn record keys, we can also observe differences (but only for perturbed income not cell keys).

Is it possible to solve the issues? In case of the consistency issue for continuous variables - that may be also of interest for @ppdewolf - Sarah solved the issue within an destatis-internal prototype. She multiplied the original record key by a dichotomous indicator variable: 0=no contribution of the continuous variable (e.g. income=0) such that the cell key will be identical to the case that users exclude such units from the data set, and 1=otherwise. May that be a solution for both of you?

Best,
@tenderle

Here is the complete code:

# Cell Key
library(cellKey)

## The data set (sex, age, income)
dat <- ck_create_testdata()
dat <- dat[,c("sex","age","income"),]

dim.sex <- data.table(levels=c("@","@@","@@"), codes=c("Total", "male","female"))
dim.age <- data.table(levels=c("@",rep("@@", 6)), codes=c("Total", paste0("age_group",1:6)))
dimList <- list(sex=dim.sex, age=dim.age)
weightVar <- NULL
numVars <- c("income")

# parameters
pTable_destatis <- ck_create_pTable(type="destatis")
sTable <- ck_generate_sTable(smallC=12)
mTable <- c(0.6,0.4,0.2)

pert_params_destatis <- ck_create_pert_params(
  smallN=12,
  pTable=pTable_destatis,
  sTable=sTable,
  mTable=mTable)

# Externally predrawn record keys
set.seed(123)
dat$rkeys_predrawn <- round(runif(dim(dat)[1]), 9)

## Two data set ('dat1' with all individuals, and 'dat2' with those which have positive income)

# i.e. one unit will be excluded in dat2 (sex=1, age=3 and income=0)
dat[income==0,,]

dat1 <- dat
dat2 <- dat[income>0,,]

## (a) Both data sets using the implemted key generation
inp_destatis_1a <- ck_create_input(
  dat=dat1,
  def_rkey=9,
  pert_params=pert_params_destatis)

inp_destatis_2a <- ck_create_input(
  dat=dat2,
  def_rkey=9,
  pert_params=pert_params_destatis)

res_destatis_1a <- perturbTable(
  inp=inp_destatis_1a,
  dimList=dimList,
  weightVar=weightVar, numVars=numVars)

res_destatis_2a <- perturbTable(
  inp=inp_destatis_2a,
  dimList=dimList,
  weightVar=weightVar, numVars=numVars)


## (b) Both data sets using externally generated keys
inp_destatis_1b <- ck_create_input(
  dat=dat1,
  def_rkey="rkeys_predrawn",
  pert_params=pert_params_destatis)

inp_destatis_2b <- ck_create_input(
  dat=dat2,
  def_rkey="rkeys_predrawn",
  pert_params=pert_params_destatis)


res_destatis_1b <- perturbTable(
  inp=inp_destatis_1b,
  dimList=dimList,
  weightVar=weightVar, numVars=numVars)

res_destatis_2b <- perturbTable(
  inp=inp_destatis_2b,
  dimList=dimList,
  weightVar=weightVar, numVars=numVars)

## Results (a)
res_destatis_1a@tab[,cellKey:=res_destatis_1a@cellKeys,]
res_destatis_2a@tab[,cellKey:=res_destatis_2a@cellKeys,]

res_destatis_1a@tab
res_destatis_2a@tab

## Results (b)
res_destatis_1b@tab[,cellKey:=res_destatis_1b@cellKeys,]
res_destatis_2b@tab[,cellKey:=res_destatis_2b@cellKeys,]

res_destatis_1b@tab
res_destatis_2b@tab

Package installation problem

Hello,
I receive an error when i run this command :

install_github(
repo = "sdcTools/cellKey",
force = TRUE
)

Error message :

Installing package into ‘XXXXXXXXX/3.4’
(as ‘lib’ is unspecified)

  • installing source package ‘cellKey’ ...
    ** R
    ** data
    *** moving datasets to lazyload DB
    ** preparing package for lazy loading
    Error : object ‘add_nodes’ is not exported by 'namespace:sdcTable'
    ERROR: lazy loading failed for package ‘cellKey’
  • removing ‘XXXXXXXXXXXXX/3.4/cellKey’
    Error in i.p(...) :
    (converted from warning) installation of package ‘/tmp/RtmpGpvGVc/file5c84f85c6f4/cellKey_0.15.1.tar.gz’ had non-zero exit status

Can someone help me ?

Testing the 'destatis' functionality

Hi Bernhard,

I tested your implementation using type='destatis' and externally generated record keys and then cross checked the results with our SAS implementation. I got the same perturbed tables. It works fine. Thx for the implementation so far.

One of you slots in class pert_table is called cellKeys and defined as integer. It works with the 'abs' implementation. However, using type='destatis' results in zeroes since the 'destatis'-formatted cell keys are numeric.

Is it possible to change it such that the 'destatis'-formatted cell keys are part of the output?

Thx,
Tobias

error: Error in if (type == "abs") { : argument is of length zero

Hello,
my code:

HC_92_HU<- read.csv2("H:/munkafile-ok/hc_92_1010_minta_egyben.csv", header=TRUE, sep=";", dec=",", fill=TRUE)
colnames(HC_92_HU)<-c("geo_m", "sex", "age_m", "yae_h", "usual_resident", "spv_cov_imputation_flag")

head(HC_92_HU)

set.seed(123)
options(scipen=999)
HC_92_HU$recordkey<-runif(dim(HC_92_HU)[1])
head(HC_92_HU)

params_new <- pt_create_pParams(D=2, V=0.9)
ptable_destatis_new <- pt_create_pTable(params = params_new, type = "destatis")

inp <- ck_create_input( dat=HC_92_HU, def_rkey="recordkey", pert_params=params_new)

Error:
Error in if (type == "abs") { : argument is of length zero

Can you please help?
Thank you!

Results when creating perturbed magnitude tables for subgroups of data

@bernhard-da When using the by argument and creating perturbed magnitude tables directly one after another, I don't get the appropriate results. E.g. for by="cnt_posincome" or by="cnt_females" the results are not the ones I should get.

Here is the example:

library(cellKey)


## loading testdata and adding record keys (for abs-algorithm)
dat <- ck_create_testdata()

## create some 0/1 variables that should be perturbed later
dat[,cnt_females:=ifelse(sex=="male", 0, 1)]
dat[,cnt_males:=ifelse(sex=="male", 1, 0)]
dat[,cnt_highincome:=ifelse(income>=9000, 1, 0)]
dat[,cnt_posincome:=ifelse(income>0, 1, 0)]

pert_params_destatis <- ck_create_pert_params(
  smallN=12,
  pTable=ck_create_pTable(type="destatis"),
  sTable=ck_generate_sTable(smallC=12),
  mTable=c(0.6,0.4,0.2))

inp_destatis <- ck_create_input(dat=dat,def_rkey=9,pert_params=pert_params_destatis)

dim.sex <- ck_create_node(total_lab="Total")
dim.sex <- ck_add_nodes(dim.sex, reference_node="Total", node_labs=c("male","female"))

dim.age <- ck_create_node(total_lab="Total")
dim.age <- ck_add_nodes(dim.age,reference_node="Total", node_labs=paste0("age_group",1:6))

## define required inputs
dimList <- list(sex=dim.sex, age=dim.age)
weightVar <- "sampling_weight"
numVars <- c("savings", "income")

## create perturbed magnitude table for subgroups of data
res <- perturbTable(
  inp=inp_destatis,
  dimList=dimList,
  weightVar=weightVar,
  countVars=c("cnt_females", "cnt_males","cnt_highincome"),
  numVars=numVars, by="cnt_males")

ck_cont_table(res, vname="income")


res <- perturbTable(
  inp=inp_destatis,
  dimList=dimList,
  weightVar=weightVar,
  countVars=c("cnt_females", "cnt_males","cnt_highincome","cnt_posincome"),
  numVars=numVars, by="cnt_posincome")

ck_cont_table(res, vname="income")


res <- perturbTable(
  inp=inp_destatis,
  dimList=dimList,
  weightVar=weightVar,
  countVars=c("cnt_females", "cnt_males","cnt_highincome","cnt_posincome"),
  numVars=numVars, by="cnt_females")

ck_cont_table(res, vname="income")

If you reorder res <- perturbTable() and run the whole example you get the expected results for the first res.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.