18
中中中中中中 中中中中中中中中中1

K060 中心極限定理clt

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: K060 中心極限定理clt

中心極限定理

すべては正規分布へ!

1

Page 2: K060 中心極限定理clt

2中心極限定理

Page 3: K060 中心極限定理clt

3

これを確かめる

Page 4: K060 中心極限定理clt

4一様分布の場合 n=1

-0.5 0.0 0.5 1.0 1.5

0.0

0.2

0.4

0.6

0.8

1.0

x

du

nif

(x)

Page 5: K060 中心極限定理clt

5一様分布の場合 n=2

-3 -2 -1 0 1 2 3

0.0

0.1

0.2

0.3

0.4

x

sap

ply

(x, u

2s)

独立な 2 個の一様分布の和の分布

Page 6: K060 中心極限定理clt

6一様分布の場合 n=3

独立な 3 個の一様分布の和の分布

-3 -2 -1 0 1 2 3

0.0

0.1

0.2

0.3

0.4

x

sap

ply

(x, u

3s)

Page 7: K060 中心極限定理clt

7

u2 <- function(z) switch(length(which(c((z >= 0), (z >= 1), (z > 2)))) + 1, 0, z, 2 - z, 0) u2s <- function(z) u2(z / sqrt(6) + 1) / sqrt(6)

x <- seq(-3, 3, length = 101) plot(x, sapply(x, u2s), type = "l") curve(dnorm, -3, 3, add = T, col = 2)

u3 <- function(z)

switch(length(which(c((z >= 0), (z >= 1), (z > 2), (z > 3)))) + 1,

0, z^2 / 2, -z^2 + 3 * z - 3 / 2, (z - 3)^2 / 2, 0)

u3s <- function(z)

u3(1.5 + (z * 0.5))* 0.5

x <- seq(-3, 3, length = 101)

plot(x, sapply(x, u3s), type = "l", ylim = c(0, 0.4))

curve(dnorm, -3, 3, add = T, col = 2)

Page 8: K060 中心極限定理clt

8種々の分布

• シミュレーションで使うための新しい分布を定義する二次分布三角分布平方根分布

一様分布2項分布など

Page 9: K060 中心極限定理clt

9密度関数と分布関数

Page 10: K060 中心極限定理clt

10中心極限定理のシミュレーション

• 平均,分散があればどんな分布でも成立する 離散型でも成立

• 左右対称な分布と非対称な分布での振る舞いを比較する 標準正規分布へどのぐらいで収束するか

• 母集団分布に,種々の分布を仮定1. 標本を n個取り出す2. その平均を求める3. それをシミュレーション回数 nsim 回繰り返して, nsim 個の平均を

求める

Page 11: K060 中心極限定理clt

11中心極限定理のシミュレーション(一様分布の場合)

n <- 10

nsim <-1000

rslt <- apply(sapply(rep(n, nsim), runif), 2, mean)

rslt

rslt <- c()

n <- 10

nsim <-1000

for(i in 1:nsim){

rslt[i] <- mean(runif(n))

}

rslt

stdata <- scale(rslt)

hist(stdata, nclass = 20, xlim = c(-4, 4), freq = F)

curve(dnorm, -4, 4, add = T, col = 2)

nsim 個の平均の値の平均と標準偏差を求め,基

準化する標準正規分布の密度関数を重ね書きして,正規分布への収束の度合いを眺める

Page 12: K060 中心極限定理clt

12中心極限定理のシミュレーション(一様分布の場合)

cltplot <- function(data, n){

hist(scale(data), nclass = 20, xlim = c(-4, 4),

ylim = c(0, 0.5), freq = F, main = paste("N =" , n))

curve(dnorm, -4, 4, col = 2, add = T)

}

clturand <- function(n, nsim){

if(n == 1)

result <- apply(matrix(sapply(rep(n, nsim), runif), n, nsim), 2, mean)

else

result <- apply(sapply(rep(n, nsim), runif), 2, mean)

cltplot(result, n)

}

Page 13: K060 中心極限定理clt

13

> clturand(5,1000)N = 5

scale(data)

De

nsi

ty

-4 -2 0 2 4

0.0

0.1

0.2

0.3

0.4

0.5

Page 14: K060 中心極限定理clt

14nを変化させる

nsim<-1000

cltunif <- function(nmax){

for(i in 1:nmax){

if (options()$device == "X11")

X11()

if (options()$device == "windows")

win.graph()

clturand(i, nsim)

}

}

> cltunif(5)

nsim を 100 や 500 に変えてみて収束の具合を見る

どのぐらいで収束しているか見よう。

出てきたグラフをすべて削除するには, graphics.off()

Page 15: K060 中心極限定理clt

15一様分布だけではなく,分布を指定する

source(“dist.r”)

cltrand <- function(n, nsim, rdist){

if(n == 1)

result <- apply(matrix(sapply(rep(n, nsim), rdist), n, nsim), 2, mean)

else

result <- apply(sapply(rep(n, nsim), rdist), 2, mean)

cltplot(result, n)

}

clt <- function(nmax, rdist){

for(i in 1:nmax){

if (options()$device == "X11")

X11()

if (options()$device == "windows")

win.graph()

cltrand(i, nsim, rdist)

}

}

Page 16: K060 中心極限定理clt

16使い方

• 教科書 95 ページ参照• 二次分布の場合 clt(5, rquad)

N = 5

scale(data)

De

nsi

ty

-4 -2 0 2 4

0.0

0.1

0.2

0.3

0.4

0.5

N = 1

scale(data)

De

nsi

ty

-4 -2 0 2 4

0.0

0.1

0.2

0.3

0.4

0.5

Page 17: K060 中心極限定理clt

17clt 関数で指定できる分布の例

Page 18: K060 中心極限定理clt

18パラメータが必要な分布では