7.2 Checking the procedure with fake-data simulation

  • Step 1: Creating Pretend world.

    Assume \(y = 61.9 - 1.1 x + \text{error}\) is true, \(\text{error} \sim N(0,2.5)\)

a <- 61.9
b <- -1.1
sigma <- 2.5
## Use predictors from data set
x <- exercise$strengthTraining
n <- length(x)
  • Step 2: Simulating fake data
y <- a + b*x + rnorm(n,0,sigma)
fake <- tibble(x,y)
  • Step 3: Fit the fake data
fit <- stan_glm(y ~ x, data = fake, refresh = 0)
print(fit, detail=FALSE)
##             Median MAD_SD
## (Intercept) 58.8    4.2  
## x           -1.0    0.1  
## 
## Auxiliary parameter(s):
##       Median MAD_SD
## sigma 2.7    0.3

We can see in this particular simulation, the fit is consistent with the assumed model. But to understand this better we embed this in a loop…