Skip to content

Instantly share code, notes, and snippets.

@olooney
Created December 20, 2017 15:46
Show Gist options
  • Save olooney/f4f60888d67956e1db5156a29157d76d to your computer and use it in GitHub Desktop.
Save olooney/f4f60888d67956e1db5156a29157d76d to your computer and use it in GitHub Desktop.
illustrate CLS convergence for non-skewed and highly skewed random variables.
compare_histograms <- function(sn) {
sample_means <- function(r,n) { sqrt(n)*rowMeans(matrix(r(n*10000), ncol=n)) }
center_scale <- function(v) (v - mean(v))/sd(v)
exp_sample <- center_scale(sample_means(rexp, sn))
unif_sample <- center_scale(sample_means(runif, sn))
max_break = ceiling(max(c(unif_sample, exp_sample)))
min_break = floor(min(c(unif_sample, exp_sample)))
breaks = seq(min_break,max_break,length.out=(max_break-min_break)*8+1)
hist(unif_sample, breaks=breaks, col=adjustcolor('green', alpha.f=0.5), xlim=c(min_break,max_break))
hist(exp_sample, breaks=breaks, col=adjustcolor('yellow', alpha.f=0.5), xlim=c(min_break,max_break), add=T)
}
compare_histograms(30)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment