-
Notifications
You must be signed in to change notification settings - Fork 0
Age vs Thickness GLM Simulation
- Create a scatterplot (Age on x-axis, Thickness on y-axis) and visually compare groups.
- Add linear trendlines and interpret the slope as an estimate of association with age.
- Test whether the slope differs from 0 (statistical evidence of an age effect).
- Test whether groups differ after accounting for age (adjusted group “offset”).
Create these headers in row 1:
- A: ID
- B: Group (Control/Patient)
- C: GroupCode (0/1)
- D: Age
- E: Thickness
- In A2, type
1 - In A3, type
2 - Highlight A2:A3, then drag down until A101 (you should end at ID = 100)
- In B2:B51, enter
Control(copy/paste or drag-fill) - In B52:B101, enter
Patient
- In C2, enter:
-
Google Sheets / Excel:
=IF(B2="Patient",1,0)
-
Google Sheets / Excel:
- Copy down to C101
- In D2, enter:
-
Google Sheets:
=RANDBETWEEN(20,80) -
Excel:
=RANDBETWEEN(20,80)
-
Google Sheets:
- Copy down to D101
This model is designed so students can detect:
-
Thickness declines with age (negative slope)
-
Patient group is lower after adjusting for age (group offset)
-
In E2, enter:
=2.90 + (-0.004)*(D2-20) + (-0.10)*C2 + 0.07*NORM.S.INV(RAND())
- Copy down to E101
Otherwise the data will change every time the sheet recalculates.
- Copy D2:E101
- Paste special → Values only
- Google Sheets: Edit → Paste special → Values only
- Excel: Home → Paste → Paste Values
The cleanest approach is to plot Control and Patient as separate series.
Create two new headers:
- F: ControlThickness
- G: PatientThickness
In F2:
=IF($B2="Control",$E2,NA())
In G2:
=IF($B2="Patient",$E2,NA())
Copy F2:G2 down to row 101.
- Select D1:D101 (Age)
- Hold Ctrl/Cmd and also select F1:G101 (the two thickness series)
- Insert → Scatter → Scatter with only markers
- Confirm you see two colors/series
- Select D1:D101, then (Ctrl/Cmd-select) F1:G101
- Insert → Chart
- Chart type → Scatter chart
- Confirm you see two series
Turn on:
- Trendline = Linear
- Display equation
- (Optional) Display R²
- Click Control series → Add Trendline → Linear → Display Equation, Display R²
- Repeat for Patient series
- Chart editor → Customize → Series
- Choose a series → enable Trendline → Label: Use equation
- Repeat for the other series
A linear trendline equation looks like:
Thickness = intercept + slope × Age
- If slope ≈ 0 → no age association
- If slope clearly nonzero → age association (positive or negative)
- The formal test asks whether slope is statistically different from 0
Pooled (all participants): Thickness ~ Age
- Pick two adjacent empty cells (e.g., I2:J2) and enter:
=LINEST(E2:E101, D2:D101, TRUE, TRUE)
- Extract the slope standard error:
=INDEX(LINEST(E2:E101, D2:D101, TRUE, TRUE), 2, 1)
- Compute t-statistic (slope / SE). Example structure:
- Put slope in I2 (from LINEST)
- Put SE(slope) in I3 (from INDEX)
- Then in I4:
=I2/I3
- Two-sided p-value (df = n − 2):
=T.DIST.2T(ABS(I4), COUNT(D2:D101)-2)
Deliverable for students: report slope, t, and p-value.
If the Analysis ToolPak is enabled:
- Data → Data Analysis → Regression
- Y Range: Thickness (E2:E101)
- X Range: Age (D2:D101)
- Read the slope coefficient and its p-value in the output
This is an adjusted comparison:
- Does Patient vs Control differ at the same age?
Model:
Thickness = b0 + b1·Age + b2·GroupCode + b3·(Age×GroupCode)
- Create an interaction column:
- H1: AgeXGroup
- H2:
=D2*C2
Copy down to H101.
- Run regression with predictors: Age (D), GroupCode (C), AgeXGroup (H)
Interpretation
- If b3 (Age×GroupCode) is significant → slopes differ by group (different age effect)
- If b3 is not significant → proceed with common-slope model
Model:
Thickness = b0 + b1·Age + b2·GroupCode
Run regression with predictors:
- Age
- GroupCode
Interpretation
-
b2 estimates the adjusted group difference (Patient − Control)
- If b2 is significant and negative → Patient is lower after accounting for age
- If b2 is not significant → no evidence of adjusted group difference