Friday, February 13, 2015

R18. Student t Distribution in R

We can use the function dt for the Student t-Distribution to get the probability density function.


The Student t-Distribution is for the case the sample comes from a normal population, however the number of samples is less than 30.


The t-Distribution goes very near the normal as n becomes 30. It is hard to spot the difference in the graph.

# ex18.R
x <- seq(-3,+3, length = 500)
n <- 5
y <- dt(x, n-1)
plot(x, y, ylim = c(0,.4), col = 'red', type = 'l',
     ylab = 'Probability Density Function',
     main = 't dist, n=5:red, n=10:green, n=30:blue, norm:magenta')
n <- 10
y <- dt(x, n-1)
lines(x, y, col = 'green')
n <- 30
y <- dt(x, n-1)
lines(x, y, col = 'blue')
y <- dnorm(x)
lines(x, y, col = 'magenta')

Output:

No comments:

Post a Comment