SBMS7402 — session materials
By the end of this session, you will be able to:
An Electronic Health Record (EHR) is the digital chart of a patient’s encounters with the health system—visits, diagnoses, labs, prescriptions, and clinical notes stored so clinicians (and later analysts) can reuse them.
Toy timeline (one patient):
Coding systems are a shared language so different hospitals and software can mean the same clinical idea.
Scaling clinical observations from single patient encounters to entire populations.
Clinical Medicine: Focuses on diagnosis, treatment, and immediate patient outcomes.
Population Health: Health outcomes, determinants, and patterns across defined groups (e.g., regional populations, disease cohorts).
Global Health & Digital Health Venture: Scalable health solutions, cross-border disease surveillance, and commercialization of data-driven digital health products.
Problem
Many biomedical startups fail due to building solutions for undersized or ill-defined patient markets.
How many potential customers could benefit from the product?
EHR can
Problem
EHR can
Problem Traditional Randomized Controlled Trials (RCTs) are
EHR can
Regulatory bodies (e.g., US FDA, EMA, NMPA) increasingly accept real-world evidence (RWE)—evidence generated from routine care data such as EHRs, not only from traditional trials—for
Missingness (missing for a reason)
Selection / Sampling Bias
Measurement / Coding Error
Healthcare question: Does systolic blood pressure tend to rise with age?
In plain English
We fit the line so we can describe, predict, and later test whether a relationship is compatible with chance.
With that intuition, the linear regression model is formally defined as \[ \begin{aligned} y_{i} = & \beta_{0} + \beta_{1}x_{1i} + \beta_{2}x_{2i} + \dots + \beta_{p}x_{pi} + \epsilon_{i} \text{, or}\\ \mathbb{y} = &\mathbb{\beta}\mathbb{X}+ \mathbb{\epsilon} \end{aligned} \]
Optional / advanced
The matrix form \(\mathbf{y}=\boldsymbol{\beta}\mathbf{X}+\boldsymbol{\epsilon}\) is a compact way to write the same model for many predictors. Focus first on the scalar equation and the meaning of \(\beta\) and \(\epsilon\).
Confidence Interval (CI) for the Mean Response: The average expected outcome for all individuals with a specific predictor value \(x\)
Prediction Interval (PI) for a New Observation: Predict the specific outcome \(y\) for a single, new individual with a specific predictor value \(x\).
The following relationship holds \[TSS = ESS + RSS\] TSS (Total Sum of Squares): \[\sum (y_i - \bar{y})^2\] ESS (Explained Sum of Squares): \[\sum (\hat{y}_i - \bar{y})^2\] RSS (Residual Sum of Squares):\[\sum (y_i - \hat{y}_i)^2\]
\[ R^2 = \frac{ESS}{TSS} = 1 - \frac{RSS}{TSS} \]
Even if we have \(R^2\), we need to know whether the explained variance is statistically significant.
Null Hypothesis \[ H_0: \beta_1 = \beta_2 = \dots = \beta_p = 0 \]
Test statistics
\[ F = \frac{ESS / df_{ESS}}{RSS / df_{RSS}} \sim F_{df_{ESS},df_{RSS}} \]
Investigate whether each predictor makes a statistically significant contribution to the outcome
Null Hypothesis \[ H_0: \beta_i = 0 \]
Test statistics
\[ \beta_i \sim t_{n-(p+1)}(0,\frac{s_{y\vert{}x}^{2}}{(n-1)s_{x_i}^{2}(1-r_{i}^{2})}) \]
Ask these in everyday language first (formal names in parentheses):
Failure modes matter clinically: e.g. if sicker patients get more labs, associations estimated from complete cases can be biased.
Plain check: Does \(y\) change at a roughly constant rate as \(x\) increases, or is there a bend / threshold?
The model assumes that the outcome changes linearly with each continuous predictor.
Checking:
Categorize the continuous predictor.
The predictor has the threshold effect
Transformations to the predictor (e.g., adding quadratic terms, log transformations)
The predictor has the non-linear effect on the outcome
Piecewise Regression
Specifying a threshold point in the regression model
Plain check: Do residuals look like a bell (symmetric pile around zero), or are they piled on one side / heavy-tailed?
Plain check: Is each leftover “its own story,” or are nearby / same-patient / same-clinic residuals similar?
Some obvious situations that violate this assumption
Checking the group difference
Plain check: Is the leftover scatter similar across the range of fitted values, or does it fan out like a funnel?
High leverage points are x-outliers with the potential to exert undue influence on regression coefficient estimates. Influential points are specific observations that have actually exerted an undue influence on the estimates. DFBETA statistics are recommended to quantify how much each coefficient would change if a specific observation were omitted from the dataset.
Below are examples of how to fit a multiple linear regression model and generate the necessary diagnostic plots in both Python and R.
OLS Regression Results
==============================================================================
Dep. Variable: Y R-squared: 0.810
Model: OLS Adj. R-squared: 0.808
Method: Least Squares F-statistic: 420.6
Date: Thu, 13 Aug 2026 Prob (F-statistic): 7.92e-72
Time: 16:13:04 Log-Likelihood: -821.84
No. Observations: 200 AIC: 1650.
Df Residuals: 197 BIC: 1660.
Df Model: 2
Covariance Type: nonrobust
==============================================================================
coef std err t P>|t| [0.025 0.975]
------------------------------------------------------------------------------
const 25.7620 7.528 3.422 0.001 10.917 40.607
X1 2.2881 0.114 20.148 0.000 2.064 2.512
X2 -1.2151 0.054 -22.687 0.000 -1.321 -1.110
==============================================================================
Omnibus: 1.716 Durbin-Watson: 1.916
Prob(Omnibus): 0.424 Jarque-Bera (JB): 1.565
Skew: 0.217 Prob(JB): 0.457
Kurtosis: 3.012 Cond. No. 822.
==============================================================================
Notes:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
# 1. Generate Synthetic Data
set.seed(42)
n <- 200
X1 <- rnorm(n, mean=50, sd=10)
X2 <- rnorm(n, mean=100, sd=20)
# Create outcome with normal noise
Y <- 15 + 2.5*X1 - 1.2*X2 + rnorm(n, mean=0, sd=15)
data <- data.frame(Y, X1, X2)
# 2. Fit the Linear Regression Model
model <- lm(Y ~ X1 + X2, data=data)
# Print model summary (Contains F-test, RSS, and coefficients)
print(summary(model))
# 3. Residual Diagnostics
# R has built-in diagnostic plots that are generated by plotting the model object
par(mfrow=c(2,2)) # Set up a 2x2 grid for plots
# Plot 1: Residuals vs Fitted (checks linearity and constant variance)
# Plot 2: Normal Q-Q (checks normality of residuals)
# Plot 3: Scale-Location (checks homoscedasticity)
# Plot 4: Residuals vs Leverage (checks for influential points / high leverage)
plot(model)