Skip to content

Commit 766efe1

Browse files
authored
Merge pull request #16 from tenderle/master
Version 0.2.0 Prototype Version for Census Testing
2 parents 68f7fe8 + 23046e3 commit 766efe1

16 files changed

+503
-43
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
.Ruserdata
55
*.Rproj
66
*.html
7-
Readme.Rmd
7+
Readme.Rmd
8+
inst/doc

DESCRIPTION

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
Package: ptable
22
Type: Package
3-
Date: 2018-11-20
3+
Date: 2018-12-02
44
Title: Generation of perturbation tables
5-
Version: 0.1.13
5+
Version: 0.2.0
66
Authors@R: c(person("Tobias", "Enderle", email = "[email protected]", role = c("aut", "cre")),
77
person("Sarah", "Giessing", email = "[email protected]", role = c("ctb")))
88
Description: This package computes perturbation tables with probabilities or pre-drawn perturbation values.
99
Imports: data.table,nloptr,RColorBrewer,flexdashboard,lattice,methods,rlang,rmarkdown,ggplot2
10-
Suggests: cellKey, sdcTable
10+
Suggests: cellKey, sdcTable,
11+
knitr
1112
License: EUPL
1213
Encoding: UTF-8
1314
Maintainer: Tobias Enderle <[email protected]>
1415
LazyData: true
15-
RoxygenNote: 6.0.1
16+
RoxygenNote: 6.0.1
17+
VignetteBuilder: knitr

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export(fifi_plot)
44
export(pt_create_pParams)
55
export(pt_create_pTable)
66
export(pt_export)
7+
export(pt_vignette)
78
export(ptable)
89
exportClasses(ptable)
910
exportClasses(ptable_params)
@@ -42,4 +43,5 @@ importFrom(stats,formula)
4243
importFrom(stats,runif)
4344
importFrom(stats,weights)
4445
importFrom(stats,xtabs)
46+
importFrom(utils,RShowDoc)
4547
importFrom(utils,write.table)

R/pt_create_pParams.R

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
#'
33
#' creates the required input for \code{\linkS4class{ptable}}.
44
#'
5-
#' @param D perturbation parameter for maximum perturbation (scalar or vector)
5+
#' @param D perturbation parameter for maximum noise/perturbation (scalar or vector)
66
#' @param V perturbation parameter for variance (scalar)
7-
#' @param js treshold value for blocking of small frequencies (i.e. there won't occur positive target frequencies below the treshold value)
8-
#' Target frequencies are defined by ...
9-
#' @param pstay optional parameter to set
7+
#' @param js treshold value for blocking of small frequencies (i.e. the perturbation will not produce positive cell values that are equal to or smaller than the treshold value).
8+
#' @param pstay optional parameter to set the probability (0 < p < 1) of an original frequency to remain unperturbed: NA (default) no preset probability (i.e. produces the maximum entropy solution)
109
#' @param optim optimization parameter: \code{1} standard approach (default)
1110
#' @param mono (logical) vector specifying optimization parameter for monotony condition
1211
#' @param epsilon (double)
@@ -36,8 +35,10 @@ pt_create_pParams <-function(D, V, js=0, pstay=NULL, optim=1, mono=TRUE, epsilon
3635
stopifnot(is_bare_logical(mono))
3736
stopifnot(is_bare_integerish(pTableSize))
3837

39-
if (is.null(pstay)) pstay <- 0
40-
stopifnot(is_bare_numeric(pstay))
38+
if (is.null(pstay)) pstay <- NA
39+
#stopifnot(is_bare_numeric(pstay))
40+
if(sum(c(0,1) %in% pstay) > 0)
41+
stop(paste("Parameter 'pstay' must be larger than zero and smaller than one (i.e. 0 < pstay < 1)."))
4142

4243

4344
if (js==0) ncat <- D

R/pt_create_pTable.R

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
#' pt_create_pTable
22
#'
33
#' produces perturbation table that is needed to add noise to statistical frequency tables. The perturbation probabilities are constructed given the following constraints:
4-
#' 1. Zero mean
5-
#' 2. Constant variance
6-
#' 3. Probabilities are between zero and one
7-
#' 4.
8-
#' 5. probabilities sum up to 1
4+
#' - Unbiasedness of the noise
5+
#' - Fixed noise variance
6+
#' - Transition probabilities are between zero and one and the sum up to 1
7+
#' - Perturbations will not produce negaive cell values or positive cell values equal to or less than a specific threshold value
8+
#' - The absolute value of any perturbation is less than a specific integer value (i.e. the maxiumum noise)
9+
#'
10+
#' For more information, see the vignette using \code{pt_vignette()}.
911
#' @md
1012
#'
1113
#' @param params an object of class \code{\linkS4class{ptable_params}}
1214
#' generated with \code{\link{pt_create_pParams}}
13-
#' @param type (character) type of pTable (either 'abs' or 'destatis')
15+
#' @param type (character) type of pTable, either 'destatis' (default) or 'abs' or 'abs2'
1416
#' @param monitoring (logical) output monitoring on/off
1517
#' @param debugging (logical) debug monitoring on/off
1618
#'
@@ -29,7 +31,7 @@
2931
#' @rdname pt_create_pTable
3032
#' @export
3133
#'
32-
pt_create_pTable <-function(params, type, monitoring=FALSE, debugging=FALSE){
34+
pt_create_pTable <-function(params, type="destatis", monitoring=FALSE, debugging=FALSE){
3335
. <- v <- p <- NULL
3436
pert_params <- params
3537

@@ -41,6 +43,8 @@ pt_create_pTable <-function(params, type, monitoring=FALSE, debugging=FALSE){
4143
V <- slot(pert_params, "V")
4244
js <- slot(pert_params, "js")
4345
pstay <- slot(pert_params, "pstay")
46+
pstay[is.na(pstay)] <- 0
47+
4448
mono <- slot(pert_params, "mono")
4549
epsilon <- slot(pert_params, "epsilon")
4650

R/pt_export.R

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#' pt_export
22
#'
3-
#' Function to export ptable (csv).
3+
#' Function to export perturbation table to Tau-Argus or SAS (as csv-file).
44
#'
55
#' @param input an object of class \code{\linkS4class{ptable}}
66
#' @param file (character) filename
7+
#' @param SDCtool (character) either "TauArgus" or "SAS"
78
#'
89
#' @author Tobias Enderle
910
#' @keywords export
@@ -12,13 +13,13 @@
1213
#' params <- pt_create_pParams(D=5, V=3, js=2, label="test")
1314
#' ptable_destatis <- pt_create_pTable(params=params, type="destatis")
1415
#' \dontrun{
15-
#' pt_export(ptable_destatis,file="Test")
16+
#' pt_export(ptable_destatis,file="Test", SDCtool="TauArgus")
1617
#' }
1718
#'
1819
#' @rdname pt_export
1920
#' @export
2021
#'
21-
pt_export <- function(input, file){
22+
pt_export <- function(input, file, SDCtool="TauArgus"){
2223

2324
stopifnot(isS4(input))
2425
stopifnot(class(input)=="ptable")
@@ -27,7 +28,14 @@ pt_export <- function(input, file){
2728
type <- slot(params, "type")
2829
stopifnot(type=="destatis")
2930

30-
pTable <- slot(input, "pTable")[,c('i','j','p','v','p_int_ub'),]
31+
stopifnot(SDCtool %in% c("TauArgus","SAS"))
32+
33+
if (SDCtool=="TauArgus")
34+
pTable <- slot(input, "pTable")[,c('i','j','p','v','p_int_ub'),]
35+
36+
if (SDCtool=="SAS")
37+
pTable <- slot(input, "pTable")[,c('i','j','p','v','p_int_lb','p_int_ub'),]
38+
3139

3240
write.table(pTable, file=paste(file,".csv",sep=""), sep=";", dec=".", row.names = FALSE, col.names = TRUE)
3341
}

R/pt_vignette.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#' pt_vignette
2+
#'
3+
#' starts the package vignette that gets you started with the package
4+
#'
5+
#' @return a browser windows/tab with showing the vignette
6+
#' @export
7+
#' @importFrom utils RShowDoc
8+
#' @examples
9+
#' \dontrun{
10+
#' pt_vignette()
11+
#' }
12+
pt_vignette <- function() {
13+
RShowDoc("introduction", package="ptable")
14+
}

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,24 @@ We have a first rough version with which interested users may play around. Feedb
1919

2020
- Merge the two main functions `pt_create_pParams(...)` and `pt_create_pTable(...)` into one function
2121
- Allow for special cases: extended parameter setting, i.e. improved row-wise parameter settings
22-
- Add theoretical short description
23-
- Add vignettes (documentation)
2422
- Add error codes
2523
- Improved `fifi_...`-functions
2624
- Add test environment
2725
- Improve accuracy of ptable by means of digits-functionality
2826
- Add generic functions in pt\_methods.R, e.g. plot(...)
2927
- Update optimization for predrawn allocation if `type="abs"`
3028

29+
#### Version 0.2.0
30+
31+
- Prototype Version for Testing (Census)
32+
33+
#### Version 0.1.14
34+
35+
- feature: new argument `SDCtool` of function `pt_export()`: either "TauArgus" or "SAS"
36+
- feature: vignette and new function `pt_vignette()` to show it
37+
- updated default for argument `pstay` in function `pt_create_pParams()`
38+
- updated default for argument `type` in function `pt_create_pTable()`
39+
3140
#### Version 0.1.12/13
3241

3342
- Prepared for prototype testing
@@ -72,13 +81,12 @@ We have a first rough version with which interested users may play around. Feedb
7281

7382
- first uploaded version
7483

75-
7684
### Installation
7785

7886
The package can directly be installed from `github`
7987

8088
``` r
81-
devtools::install_github("sdcTools/ptable", build_vignette=FALSE)
89+
devtools::install_github("sdcTools/ptable", build_vignette=TRUE)
8290
```
8391

8492
### Usage

inst/pt_dashboard.Rmd

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,13 @@ numericInput(inputId="V", label="Variance (=V)",
2727
value=3, min = 0.1, max = 5, step = 0.1, width="100px")
2828
sliderInput("js", label = "Treshold (=js)",
2929
min = 0, max = 5, value = 2, step = 1)
30-
sliderInput("pstay", label = "Probability of frequencies not to be perturbed (=pstay)",
31-
min = 0, max = 1, value = 0, step = 0.05)
30+
31+
numericInput(inputId="pstay", label="Preset probability of frequencies not to be perturbed (=pstay)", value=NA, min = 0.05, max = 0.99, step = 0.05, width="200px")
32+
#checkboxInput("pstayset", "Preset probability of frequencies not to be perturbed (=pstay)", value=FALSE, width = NULL)
33+
#test <- reactive(input$pstayset)
34+
#if (reactive(test()) == TRUE) pstay <- NA
35+
#sliderInput("pstay", label = "Set probability (=pstay)",
36+
# min = 0.05, max = 0.95, value = 0.5, step = 0.05)
3237
3338
checkboxInput("mono", "Set Monotony", value = TRUE, width = NULL)
3439
radioButtons("optim", "Set of objective functions (=optim)",

man/pt_create_pParams.Rd

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/pt_create_pTable.Rd

Lines changed: 12 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/pt_export.Rd

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/pt_vignette.Rd

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/bibtex.bib

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@article{giessing2016,
2+
author = "Giessing, Sarah",
3+
title = {Computational Issues in the Design of Transition Probabilities and Disclosure Risk Estimation for Additive Noise},
4+
journal = {Privacy in Statistical Databases},
5+
year = 2016,
6+
volume = {9867},
7+
publisher = "Springer",
8+
pages = {237--251}
9+
}
10+
11+
12+
@article{marley2011,
13+
author = "Marley, J. K. and Leaver, V. L.",
14+
Title = { A method for confidentialising user-defined tables: Statistical proper-ties and a risk-utility analysis.},
15+
journal = {Proceedings of 58th World Statistical Congress},
16+
year = 2011,
17+
pages = {1072--1081}
18+
}
19+
20+

vignettes/desktop.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[LocalizedFileNames]
2+
bibtex.bib[email protected],0

0 commit comments

Comments
 (0)