Exercise: Can you recover the effect you built?#
Before using a fitted slope to test a scientific hypothesis, establish what it estimates under a known generating process and what changes when the fitted model omits curvature.
See the shared submission guidance and rubric. Run from book/exercises; the setup below supplies data, not completed answers.
# Shared simulator and small utility functions; no live service is called.
source("../R/course.R")
set.seed(104)
x <- rep(seq(-2, 2, length.out=20), 5)
make_response <- function(x, beta=-25, curvature=0, sigma=30) {
600 + beta*x + curvature*x^2 + rnorm(length(x), 0, sigma)
}
y <- make_response(x)
1. Translate a hypothesis into parameters#
Fit y ~ x. Identify the scientific meaning and units of the intercept and slope, assuming x is a centered stimulus score and y is milliseconds. Write the null and a specific alternative prediction before reading the coefficient table. Compare the fitted slope with the known -25.
# Fit the model and obtain a slope estimate and interval.
Your explanation and evidence:
2. Check recovery over experiments#
Generate 300 datasets with beta=-25 and curvature=0. Report slope bias, empirical SD, and the fraction of 95% intervals covering -25. Add Monte Carlo SE for that fraction. Explain why a single close estimate is insufficient validation.
# Collect one row of coefficient and interval results per experiment.
Your explanation and evidence:
3. Break a modeling assumption#
Generate curvature=30 data with beta=-25. Compare linear and quadratic residual plots and fitted curves. Repeat after restricting x to nonnegative values. Explain why the slope from the misspecified linear model depends on the stimulus range; distinguish it from the generating linear coefficient.
# Fit both specifications over the full and restricted ranges.
Your explanation and evidence:
What to submit#
A parameter-meaning table, a recovery summary, and full-range/restricted-range diagnostic plots. Explain which hypothesis each fitted coefficient actually tests.