Exercises · Day 6, Part 2 (Optional): Patient-Level Prediction
Sample notebook
Run the companion notebook in Colab (synthetic data, no credentials needed):
or download it.
What you will do
- State a prediction problem as a target cohort, an outcome cohort, and a time-at-risk.
- Run the PatientLevelPrediction workflow against your training CDM, or follow the same steps in the Colab notebook.
- Read the AUC and the calibration output.
- Change one design choice and compare the results.
Setup is site specific
This lab reuses the R environment, the connection details, and the dedicated cohort table from Day 6, Part 1. If your CDM connection is not working yet, do Path B with the Colab notebook.
Step 1: State the prediction problem
Write one sentence in this form before you run anything:
Among [target cohort], who will have [outcome] within [time-at-risk] of cohort entry?
For the guided lab, the target cohort is the new-user riluzole cohort (cohort ID 1) and the outcome is the cohort you added as homework in Part 1 (cohort ID 2), with a time-at-risk of 1 to 365 days after cohort entry.
Step 2, Path A: Run the workflow in R
Use the code block on the Part 2 module page. Work through it in order:
createDatabaseDetails()names the CDM schema, the cohort table, the target cohort ID, and the outcome cohort ID.createCovariateSettings()chooses the covariates.getPlpData()extracts the data.createStudyPopulationSettings()sets the time-at-risk and the handling of people who had the outcome before entry.runPlp()splits the data, trains a lasso logistic regression, and evaluates it on the test set.plotPlp()writes the evaluation plots.
After each step, note what the step returned and how long it took.
Step 2, Path B: Follow the Colab notebook
The notebook uses a synthetic CDM and Python to show the same sequence: a target cohort, an outcome, covariates, a train and test split, a model, AUC, and calibration. It teaches the sequence of steps in a prediction study and does not run the PatientLevelPrediction package itself.
Step 3: Read the results
Answer these from your output:
- What is the AUC on the test set? What does that value say about how well the model ranks people?
- In the calibration output, where do predicted and observed risk agree, and where do they differ?
- Which covariates have the largest coefficients? Why would it be a mistake to read them as causes of the outcome?
- How many people in the target cohort had the outcome during the time-at-risk? Is that enough to trust the evaluation?
Step 4: Change one design choice
Change one thing, rerun, and compare:
- Time-at-risk: change
riskWindowEndfrom 365 to 180. - Covariates: add or remove one group of covariates.
- Prior outcomes: switch
removeSubjectsWithPriorOutcome.
Write one sentence on what changed in the population size, the AUC, and the calibration, and why.
Homework
- Identify one question from your research area that calls for patient-level prediction and one that calls for population-level estimation, and explain the difference.
- Write a short plan for external validation: which other database could the model be tested on, and what would you expect to differ?