有意水準α(両側検定)の棄却域を図示する関数。
無駄に長い。必要がなければしない作業。
normd2 <- function (α)
{
z <- seq(-3,3,0.01)
x <-z
plot(z,dnorm(z,mean=0,sd=1.0),type="n")
curve(dnorm(x,mean=0,sd=1.0),type="l",add=T)
alpha <- α
title("Alpha=0.05")
zmin <- -3
zmax <- 3
critical.left <- qnorm(alpha/2, mean=0, sd=1.0)
xaxis <- seq(zmin, critical.left, length=100)
yaxis <- c(dnorm(xaxis, mean=0, sd=1.0), 0, 0)
yaxis <- c(dnorm(xaxis, mean=0, sd=1.0), 0, 0)
xaxis <- c(xaxis, critical.left, xmin)
polygon(xaxis, yaxis, density=25)
critical.right <- qnorm(alpha/2, mean=0,sd=1.0,lower.tail=F)
xaxis <- seq(critical.right, zmax, length=100)
yaxis <- c(dnorm(xaxis, mean=0, sd=1.0), 0, 0)
xaxis <- c(xaxis, zmax, critical.right)
polygon(xaxis, yaxis, density=25)
ypos <- dnorm(critical.left, mean=0, sd=1.0)
text(zmin, ypos, "rejection?nregion", adj=0)
text(zmax, ypos, "rejection?nregion", adj=1)
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)
}
> normd2(0.05)
無駄に長い。必要がなければしない作業。
normd2 <- function (α)
{
z <- seq(-3,3,0.01)
x <-z
plot(z,dnorm(z,mean=0,sd=1.0),type="n")
curve(dnorm(x,mean=0,sd=1.0),type="l",add=T)
alpha <- α
title("Alpha=0.05")
zmin <- -3
zmax <- 3
critical.left <- qnorm(alpha/2, mean=0, sd=1.0)
xaxis <- seq(zmin, critical.left, length=100)
yaxis <- c(dnorm(xaxis, mean=0, sd=1.0), 0, 0)
yaxis <- c(dnorm(xaxis, mean=0, sd=1.0), 0, 0)
xaxis <- c(xaxis, critical.left, xmin)
polygon(xaxis, yaxis, density=25)
critical.right <- qnorm(alpha/2, mean=0,sd=1.0,lower.tail=F)
xaxis <- seq(critical.right, zmax, length=100)
yaxis <- c(dnorm(xaxis, mean=0, sd=1.0), 0, 0)
xaxis <- c(xaxis, zmax, critical.right)
polygon(xaxis, yaxis, density=25)
ypos <- dnorm(critical.left, mean=0, sd=1.0)
text(zmin, ypos, "rejection?nregion", adj=0)
text(zmax, ypos, "rejection?nregion", adj=1)
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)
}
> normd2(0.05)