Learn R Programming

tidydp (version 0.1.0)

dp_add_noise: Add Differentially Private Noise to Data Frame Columns

Description

Adds calibrated Laplace or Gaussian noise to specified numeric columns in a data frame to achieve differential privacy. This is the primary function for column-level privacy.

Usage

dp_add_noise(
  data,
  columns,
  epsilon,
  delta = NULL,
  lower = NULL,
  upper = NULL,
  mechanism = NULL,
  .budget = NULL
)

Value

Data frame with noise added to specified columns

Arguments

data

A data frame

columns

Character vector of column names to add noise to

epsilon

Privacy parameter (smaller = more privacy, more noise)

delta

Privacy parameter for Gaussian mechanism (default: NULL, uses Laplace)

lower

Named numeric vector of lower bounds for each column

upper

Named numeric vector of upper bounds for each column

mechanism

Either "laplace" or "gaussian" (auto-selected based on delta if NULL)

.budget

Optional privacy budget object to track expenditure

Examples

Run this code
data <- data.frame(age = c(25, 30, 35, 40), income = c(50000, 60000, 70000, 80000))
private_data <- data %>%
  dp_add_noise(
    columns = c("age", "income"),
    epsilon = 0.1,
    lower = c(age = 0, income = 0),
    upper = c(age = 100, income = 200000)
  )

Run the code above in your browser using DataLab