Session Ready
Exercise

Q-Q plots for assessing normality

The quantile-quantile plot (Q-Q plot) is a better graphical method for revealing non-normality. In general, a Q-Q plot compares the quantiles of the data with the quantiles of a reference distribution; if the data are from a distribution of the same type (up to scaling and location), a reasonably straight line should be observed. You should know that the degrees of freedom (df) refer to the number of values or observations that can affect the system you are working with.

In the video, you saw how to generate 1000 normal data points with the rnorm() function, as well as how to use qqnorm() to create the Q-Q plot, and qqline() to add a straight line for reference:

> data <- rnorm(1000, mean = 3, sd = 2)
> qqnorm(data)
> qqline(data) 

In this exercise, you will create a Q-Q plot of the Dow Jones log-returns in djx against the normal reference distribution, which you will add as a visual guide. You will then compare the plot with simulated datasets from normal, Student t and uniform distributions generated with the rnorm(), rt() and runif() functions. You will be learning about the t distribution later in this chapter.

If the data are from a normal distribution the dots should be close to the red line (although there may be some deviation at the very end).

Once again, djx has been loaded into your workspace.

Instructions
100 XP
  • Make a Q-Q plot of djx against normal with and add a red line with qqline() and col = "red" to judge whether the plot is linear.
  • Calculate the length of djx with length() and assign to object n.
  • Generate n standard normal variables with rnorm() and assign them to x1. Make a Q-Q plot of x1 against normal and add a red line as before.
  • Generate n Student t variables with degree of freedom 4 and assign them to x2 (this has been done for you). Make a Q-Q plot of x2 against normal and add a red line.
  • Generate n uniform variables and assign them to x3 (this has been done for you). Make a Q-Q plot of x3 against normal and add a red line.