File:Confidence-interval.svg
Summary
Description |
English: A probability density function of Student's t-distribution for directions to construct confidence interval of mean of normal distribution. |
Date | |
Source | Own work |
Author | ARAKI Satoru |
SVG development |
library(ggplot2)
alpha <- 0.05 # a significance level
n <- 10 # degree of freedom
accept <- function(x){
y <- dt(x, n)
y[x < qt(alpha/2, n) | x > qt(1 - alpha/2, n)] <- NA
return(y)
}
reject <- function(x){
y <- dt(x, n)
y[x > qt(alpha/2, n) & x < qt(1 - alpha/2, n)] <- NA
return(y)
}
N <- 1e4 # a large number
s <- 5 # fontsize
p <-
ggplot(data.frame(x=c(-3, +3)), aes(x=x)) +
stat_function(
fun=accept, geom="area",
fill="#0072B2", n=N) +
stat_function(
fun=reject, geom="area",
fill="#D55E00", n=N) +
annotate(
"text", x=0, y=0.2,
parse=T, label="1-alpha",
size=s, colour="#EEEEEE") +
annotate(
"text", x=-2.5, y=0.2,
parse=T, label="alpha/2",
size=s, colour="#D55E00") +
annotate(
"text", x=+2.5, y=0.2,
parse=T, label="alpha/2",
size=s, colour="#D55E00") +
annotate(
"text", x=qt(alpha/2, n), y=-0.02,
parse=T, label="-t[n-1](alpha/2)",
size=s, colour="#000000") +
annotate(
"text", x=0, y=-0.02,
label="0",
size=s, colour="#000000") +
annotate(
"text", x=qt(1 - alpha/2, n), y=-0.02,
parse=T, label="+t[n-1](alpha/2)",
size=s, colour="#000000") +
theme(
axis.text.y=element_blank(),
axis.text.x=element_blank(),
axis.ticks=element_blank()) +
labs(x="", y="")
svg(filename="confidence-interval.svg", width=16/2, height=9/2)
plot(p)
dev.off()
Licensing
I, the copyright holder of this work, hereby publish it under the following license:
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
- You are free:
- to share – to copy, distribute and transmit the work
- to remix – to adapt the work
- Under the following conditions:
- attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
- share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.