### 正規分布の棄却域の図示

MINAKA Nobuhiro — Nov 4, 2013, 2:27 PM

``````## 正規分布のもとでの棄却域の図示

# —————————————————————————————————
# 棄却水準（α＝0.05）の場合
# —————————————————————————————————

# 正規分布（平均0, 標準偏差0.8）の図示
curve(dnorm(x, mean=0, sd=0.8), -3, 3, xlab="x: normal distribution N(0, 0.8^2)", ylab="density")

# 棄却水準（α＝0.05）を設定と表示
alpha <- 0.05
title("Alpha=0.05")
``````

``````
# 左側棄却域の表示
curve(dnorm(x, mean=0, sd=0.8), -3, 3, xlab="x: normal distribution N(0, 0.8^2)", ylab="density")
title("Alpha=0.05")

xmin <- -3
xmax <- 3
critical.left <- qnorm(alpha/2, mean=0, sd=0.8)
xaxis <- seq(xmin, critical.left, length=100)
yaxis <- c(dnorm(xaxis, mean=0, sd=0.8), 0, 0)
yaxis <- c(dnorm(xaxis, mean=0, sd=0.8), 0, 0)
xaxis <- c(xaxis, critical.left, xmin)
polygon(xaxis, yaxis, density=25)
``````

``````
# 右側棄却域の追加表示
curve(dnorm(x, mean=0, sd=0.8), -3, 3, xlab="x: normal distribution N(0, 0.8^2)", ylab="density")
title("Alpha=0.05")
xaxis <- seq(xmin, critical.left, length=100)
yaxis <- c(dnorm(xaxis, mean=0, sd=0.8), 0, 0)
yaxis <- c(dnorm(xaxis, mean=0, sd=0.8), 0, 0)
xaxis <- c(xaxis, critical.left, xmin)
polygon(xaxis, yaxis, density=25)

critical.right <- qnorm(alpha/2, mean=0, sd=0.8,lower.tail=F)
xaxis <- seq(critical.right, xmax, length=100)
yaxis <- c(dnorm(xaxis, mean=0, sd=0.8), 0, 0)
xaxis <- c(xaxis, xmax, critical.right)
polygon(xaxis, yaxis, density=25)

# 棄却域タイトル表示
ypos <- dnorm(critical.left, mean=0, sd=0.8)

# 受容域タイトル表示
text((critical.left+critical.right)/2, 2*ypos+0.02, "acceptance region")
xaxis <- c(rep(critical.left,2), rep(critical.right,2))
yaxis <- c(2*ypos-0.02, 2*ypos, 2*ypos, 2*ypos-0.02)
lines(xaxis,yaxis)
``````

``````
# α＝0.05での棄却水準値
critical.left
``````
``````[1] -1.568
``````
``````critical.right
``````
``````[1] 1.568
``````
``````
# —————————————————————————————————
# 棄却水準（α＝0.01）の場合
# —————————————————————————————————

# 正規分布（平均0, 標準偏差0.8）の図示
curve(dnorm(x, mean=0, sd=0.8), -3, 3, xlab="x: normal distribution N(0, 0.8^2)", ylab="density")

# 棄却水準（α＝0.01）を設定と表示
alpha <- 0.01
title("Alpha=0.01")

# 左側棄却域の表示
xmin <- -3
xmax <- 3
critical.left <- qnorm(alpha/2, mean=0, sd=0.8)
xaxis <- seq(xmin, critical.left, length=100)
yaxis <- c(dnorm(xaxis, mean=0, sd=0.8), 0, 0)
yaxis <- c(dnorm(xaxis, mean=0, sd=0.8), 0, 0)
xaxis <- c(xaxis, critical.left, xmin)
polygon(xaxis, yaxis, density=25)

# 右側棄却域の表示
critical.right <- qnorm(alpha/2, mean=0, sd=0.8,lower.tail=F)
xaxis <- seq(critical.right, xmax, length=100)
yaxis <- c(dnorm(xaxis, mean=0, sd=0.8), 0, 0)
xaxis <- c(xaxis, xmax, critical.right)
polygon(xaxis, yaxis, density=25)

# 棄却域タイトル表示
ypos <- dnorm(critical.left, mean=0, sd=0.8)

# 受容域タイトル表示
text((critical.left+critical.right)/2, 2*ypos+0.02, "acceptance region")
xaxis <- c(rep(critical.left,2), rep(critical.right,2))
yaxis <- c(2*ypos-0.02, 2*ypos, 2*ypos, 2*ypos-0.02)
lines(xaxis,yaxis)
``````

``````
# α＝0.01での棄却水準値
critical.left
``````
``````[1] -2.061
``````
``````critical.right
``````
``````[1] 2.061
``````
``````
# Original Script: 8 December 2004 by MINAKA Nobuhiro