Skip to content

Instantly share code, notes, and snippets.

@ceshine
Last active January 7, 2016 05:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ceshine/02a344a83ea4660563f9 to your computer and use it in GitHub Desktop.
Save ceshine/02a344a83ea4660563f9 to your computer and use it in GitHub Desktop.
ANOVA of Observations v.s. ANOVO of Bootstrapped Statistics
n.samples = 100
series.A = rnorm(n.samples, 0, 2)
series.B = rnorm(n.samples, 0.1, 2)
bundle = data.frame(y=c(series.A, series.B), x=c(rep(0, n.samples), rep(1, n.samples)))
summary(aov(y ~ factor(x), data=bundle))
resampleTotal <- function(x){
sum(sample(x, length(x), replace=T))
}
n.resamples = 100
series.A.sum.resamples = rep(0, n.resamples)
series.B.sum.resamples = rep(0, n.resamples)
for(i in 1:n.resamples){
series.A.sum.resamples[i] = resampleTotal(series.A)
series.B.sum.resamples[i] = resampleTotal(series.B)
}
bundle.resample = data.frame(y=c(series.A.sum.resamples, series.B.sum.resamples), x=c(rep(0, n.resamples), rep(1, n.resamples)))
summary(aov(y ~ factor(x), data=bundle.resample))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment