library(marginaleffects)
library(data.table)
library(ggplot2)
library(nnet)
library(MASS)
set.seed(1024)
simulation <- function(...) {
Y_train <- rnorm(25, mean = pi)
Y_test <- rnorm(25, mean = pi)
m <- lm(Y_train ~ 1)
p <- predictions(m, conf_level = .90)
out <- data.table(
`Test set coverage` = mean(Y_test >= p$conf.low & Y_test <= p$conf.high),
`True mean coverage` = pi >= p$conf.low[1] & pi <= p$conf.high[1]
)
return(out)
}
results <- rbindlist(lapply(1:1000, simulation))
colMeans(results)
Test set coverage True mean coverage
0.2498 0.8770