Last active
August 29, 2015 14:26
-
-
Save m-note/b4e7bce1349a03cd5430 to your computer and use it in GitHub Desktop.
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
library(WDI) | |
x <- WDI(country="all", indicator=c("AG.AGR.TRAC.NO"), | |
start=1980, end=2011) | |
y <- na.exclude(x[,3]) | |
mean(y) | |
# 881532.3 | |
sd(y) | |
# 2925623 | |
var(y) | |
# 8.559267e+12 | |
var(y)/10000 | |
# 855926716 | |
# Central Limit Theorem | |
sample_mean <- NULL | |
for (i in 1:10000){ | |
sample <- sample(y, 2200, replace = FALSE, prob = NULL) | |
sample_mean[i] <- mean(sample) | |
} | |
hist(sample_mean) | |
plot(density(sample_mean)) | |
mean(sample_mean) | |
sd(sample_mean) | |
sd(y)/sqrt(10000) | |
# Law of Large Number | |
#データ数が多いと、サンプル平均は真の平均に近づく | |
mean(sample(y, 10, replace = FALSE, prob = NULL)) | |
mean(sample(y, 100, replace = FALSE, prob = NULL)) | |
mean(sample(y, 1000, replace = FALSE, prob = NULL)) | |
mean(sample(y, 2000, replace = FALSE, prob = NULL)) | |
mean(sample(y, 3000, replace = FALSE, prob = NULL)) | |
dif_mean <- NULL | |
for (i in seq(20,3860,20)){ | |
dif_mean[i] <- mean(y) - mean(sample(y, i, replace = FALSE, prob = NULL)) | |
} | |
plot(dif_mean) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment