Investigation: Reconsidering the p-value#

A null hypothesis is a model restriction, not a probability. A p-value is a tail probability for a specified statistic under that null and its assumptions. It is not the posterior probability of the null, the probability of chance, or an effect size.

Question. Simulate null p-values, compare uncertainty at two sample sizes, and show the false-positive consequences of searching many outcomes.

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)
B <- 1000
null_p <- replicate(B,t.test(rnorm(30))$p.value)
hist(null_p,breaks=seq(0,1,.05),main="p-values under a specified null",xlab="p-value")
c(false_positive_rate=mean(null_p<.05),mcse=sqrt(.05*.95/B))
# Search 20 independent null outcomes, then report only the smallest p-value.
searched <- replicate(500,min(replicate(20,t.test(rnorm(30))$p.value)))
c(any_nominal_positive=mean(searched<.05),bonferroni_positive=mean(searched<.05/20))
false_positive_rate
0.047
mcse
0.00689202437604511
any_nominal_positive
0.62
bonferroni_positive
0.04
../_images/f60dc39183513bade015e29e3cca45a0103ede57fc99ffeef3c8340f6bb17ee2.png

A magnitude and an interval answer different questions#

The null is mu=0 under this sampling model. The p-value is a tail probability for the test statistic under the null; it is not P(mu=0 | data). A larger sample can make a small effect distinguishable from zero without making it practically important.

summarize_study <- function(n) {
  z <- rnorm(n,.15)
  test <- t.test(z)
  data.frame(n=n,estimate=mean(z),lower=test$conf.int[1],upper=test$conf.int[2],p=test$p.value)
}
rbind(summarize_study(30),summarize_study(500))
A data.frame: 2 × 5
nestimatelowerupperp
<dbl><dbl><dbl><dbl><dbl>
300.2517154-0.135966200.63939690.1945576428
5000.1610765 0.070076320.25207660.0005499326

Interpret and verify#

Report an estimate and interval, describe the testing family and selection procedure, and distinguish exploratory findings from confirmatory evidence.

Failure to consider: Selecting the smallest p-value and reporting it as if only one test was planned hides the search. A nonsignificant result does not establish a negligible effect.

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.

Revisit significance language used in earlier models; compare it with explicit Bayesian evidence next.

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