I have to use Johnson distribution to see how different means are when modifying the skewness value (.3 in the code below):
library(moments)
library(SuppDists)
k <- 500
parms <-JohnsonFit(c(0, 1, .3, 6))
sJohnson(parms)
poblacion <- rJohnson(1000, parms)
mu.pob <- mean(poblacion)
sd.pob <- sd(poblacion)
p <- vector(length=k)
for (i in p){
muestra <- poblacion[rJohnson(1000, parms)]
p[i] <- t.test(muestra, mu = mu.pob)$p.value
}
a_teo = 0.05
a_emp = length(p[p<a_teo])/k
sprintf("alpha_teo = %.3f <-> alpha_emp = %.3f", a_teo, a_emp)
If I change the .3 for 1, I got different values for mean and standard deviation, but I got exactly the same empirical value for alpha: 1.000. What is wrong with my code?
There are a few errors in your code.
for(i in p)it should befor(i in seq.int(k));poblacion[rJohnson(1000, parms)], is wrong. The indexrJohnsonis not integer and it will not indexppoblacion. The correct ways should be any of the ways in theforloop below.a_empis too complicated, see the equivalentmean(p < a_teo).And here is the complete code corrected.
Created on 2024-03-10 with reprex v2.1.0
Edit
Instead of the
forloop above, you can usereplicate. Fromhelp("replicate"), my emphasis:Note that with
replicateyou do not need to createpwith the required length beforehand, it will bereplicate's return value.