Skip to content

Instantly share code, notes, and snippets.

@tomato42
Created June 28, 2020 18:32
Show Gist options
  • Save tomato42/c2ff6be65bbd1fbed83c31a5089cd06b to your computer and use it in GitHub Desktop.
Save tomato42/c2ff6be65bbd1fbed83c31a5089cd06b to your computer and use it in GitHub Desktop.
# number of subjects in each condition
n <- 10000
# number of replications of the study in order to check the Type I error rate
nsamp <- 10000
ps <- replicate(nsamp, {
#population mean = 0, sd = 1 for both samples, therefore, no real effect
y1 <- rnorm(n, 0, 1)
y2 <- rnorm(n, 0, 1)
tt <- ks.test(y1, y2)
tt$p.value
})
sum(ps < .05) / nsamp
# that gave me the expected 0.0466 and 0.0491 on rerun
# number of subjects in each condition
n <- 10000
# number of replications of the study in order to check the Type I error rate
nsamp <- 10000
ps <- replicate(nsamp, {
#population mean = 0, sd = 1 for both samples, therefore, no real effect
y1 <- rnorm(n, 0, 1)
tt <- ks.test(y1, 'pnorm')
tt$p.value
})
sum(ps < .05) / nsamp
# that gave me 0.0484, 0.0504 and 0.0484
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment