F分布のグラフィクス

MINAKA Nobuhiro — Nov 4, 2013, 3:04 PM

## F分布に関連する関数(df, pf, qf, rf)
## Copyright (c) 2004, 2013 by MINAKA Nobuhiro. All rights reserved. 

# —————————————————————————————————
# F分布の密度関数(df)を表示
# —————————————————————————————————

x <- seq(0, 4, 0.01)
plot(x, df(x, 15, 50), type="n", xlab="x", ylab="density")
curve(df(x, 13, 50), type="l", add=T)

plot of chunk unnamed-chunk-1


# —————————————————————————————————
# F分布の確率分布関数(pf)を追加表示
# —————————————————————————————————

x <- seq(0, 4, 0.01)
plot(x, df(x, 15, 50), type="n", xlab="x", ylab="density")
curve(df(x, 13, 50), type="l", add=T)
curve(pf(x, 13, 50), type="l", lty=3, add=T)

plot of chunk unnamed-chunk-1


# —————————————————————————————————
# 5%点の追加表示
# —————————————————————————————————

x <- seq(0, 4, 0.01)
plot(x, df(x, 15, 50), type="n", xlab="x", ylab="density")
curve(df(x, 13, 50), type="l", add=T)
curve(pf(x, 13, 50), type="l", lty=3, add=T)

abline(h=0.05)
lower.alpha5 <- qf(0.05, 13, 50)
lower.alpha5
[1] 0.4322
abline(v=lower.alpha5)
points(lower.alpha5, 0.05, cex=3.0, pch="*")

abline(h=0.95)
upper.alpha5 <- qf(0.05, 13, 50, lower.tail = FALSE)
upper.alpha5
[1] 1.921
abline(v=upper.alpha5)
points(upper.alpha5, 0.95, cex=3.0, pch="*")

plot of chunk unnamed-chunk-1


# —————————————————————————————————
# 1%点の追加表示
# —————————————————————————————————

x <- seq(0, 4, 0.01)
plot(x, df(x, 15, 50), type="n", xlab="x", ylab="density")
curve(df(x, 13, 50), type="l", add=T)
curve(pf(x, 13, 50), type="l", lty=3, add=T)

abline(h=0.05)
abline(v=lower.alpha5)
points(lower.alpha5, 0.05, cex=3.0, pch="*")

abline(h=0.95)
abline(v=upper.alpha5)
points(upper.alpha5, 0.95, cex=3.0, pch="*")

abline(h=0.01, lty=2)
lower.alpha1 <- qf(0.01, 13, 50)
lower.alpha1
[1] 0.2963
abline(v=lower.alpha1, lty=2)
points(lower.alpha1, 0.01, cex=3.0, pch="*")

abline(h=0.99, lty=2)
upper.alpha1 <- qf(0.01, 13, 50, lower.tail = FALSE)
upper.alpha1
[1] 2.508
abline(v=upper.alpha1, lty=2)
points(upper.alpha1, 0.99, cex=3.0, pch="*")

plot of chunk unnamed-chunk-1


# —————————————————————————————————
# F分布のパラメーター(1)――分子自由度n1を変える
# —————————————————————————————————

x <- seq(0, 4, 0.01)
plot(x, df(x, 15, 50), type="n", xlab="x", ylab="density")
title("F Distribution\nn1=13 -> 5")
for (i in 1:5) curve(df(x, 13-2*(i-1), 50), type="l", lty=i, add=T)

plot of chunk unnamed-chunk-1


# —————————————————————————————————
# F分布のパラメーター(2)――分母自由度n2を変える
# —————————————————————————————————

x <- seq(0, 4, 0.01)
plot(x, df(x, 15, 50), type="n", xlab="x", ylab="density")
title("F Distribution\nn2=50 -> 10")
for (i in 1:5) curve(df(x, 13, 50-10*(i-1)), type="l", lty=i, add=T)

plot of chunk unnamed-chunk-1


# —————————————————————————————————
# F分布のパラメーター(3)――分子と分母の自由度を同時に変える
# —————————————————————————————————

x <- seq(0, 4, 0.01)
plot(x, df(x, 15, 50), type="n", xlab="x", ylab="density")
title("F Distribution\nn1=13 -> 5\nn2=50 -> 10")
for (i in 1:5) curve(df(x, 13-2*(i-1), 50-10*(i-1)), type="l", lty=i, add=T)

plot of chunk unnamed-chunk-1


# Original Script: 8 December 2004 by MINAKA Nobuhiro
# Last Modified: 4 November 2013 by MINAKA Nobuhiro