Investigation: Models as testable hypotheses#

A testable model specifies observables, parameters, and conditions under which predictions could fail. A generative statistical model specifies a distribution for data; a mechanistic model makes additional claims about the process. Neither is synonymous with a generative AI system.

Question. Simulate reaction times under a known word-frequency effect, fit the stated model, and check parameter recovery over repeated samples.

Before running: write the result you expect and what would challenge it. Data are simulated unless explicitly identified otherwise.

# Open this notebook from book/notebooks (or book/exercises).
course_path <- if (file.exists("../R/course.R")) "../R/course.R" else "book/R/course.R"
stopifnot(file.exists(course_path))
source(course_path)
set.seed(432)

Specify the generating equation#

Here RT = 650 + beta × frequency + independent Gaussian noise, with noise SD 40 ms. This is a deliberately simplified study without repeated measures.

simulate_effect <- function(n=100, beta=-25) {
  frequency <- runif(n,1,7)
  data.frame(frequency=frequency, rt=650+beta*frequency+rnorm(n,0,40))
}
d <- simulate_effect()
fit <- lm(rt ~ frequency,d)
coef(fit)
confint(fit)
(Intercept)
643.217676857763
frequency
-24.2052133899211
A matrix: 2 × 2 of type dbl
2.5 %97.5 %
(Intercept)623.15720663.27815
frequency-28.68265-19.72777

Verify a simulator, not just a single fitted result#

A recovery check needs repeated samples. Use a tolerance informed by Monte Carlo error instead of demanding that one sample equal the generating coefficient.

recover <- function(beta,B=200) replicate(B,coef(lm(rt ~ frequency,simulate_effect(beta=beta)))[2])
effect <- recover(-25)
null <- recover(0)
recovery <- data.frame(truth=c(-25,0), estimate=c(mean(effect),mean(null)), mcse=c(sd(effect),sd(null))/sqrt(200))
recovery
stopifnot(all(abs(recovery$estimate-recovery$truth) < 5*recovery$mcse))
boxplot(list(effect=effect,null=null),ylab="Estimated slope (ms per frequency unit)")
A data.frame: 2 × 3
truthestimatemcse
<dbl><dbl><dbl>
-25-24.985658060.1588388
0 -0.082238120.1684812
../_images/1a8d6416526c43952b6a4a608d94bb3e8ecf00126deb653d33c8a354fa01a0dd.png

Interpret and verify#

Audit a proposed simulator against its equation and verify recovery under both a nonzero effect and a null effect.

Failure to consider: A simulator can implement the wrong sign, unit, or source of dependence and still produce a convincing plot.

Report the target, the numerical result with its units, the relevant uncertainty, and one limitation. Distinguish what is established by the simulation from what would require real data.

AI audit: critique the saved faulty claim in the companion exercise before using any live assistant. If you use AI, record the relevant suggestion, your independent check, and the final decision.

Translate the preceding theory into measurements and explicit predictions before organizing the data.

sessionInfo()
R version 4.2.1 (2022-06-23)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS 15.7.7

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib

locale:
[1] C.UTF-8/C.UTF-8/C.UTF-8/C/C.UTF-8/C.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] fansi_1.0.3         crayon_1.5.1        digest_0.6.29      
 [4] utf8_1.2.2          IRdisplay_1.1       repr_1.1.4         
 [7] lifecycle_1.0.1     jsonlite_1.8.0      evaluate_0.15      
[10] pillar_1.8.0        rlang_1.0.6         cli_3.3.0          
[13] uuid_1.1-0          vctrs_0.4.1         IRkernel_1.3.0.9000
[16] tools_4.2.1         glue_1.6.2          fastmap_1.1.0      
[19] compiler_4.2.1      base64enc_0.1-3     pbdZMQ_0.3-7       
[22] htmltools_0.5.3    

Attribution#

Notebook authored by Amy Sentis and Fiona Horner.

Revised investigation: 2026 course revision. Original authorship is retained; examples and explanatory text have been updated.