# A shared analysis workflow

## Specify before computing

Start with a scientific question, target population, and observational unit. State whether the goal is description, estimation, prediction, or causal explanation. Define the estimand (the quantity being estimated), outcome units, and evidence needed to justify the claim.

Write a short plan before examining results. Exploration is welcome: retain discoveries and deviations rather than presenting data-dependent choices as prespecified.

## Prepare accountable data

Preserve raw values. Describe keys, meanings, units, provenance, inclusion rules, and missing-value encodings. Check key uniqueness and join cardinality. Log exclusion counts and reasons. Compare reasonable cleaning choices when they could change the conclusion. Complete-case analysis and imputation each require assumptions; neither is a universal default.

The simulated lexical-decision dataset is a reusable core investigation. Two worked companions connect it to real observations: [lexical records](../notebooks/lexical-data-investigation.ipynb) and [HCP brain volumes](../notebooks/hcp-data-investigation.ipynb). Optional extensions use existing English Lexicon Project and HCP files. Verify documentation and access conditions first. For HCP, determine whether family/site metadata are available before claiming independence or selecting validation splits; unavailable metadata are a limitation to report.

## Separate development from evaluation

For prediction, set aside final assessment data before learning preprocessing or selecting a model. Match the split unit to the intended population: new rows, participants, words, families, sites, or future periods are different targets. A subject holdout with shared items does not evaluate new items.

Within training data, resample the **whole procedure**: learned missing-value handling, scaling, feature selection, dimension reduction, fitting, threshold selection, and tuning. Use the same folds for candidate comparisons. Refit the chosen procedure on all training data and evaluate once on final assessment data. For nested cross-validation, repeat selection inside every outer analysis fold. Never change seeds until a preferred result appears.

This also applies to AI prompts, retrieval settings, and embedding-model selection. The [tidymodels guide](https://www.tidymodels.org/start/resampling/) shows an R workflow; [scikit-learn's leakage guide](https://scikit-learn.org/stable/common_pitfalls.html) provides an optional Python counterpart.

## Challenge the result

Use a simple baseline. Check dimensions, keys, units, residuals, convergence, and the intended null or generating mechanism. Match uncertainty estimates to independent sampling units. Distinguish coverage, power, false-positive rate, predictive loss, and Monte Carlo precision. Test a plausible failure case and explain what checks cannot rule out.

Prediction does not identify a causal effect. Describe the intervention, assumptions, graph, and design supporting causal identification. Simulated recovery validates code under a known mechanism; it is not evidence that the mechanism holds in a real population.

## Report a defensible claim

Include the question, provenance, target, assumptions, transformations, validation design, baseline, result with units and appropriate uncertainty, sensitivity analysis, and limitations. Add a claim-to-evidence ledger and document consequential AI use. A collaborator should reproduce a figure from a fresh environment and locate the code behind a reported number.

(exercise-submissions)=
## Exercise submissions

Each exercise supplies a specific problem, starter data, staged tasks, and a **What to submit** checklist. Complete the analysis cells and replace the explanation placeholders with your reasoning. The starter cells are runnable but do not solve the assignment. Use the companion investigation for methods, then answer the exercise's own question.

Run notebooks from `book/exercises`, restart the R kernel, and run all cells before submission. Retain figures, tables, diagnostic warnings that affect interpretation, and a final `sessionInfo()` record. Catch deliberately demonstrated errors so the remaining analysis still runs. Follow your instructor's submission destination and schedule.

Keep the supplied seed for the core assignment. When a task asks for repeated experiments, set a seed once before the simulation loop rather than resetting it inside every repetition. Label exploratory changes and retain unexpected results. Separate synthetic teaching results from claims about real participants. Some exercises are design or communication tasks: do not add a model or significance test just to make them look computational.

A live AI assistant is optional. If used, briefly record consequential suggestions, your independent verification, and accepted or rejected changes; otherwise state that none was used. Do not upload restricted participant records. Only exercises whose learning objective calls for an AI audit require one. Follow the [AI-assisted analysis guide](ai-assisted-analysis.md) for details.

## Assessment rubric

| Component | Weight | Evidence |
|---|---:|---|
| Question and design | 25% | Clear target, unit, justified assumptions and plan |
| Implementation | 25% | Runnable code implementing the plan |
| Verification and sensitivity | 30% | Independent checks, failure cases, honest validation and uncertainty |
| Interpretation and reproducibility | 20% | Qualified conclusions, provenance, environment, claim ledger and AI-use record |

Unexpected or nonsignificant results receive full credit when correctly analyzed and explained. A short unaided explanation or live modification can establish ownership. Working code without analytical justification is incomplete.
