Exercise

# Graphical methods for assessing normality

In the video, you learned how to create a histogram with 20 buckets that represents the probability density of the FTSE data, as well as how to add a **normal distribution** to the existing plot as a red line:

```
> hist(ftse, nclass = 20, probability = TRUE)
> lines(ftse, dnorm(ftse, mean = mu, sd = sigma), col = "red")
```

As you can see, `dnorm(x, mean, sd)`

calculates the probability density function (PDF) of the data `x`

with the calculated sample mean and standard deviation; this is known as the **method-of-moments**.

Finally, to calculate an estimate of the density of data `x`

, use `density(x)`

. This creates a so-called kernel-density estimate (KDE) using a non-parametric method that makes no assumptions about the underlying distribution.

The various plots suggest that the data are heavier tailed than normal, although you will learn about better graphical and numerical tests in future exercises.

In this exercise, you will fit a normal distribution to the log-returns of the Dow Jones index for 2008-2009 and compare the data with the fitted distribution using a histogram and a density plot. The object `djx`

containing Dow Jones data is loaded into your workspace.

Instructions

**100 XP**

- Calculate the average and standard deviation (
`sd()`

) of the`djx`

data and assign to`mu`

and`sigma`

, respectively. - Plot a histogram of
`djx`

with 20 buckets that represents a probability density of the data. - Fill in the
`lines()`

and`dnorm()`

functions to add the normal density curve for`djx`

as a red line to the histogram. - Plot a kernel-density estimate for
`djx`

using`density()`

. - Use the same
`lines()`

command as above to add the normal density curve for`djx`

as a red line to the KDE.