正規分布|Normal Distlibution
概要
質量関数(mass function)について説明する。
正規分布
正規分布からサンプルを取り出し,サンプル分布を作る。
n <- 10 # sample size in the experiment
N <- 5000 # total number of repetitions
# of the experiment
vec.for.means <- rep(NA,N)
vec.for.variances <- rep(NA,N)
vec.for.medians <- rep(NA,N)
試行のサンプルサイズはnとし,試行の繰り返し総数をNとする。rep(NA,N)は,NAをN回繰り返している。
vec.for.*を確認すると,NAが5万個並んでいる。
for (i in 1:N){
data <- rnorm(n,mean=0,sd=1) #data from a single experiment
# with sample size n
vec.for.means[i] <- mean(data) #sample mean (Xbar)
vec.for.variances[i] <- var(data) #sample variance
#NB dividing by 1/(n-1)
vec.for.medians[i] <- median(data) #sample median
}
平均0,標準偏差1の正規分布(つまり標準正規分布)からサンプルサイズnのデータを取り出し,dataに入れる。
その平均値mean(data)をvec.for.means[i]に投入。
分散と中央値も同様に投入。
これらの操作をfor (i in i:N)で5000回繰り返す。
# mean of the means mean(vec.for.means) # Mean of sample mean (approx 0) var(vec.for.means) #Variance of sample means (approx 1/n) 1/n # theoretical value sd(vec.for.means) #Variance of sample means (approx 1/sqrt(n)) 1/sqrt(n) # theoretical value # Mean of the sample variances mean(vec.for.variances) # Mean of the sample medians mean(vec.for.medians)