Last active
July 31, 2023 15:12
-
-
Save jeanbaptisteb/5e61d41705acefdc0d64083266f3de61 to your computer and use it in GitHub Desktop.
Type M error for effect size (cohen's W) in contingency tables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#proof of concept for calculating a type M error (exaggeration ratio) for effect size in contingency tables | |
# type M error is defined as "The expectation of the absolute value of the estimate divided by the effect size, | |
# if statistically significantly different from zero." | |
# http://www.stat.columbia.edu/~gelman/research/published/retropower_final.pdf | |
type.m.error = function(samp.size, dof, real.w, alpha=0.05, power=0.8, n.sim=10000, seed=0) { | |
set.seed(seed) | |
chis = rchisq(n=n.sim, df=dof, ncp =samp.size*real.w^2 ) | |
crit.value = qchisq(p=alpha, df=dof, lower.tail=T) | |
chis = chis[chis >= crit.value] | |
all.omegas = sqrt(chis/samp.size) | |
exaggeration.ratio = mean(all.omegas) / real.w | |
res = c( real.w, mean(all.omegas), exaggeration.ratio, real.w-mean(all.omegas)) | |
names(res) = c("real effect size", "mean observed effect size", "Type M error (exaggeration ratio)", "absolute difference") | |
return( res) | |
} | |
#type.m.error(samp.size=n, dof=dof, real.w=es, n.sim = 1000000, seed=NULL) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment