knitr::opts_knit$set(
        stop_on_error = 2L
)
knitr::opts_chunk$set(
    fig.height = 7,
    fig.width = 7
)

Differentially Private Variance with dpVariance

The dpVariance class evaluates a privacy-preserving variance of a vector of values. The class supports any vector type that can be represented numerically, meaning that it can handle the R types numeric, integer, and logical.

Syntax

# import the library
library(PSIlence)

# example data
x1 <- c(3, 12, 20, 42, 33, 65, 70, 54, 33, 45)
x2 <- c(TRUE, FALSE, FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, FALSE, TRUE)
data <- data.frame(x1, x2)

# example on a numeric variable
dpVarianceExample <- dpVariance$new(mechanism='mechanismLaplace', varType='numeric',
                      variable='x1', epsilon=10, n=10, rng=c(0, 70))
dpVarianceExample$release(data)
print(dpVarianceExample$result)

# example on a logical variable
dpVarianceExample2 <- dpVariance$new(mechanism='mechanismLaplace', varType='logical',
                       variable='x2', epsilon=0.1, n=10, rng=c(0, 1))
dpVarianceExample2$release(data)
print(dpVarianceExample2$result)

Arguments

In typical usage, there are two methods to the dpVariance class: the new method and the release method. The new method does not touch any data, it just creates an object that can calculate a differentially private covariance matrix. Only the release method touches data, and applies the functionality of the previously created object to the data.

 

The release method accepts a single argument.

Values

The release method makes a call to the mechanism, which generates a list of statistical summaries available on the result field.

 

The list in the result attribute has the following values.

 

Examples

Import the PSIlence library and attach the sample dataset:

library(PSIlence)
data(PUMS5extract10000)

 

Numeric Example

To calculate a private variance of a numeric vector with dpVariance, enter the mechanism (this will be the Laplace Mechanism, or 'mechanismLaplace'), the variable type ('numeric'), the variable of interest (the column name of the variable in the dataframe), the number of observations in the dataframe, the epsilon value (generally less than 1), and the range:

numericVariance <- dpVariance$new(mechanism='mechanismLaplace', varType='numeric',
                           variable='income', n=10000, epsilon=0.1, rng=c(0, 750000))
numericVariance$release(PUMS5extract10000)
print(numericVariance$result)

 

Logical Example

To calculate the variance of a logical variable, input a the name of a logical vector into variable and update varType to 'logical'. Note: you do not need to enter a range for a logical variable (because the range is known to be c(0,1)).

logicalVariance <- dpVariance$new(mechanism='mechanismLaplace', varType='logical',
                           variable='married', n=10000, epsilon=0.1, rng=c(0, 1))
logicalVariance$release(PUMS5extract10000)
print(logicalVariance$result)

Notes



privacytoolsproject/PSI-Library documentation built on Feb. 17, 2020, 2:03 p.m.