トップ
新規
一覧
単語検索
最終更新
ヘルプ
ログイン
アールメカブ
R_dnorm_dt
をテンプレートにして作成
開始行:
[[Rの備忘録]]
こんなコードを紹介した。
x <- 1:20
curve(dnorm, -4, 4, col = 2, lty = 2, lwd = 2)
my.dt <- function(x) dt(x, 19)
curve(my.dt, -4, 4, add = T, col = 5, lty= 3, lwd = 2)
legend(-4, .4, legend= c("正規分布", "t分布"),
col = c(2,5), lty = c(2,3), lwd = 2)
[[R_正規分布のプロット図]]もみてください。
par(mfrow = c(2,2))
#########
my.mean <- 50
my.sd <- 10
my.dnorm <- function(x) dnorm(x, mean = my.mean, sd = my...
plot(my.dnorm, 20, 80, main = paste("平均=", my.mean , ...
" の正規分布",sep = ""),ylab = "頻度", xlab = "平均")
xvals <- seq(my.mean - my.sd * 2, my.mean + my.sd * 2,
length = 100)
dvals <- my.dnorm(xvals)
polygon(c(xvals, rev(xvals) ) , c(rep(0, 100),
rev(dvals)), col = "yellow")
text(my.mean, my.dnorm(my.mean) , lab = "95%", cex = 1.8)
text(my.mean - my.sd * 2.1, my.dnorm(my.mean - my.sd * 2...
lab = "2.5%", cex = 1.2, col = "red")
text(my.mean + my.sd * 2.1, my.dnorm(my.mean + my.sd * 2...
lab = "2.5%", cex = 1.2, col = "red")
lines(c(my.mean - my.sd * 2, my.mean + my.sd * 2 ), c(0,...
lines(c(my.mean,my.mean), c(0,my.dnorm(my.mean)), lty=2,
col ="blue", lwd = 3)
#########
#########
my.mean <- 175
my.sd <- 8.8
my.dnorm <- function(x) dnorm(x, mean = my.mean, sd = my...
plot(my.dnorm, my.mean - my.sd * 3, my.mean + my.sd * 3,
main = paste("平均=", my.mean , 標準偏差=", my.sd,
" の正規分布",sep = ""),ylab = "頻度", xlab = "平均")
xvals <- seq(my.mean - my.sd * 2, my.mean + my.sd * 2,
length = 100)
dvals <- my.dnorm(xvals)
polygon(c(xvals, rev(xvals) ) , c(rep(0, 100),
rev(dvals)), col = "yellow")
text(my.mean, my.dnorm(my.mean) , lab = "95%", cex = 1.8)
text(my.mean - my.sd * 2.1, my.dnorm(my.mean - my.sd * 2...
lab = "2.5%", cex = 1.2, col = "red")
text(my.mean + my.sd * 2.1, my.dnorm(my.mean + my.sd * 2...
lab = "2.5%", cex = 1.2, col = "red")
lines(c(my.mean - my.sd * 2, my.mean + my.sd * 2 ), c(0,...
lines(c(my.mean,my.mean), c(0,my.dnorm(my.mean)), lty=2,
col ="blue", lwd = 3)
#########
### legend(-4.5, .4, legend= c("平均を中心に左右に標準偏...
#########
my.mean <- 7
my.sd <- 2
my.dnorm <- function(x) dnorm(x, mean = my.mean, sd = my...
plot(my.dnorm, my.mean - my.sd * 3, my.mean + my.sd * 3,
main = paste("平均=", my.mean , ", 標準偏差=", my.sd,
" の正規分布",sep = ""),ylab = "頻度", xlab = "平均")
xvals <- seq(my.mean - my.sd * 2, my.mean + my.sd * 2,
length = 100)
dvals <- my.dnorm(xvals)
polygon(c(xvals, rev(xvals) ) , c(rep(0, 100),
rev(dvals)), col = "yellow")
text(my.mean, my.dnorm(my.mean) , lab = "95%", cex = 1.8)
text(my.mean - my.sd * 2.1, my.dnorm(my.mean - my.sd * 2),
lab = "2.5%", cex = 1.2, col = "red")
text(my.mean + my.sd * 2.1, my.dnorm(my.mean + my.sd * 2...
lab = "2.5%", cex = 1.2, col = "red")
lines(c(my.mean - my.sd * 2, my.mean + my.sd * 2 ), c(0,...
lines(c(my.mean,my.mean), c(0,my.dnorm(my.mean)), lty=2,
col ="blue", lwd = 3)
#########
#########
my.mean <- 0
my.sd <- 1
my.dnorm <- function(x) dnorm(x, mean = my.mean, sd = my...
plot(my.dnorm, my.mean - my.sd * 3, my.mean + my.sd * 3,
main = paste("平均=", my.mean , ", 標準偏差=", my.sd,
" の正規分布",sep = ""),ylab = "頻度", xlab = "平均")
xvals <- seq(my.mean - my.sd * 2, my.mean + my.sd * 2,
length = 100)
dvals <- my.dnorm(xvals)
polygon(c(xvals, rev(xvals) ) , c(rep(0, 100),
rev(dvals)), col = "yellow")
text(my.mean, my.dnorm(my.mean) , lab = "95%", cex = 1.8)
text(my.mean - my.sd * 2.1, my.dnorm(my.mean - my.sd * 2),
lab = "2.5%", cex = 1.2, col = "red")
text(my.mean + my.sd * 2.1, my.dnorm(my.mean + my.sd * 2),
lab = "2.5%", cex = 1.2, col = "red")
lines(c(my.mean - my.sd * 2, my.mean + my.sd * 2 ), c(0,...
lines(c(my.mean,my.mean), c(0,my.dnorm(my.mean)), lty=2,
col ="blue", lwd = 3)
#########
終了行:
[[Rの備忘録]]
こんなコードを紹介した。
x <- 1:20
curve(dnorm, -4, 4, col = 2, lty = 2, lwd = 2)
my.dt <- function(x) dt(x, 19)
curve(my.dt, -4, 4, add = T, col = 5, lty= 3, lwd = 2)
legend(-4, .4, legend= c("正規分布", "t分布"),
col = c(2,5), lty = c(2,3), lwd = 2)
[[R_正規分布のプロット図]]もみてください。
par(mfrow = c(2,2))
#########
my.mean <- 50
my.sd <- 10
my.dnorm <- function(x) dnorm(x, mean = my.mean, sd = my...
plot(my.dnorm, 20, 80, main = paste("平均=", my.mean , ...
" の正規分布",sep = ""),ylab = "頻度", xlab = "平均")
xvals <- seq(my.mean - my.sd * 2, my.mean + my.sd * 2,
length = 100)
dvals <- my.dnorm(xvals)
polygon(c(xvals, rev(xvals) ) , c(rep(0, 100),
rev(dvals)), col = "yellow")
text(my.mean, my.dnorm(my.mean) , lab = "95%", cex = 1.8)
text(my.mean - my.sd * 2.1, my.dnorm(my.mean - my.sd * 2...
lab = "2.5%", cex = 1.2, col = "red")
text(my.mean + my.sd * 2.1, my.dnorm(my.mean + my.sd * 2...
lab = "2.5%", cex = 1.2, col = "red")
lines(c(my.mean - my.sd * 2, my.mean + my.sd * 2 ), c(0,...
lines(c(my.mean,my.mean), c(0,my.dnorm(my.mean)), lty=2,
col ="blue", lwd = 3)
#########
#########
my.mean <- 175
my.sd <- 8.8
my.dnorm <- function(x) dnorm(x, mean = my.mean, sd = my...
plot(my.dnorm, my.mean - my.sd * 3, my.mean + my.sd * 3,
main = paste("平均=", my.mean , 標準偏差=", my.sd,
" の正規分布",sep = ""),ylab = "頻度", xlab = "平均")
xvals <- seq(my.mean - my.sd * 2, my.mean + my.sd * 2,
length = 100)
dvals <- my.dnorm(xvals)
polygon(c(xvals, rev(xvals) ) , c(rep(0, 100),
rev(dvals)), col = "yellow")
text(my.mean, my.dnorm(my.mean) , lab = "95%", cex = 1.8)
text(my.mean - my.sd * 2.1, my.dnorm(my.mean - my.sd * 2...
lab = "2.5%", cex = 1.2, col = "red")
text(my.mean + my.sd * 2.1, my.dnorm(my.mean + my.sd * 2...
lab = "2.5%", cex = 1.2, col = "red")
lines(c(my.mean - my.sd * 2, my.mean + my.sd * 2 ), c(0,...
lines(c(my.mean,my.mean), c(0,my.dnorm(my.mean)), lty=2,
col ="blue", lwd = 3)
#########
### legend(-4.5, .4, legend= c("平均を中心に左右に標準偏...
#########
my.mean <- 7
my.sd <- 2
my.dnorm <- function(x) dnorm(x, mean = my.mean, sd = my...
plot(my.dnorm, my.mean - my.sd * 3, my.mean + my.sd * 3,
main = paste("平均=", my.mean , ", 標準偏差=", my.sd,
" の正規分布",sep = ""),ylab = "頻度", xlab = "平均")
xvals <- seq(my.mean - my.sd * 2, my.mean + my.sd * 2,
length = 100)
dvals <- my.dnorm(xvals)
polygon(c(xvals, rev(xvals) ) , c(rep(0, 100),
rev(dvals)), col = "yellow")
text(my.mean, my.dnorm(my.mean) , lab = "95%", cex = 1.8)
text(my.mean - my.sd * 2.1, my.dnorm(my.mean - my.sd * 2),
lab = "2.5%", cex = 1.2, col = "red")
text(my.mean + my.sd * 2.1, my.dnorm(my.mean + my.sd * 2...
lab = "2.5%", cex = 1.2, col = "red")
lines(c(my.mean - my.sd * 2, my.mean + my.sd * 2 ), c(0,...
lines(c(my.mean,my.mean), c(0,my.dnorm(my.mean)), lty=2,
col ="blue", lwd = 3)
#########
#########
my.mean <- 0
my.sd <- 1
my.dnorm <- function(x) dnorm(x, mean = my.mean, sd = my...
plot(my.dnorm, my.mean - my.sd * 3, my.mean + my.sd * 3,
main = paste("平均=", my.mean , ", 標準偏差=", my.sd,
" の正規分布",sep = ""),ylab = "頻度", xlab = "平均")
xvals <- seq(my.mean - my.sd * 2, my.mean + my.sd * 2,
length = 100)
dvals <- my.dnorm(xvals)
polygon(c(xvals, rev(xvals) ) , c(rep(0, 100),
rev(dvals)), col = "yellow")
text(my.mean, my.dnorm(my.mean) , lab = "95%", cex = 1.8)
text(my.mean - my.sd * 2.1, my.dnorm(my.mean - my.sd * 2),
lab = "2.5%", cex = 1.2, col = "red")
text(my.mean + my.sd * 2.1, my.dnorm(my.mean + my.sd * 2),
lab = "2.5%", cex = 1.2, col = "red")
lines(c(my.mean - my.sd * 2, my.mean + my.sd * 2 ), c(0,...
lines(c(my.mean,my.mean), c(0,my.dnorm(my.mean)), lty=2,
col ="blue", lwd = 3)
#########
ページ名: