---
title: "DP Scree Plots"
description: >
Estimate private scree values, inspect PVE, select clipped, PMWM, or Huber
controls, and customize scree plots.
output:
rmarkdown::html_vignette:
toc: true
toc_depth: 2
vignette: >
%\VignetteIndexEntry{DP Scree Plots}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r scree-setup, include=FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.align = "center",
fig.width = 7,
fig.height = 5,
message = FALSE,
warning = TRUE,
error = FALSE,
cache = FALSE
)
```
This tutorial shows how to use `dp_scree()` to estimate private scree values and proportions of variance explained (PVE), inspect the results, and draw
scree and PVE plots. Also, it explains how to choose among the **clipped mean**, **private modified winsorized mean (PMWM)**, and **Huber mean** estimators.
The focus here is on **R arguments, control settings, and visualization**.
For the paired-difference construction, mathematical formulas, and privacy accounting, see [DP Scree Methodology](method-dp-scree.html).
For installation, example datasets, input requirements, and general privacy budget allocation, see [Getting Started](tutorials-getting-started.html).
## 1. Load the example data
We use `gau`, a synthetic dataset with 1,000 observations and 20 numeric variables.
For more details, see the documentation for [`gau`](../reference/gau.html).
```{r scree-data}
library(dppca)
data("gau", package = "dppca")
X <- gau
dim(X)
```
## 2. Set the privacy budget and estimate scree values
Scree estimation needs a `loading` budget for private PC directions and a `scree` budget for the private variance estimator.
When `split` is omitted,`dp_scree()` divides the total budget **equally** between these two components.
```{r scree-privacy}
scree_privacy <- privacy_control(
eps = 6,
delta = 1e-4
)
```
You can also specify a different allocation using `split` as explained in [Getting Started](tutorials-getting-started.html).
First, we use the clipped mean method to estimate scree values for the first five PCs:
```{r scree-fit}
set.seed(123)
scree_fit <- dp_scree(
X,
k = 5,
privacy = scree_privacy,
method = "clipped",
control = clipped_control(C_clip = 20),
non_private = TRUE
)
scree_fit
```
The `clipped_control()` function requires a public clipping threshold. The value `C_clip = 20` is an illustrative setting, not an automatic or universally recommended choice.
The main arguments of `dp_scree()` are:
::: {.scree-argument-table}
| Argument | Description |
|:--|:--|
| `X` | Input observations, with numeric features in columns. |
| `k` | Number of leading PCs to estimate, from 1 to the number of numeric variables. |
| `privacy` | Total budget and loading/scree allocation from `privacy_control()`. |
| `method` | One or more of `"clipped"`, `"pmwm"`, and `"huber"` (default: `"clipped"`). |
| `control` | Method-specific tuning parameters, specified using `clipped_control()`, `pmwm_control()`, or `huber_control()`. |
| `cpp.option` | Use the compiled direction estimator (`TRUE`, the default) or its R implementation (`FALSE`). |
| `mono` | Enforce a nonincreasing scree sequence via isotonic regression (default: `TRUE`). |
| `non_private` | Compute an ordinary PCA comparison when `TRUE` (default: `FALSE`). |
| `V_dp` | Optionally reuse previously estimated private directions; their earlier loading budget must still be recorded. |
:::
## 3. Inspect and plot the result
Printing `scree_fit` shows a short overview of the fitted results.
To see scree values, PVE, and cumulative PVE for each stored method, use `summary()`:
```{r scree-summary}
scree_summary <- summary(scree_fit)
scree_summary
```
The numeric estimates remain directly accessible by method.
The optional ordinary PCA reference is under `nonprivate`, while data dimensions, selected methods, and privacy allocations are under `metadata`:
```{r scree-values}
scree_fit$clipped$scree
scree_fit$clipped$pve
scree_fit$nonprivate$scree
scree_fit$metadata$privacy
```
In a default private-only fit (`non_private = FALSE`), `scree_fit$nonprivate` is `NULL`; `scree_fit$clipped`, `$pmwm`, or `$huber` remain top-level method results.
By default, `plot()` displays both the PVE and scree plots side by side. Because this example was fitted with `non_private = TRUE`,
the ordinary PCA reference is included automatically; a fit with `non_private = FALSE` shows only private estimates:
```{r scree-default-plots, fig.width=12, fig.height=4.5, out.width="100%", results="hide", fig.alt="Private and ordinary PCA PVE and scree plots"}
plot(scree_fit)
```
To display only one view, use `type`.
```{r scree-select-views, eval=FALSE}
plot(scree_fit, type = "pve")
plot(scree_fit, type = "scree")
```
::: {.scree-plot-table}
| Plot type | What it shows |
|:--|:--|
| `"pve"` | Each component's share of the estimated variation among the `k` fitted PCs. |
| `"scree"` | Estimated variation along each private PC direction, on its original scale. |
:::
## 4. Choose a method and its tuning parameters
The three scree estimators use the same projected paired differences, but differ in how they estimate their means.
The tables below map the symbols used in [DP Scree Methodology](method-dp-scree.html)** to the R arguments of each method-specific control function.
### Clipped mean {#clipped-control}
Clipped estimation limits each squared pair difference before releasing a noisy mean. See [Clipped Mean Methodology](method-dp-scree.html#clipped-mean).
::: {.clipped-parameter-table}
| Theory notation | R argument | Meaning |
|:--|:--|:--|
| $C_{\mathrm{clip}}$ | `C_clip` | Positive upper clipping threshold; controls the bias–noise tradeoff (required, no default). |
:::
The setting used in Section 2 is:
```{r scree-clipped-control}
clipped_set <- clipped_control(C_clip = 20)
clipped_set
```
A smaller `C_clip` reduces sensitivity and Gaussian noise, but can truncate more large paired differences.
A larger value reduces clipping bias while requiring more privacy noise.
### Private modified winsorized mean (PMWM) {#pmwm-control}
PMWM privately estimates lower and upper cutoffs and then computes a noisy winsorized mean. See [PMWM Methodology](method-dp-scree.html#pmwm).
::: {.pmwm-parameter-table}
| Theory notation | R argument | Meaning |
|:--|:--|:--|
| $a,b$ | `a`, `b` | Public lower and upper bounds for the **estimated cutoffs**, with $a
.huber-parameter-table table {width: 100%;table-layout: fixed;}
.huber-parameter-table colgroup col:nth-child(1) {width: 20% !important;}
.huber-parameter-table colgroup col:nth-child(2) {width: 20% !important;}
.huber-parameter-table colgroup col:nth-child(3) {width: 60% !important;}
::: {.huber-parameter-table}
| Theory notation | R argument | Meaning |
|:--|:--|:--|
| $r_{\min},r_{\max}$ | `k_min_m2`, `k_max_m2` | Integer limits for the dyadic scale candidates $2^r$, with $r_{\min}