# CAPRE student worksheet

Work in this student worksheet from the `r-workshop/` directory (seed 20261128). Use the synthetic cohort for exercises 1 to 4. Open the oracle key in exercise 5. The cutoff is 0.45 and the effort budget is 3.0.

```{r setup}
source("capre-exercise.R")
```

## 1. Who enters the comparison?

Load the cohort. Recover the split and the flag using the recorded variables. Which two predictors leave the model when you require an observed path to injury? Inspect the mixing weights on the training folds.

```{r exercise1}
cohort <- read.csv(file.path(data_dir, "icu-ward-cohort.csv"))
fit <- fit_workshop(cohort)
# YOUR TURN
# List the eligible IDs and both omitted feature names. Explain how counting tests can reveal illness severity.
```

## 2. Which edits buy a classifier flip?

Search with all four modes before revealing any oracle values. For `flat_priced` (cost-only search), inspect the actual action names. Raise the directional proxy price from 0.08 to 0.80 and count the selected plans that still use a proxy.

```{r exercise2}
pred <- predict_cases(fit)
high <- predict_cases(fit, proxy_cost = 0.80)
# YOUR TURN
# Tabulate status by mode. Count a two-action plan once if either action changes a surveillance count.
```

## 3. What does the turning team cost?

For ICU-0486, price the two parts of the prescribed bundle separately and together. Use the training SDs and recover the joint price from the squared effort coordinates. Repeat with log-price SD 0.35.

```{r exercise3}
row <- fit$cases[1, ]
bundle <- fixed_actions(row)$turn_bundle
ref <- workshop_prices()
rated <- workshop_prices(price_noise_sd = 0.35)
# YOUR TURN
# Use the pricing and warp functions. Identify the term that appears twice in separate visits.
```

## 4. Does the class have support for this prediction?

Compare the first factual profile, the propagated turn bundle, and a stress test that adds four training SDs to tissue tolerance. Compute ensemble risk, dispersion, and Kish ESS over the same six columns. Compare the decision at penalties 0, 0.5, and 1.

```{r exercise4}
state <- capre_intervene(fit$scm, row, bundle)
q <- rbind(row[ancestors], as.data.frame(state[ancestors]))
q <- rbind(q, q[2, ])
q$tissue_tolerance[3] <- q$tissue_tolerance[3] + 4 * fit$scales["tissue_tolerance"]
rownames(q) <- c("factual", "propagated", "stress")
# YOUR TURN
# Use capre_predict_superlearner(fit$sl_anc, q) and capre_overlap_ess(fit$train[ancestors], q).
# Report the profile with the smallest ESS and why learners might still agree there.
```

## 5. Which flips survive the oracle audit?

Open the separate key now. Compare each optimized plan with its own replay and both prescribed plans with their matched risks. Repeat with severity coupling set to zero at the same seed. Report how the set of flagged IDs changes.

```{r exercise5}
key <- read.csv(file.path(data_dir, "oracle-answer-key.csv"))
graded <- audit_workshop(fit, pred, key)
# YOUR TURN
# Explain why ICU-0517 misses budget-valid recourse. Separate a probability drop from crossing the threshold.
```
