Understanding Student's t-distribution
Student's t-distribution is also known as t-distribution. It is applied to estimate the mean of the population from a normal distribution. Moreover, it is the basis of conducting Student's t-test. In the following recipe, we will introduce how to use R to perform Student's t-distribution.
Getting ready
In this recipe, you need to prepare your environment with R installed.
How to do it…
Please perform the following steps to generate samples from t-distribution:
First, we can use
rt
to generate three samples with the degree of freedom equal to10
:> set.seed(123) > rt(3, df = 10) [1] -0.6246844 -1.3782806 -0.1181245
Then, we use
dt
to obtain the density at x=3 with a degree of freedom equal to10
:> dt(3,df=10) [1] 0.01140055
Furthermore, we can visualize the Student's t-distribution's degree of freedom equals
1
:> plot(seq(-5,5,0.1), dt(seq(-5,5,0.1), df = 1), type='l', main="Student's t-distribution of df = 1")