Created
December 3, 2016 15:56
-
-
Save diamonaj/88b2b3b1828e1afdc3499f5c8cfabc22 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| set.seed(123) | |
| # create storage vectors | |
| # to store the means for each experiment | |
| storage.corr <- c() | |
| storage.uncorr <- c() | |
| # "PULL THE *CORR* LEVER" | |
| # correlated data | |
| corr.lever <- function() | |
| { | |
| return(c( | |
| rep(rbinom(n = 1, size = 1, prob = 0.5), 10), | |
| rep(rbinom(n = 1, size = 1, prob = 0.5), 10), | |
| rep(rbinom(n = 1, size = 1, prob = 0.5), 10), | |
| rep(rbinom(n = 1, size = 1, prob = 0.5), 10), | |
| rep(rbinom(n = 1, size = 1, prob = 0.5), 10))) | |
| } | |
| # "PULL THE *UNCORR* LEVER" | |
| # uncorrelated data | |
| uncorr.lever <- function() | |
| { | |
| return(rbinom(n = 50, size = 1, prob = 0.5)) | |
| } | |
| # run 1000 experiments (simulated trials) | |
| for(i in 1:1000) | |
| { | |
| storage.corr[i] <- mean(corr.lever()) | |
| } | |
| for(i in 1:1000) | |
| { | |
| storage.uncorr[i] <- mean(uncorr.lever()) | |
| } | |
| # Was the standard deviation of the means derived from uncorrelated data | |
| # LOWER than the standard deviation of the means derived from correlated data? | |
| # Across all the simulated trials (for the whole shebang)? | |
| sd(storage.uncorr) < sd(storage.corr) | |
| cat("uncorrelated data standard deviation:", sd(storage.uncorr) | |
| cat("correlated data standard deviation:", sd(storage.corr)) | |
| ###### | |
| ###### You saw it happen once, but was it a fluke? | |
| ###### We should repeat the whole shebang (repeat the repititions) and find out... | |
| ###### | |
| # create a storage vector for the results of each shebang | |
| # keeping track of whether/not the uncorrelated data set wins (has lower sd) | |
| # each time... | |
| uncorr.wins <- c() | |
| # now we run the whole shebang each time... | |
| for(k in 1:100) | |
| { | |
| if(k %% 10 == 0) {cat(k, "% -- ", sep = "")} | |
| storage.corr <- c() | |
| storage.uncorr <- c() | |
| # run 1000 experiments (simulated trials) | |
| # we will draw data from a standard normal distribution | |
| # to keep things as simple as possible | |
| for(i in 1:1000) | |
| { | |
| storage.corr[i] <- mean(corr.lever()) | |
| } | |
| for(i in 1:1000) | |
| { | |
| storage.uncorr[i] <- mean(uncorr.lever()) | |
| } | |
| uncorr.wins[k] <- sd(storage.uncorr) < sd(storage.corr) | |
| } | |
| # to see if uncorr data produces lower error (i.e., if uncorr wins)... | |
| print(uncorr.wins) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment