The sort function does what it says. We make a plot called a "step" plot:
You can also use draw a Q-Q plot (quantile-quantile). This plots the quantiles for our distribution (y-axis) against those for a normal distribution (x-axis). A straight line indicates that our distribution is close to normal.
Let's get a larger sample:
The quantile function accepts an argument telling it how to make the quantiles:
As expected, since the mean is 5 and the standard deviation is 1, 97.5 % of the values are < 5 + 1.96.
I showed this trick for plotting the normal distribution before. Now we plot it in red, and then overlay it with the density from the t-distribution (obtained with the function dt) with degrees of freedom (df) = 9,6,3,2,1.
The t distribution has fatter tails. If we had plotted it for larger values of df, it would asymptotically approach the normal distribution.
By using a very large sample, we can get a good idea for the cut-offs for 95% and 97.5% from the normal distribution:
And now compare them to the cut-offs for the t-distribution with df=9. We'll use these in the next example.