## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")

## ----setup--------------------------------------------------------------------
library(DPrivStats)
set.seed(7)

## -----------------------------------------------------------------------------
data(example_microdata)
fit <- dp_lm(income ~ education + age + hours, example_microdata,
             epsilon = 2.0, delta = 1e-6,
             bounds = list(y = c(0, 500000)))
fit

## -----------------------------------------------------------------------------
ci <- dp_confint(fit)
ci

## -----------------------------------------------------------------------------
dp_confint(fit, method = "parametric_bootstrap", B = 200)

## -----------------------------------------------------------------------------
d <- transform(example_microdata,
               high_income = as.numeric(income > 60000))
glm_fit <- dp_glm(high_income ~ education + age, d, binomial(),
                  epsilon = 2.0, delta = 1e-6,
                  max_grad_norm = 1, n_iter = 300, lr = 0.05,
                  bounds = list(y = c(0, 1)))
glm_fit

## -----------------------------------------------------------------------------
gen <- function(n) {
  data.frame(x = rnorm(n, 2, 1))
}
set.seed(1)
vc <- validate_coverage(y ~ x, c(`(Intercept)` = 1, x = 2),
                        sigma = 1, data_gen = gen, n = 400, n_sims = 50,
                        epsilon = 3, delta = 1e-6,
                        y_bounds = c(-20, 20))
vc$coverage_rate

