Exercise

# Density plots as smoothed histograms

While they are probably not as well known as the histogram, density estimates may be regarded as *smoothed histograms*, designed to give a better estimate of the density function for a random variable.

In this exercise, you'll use the `ChickWeight`

dataset, which contains a collection of chicks' weights. You will first select for the chicks that are 16 weeks old. Then, you'll create a histogram using the `truehist()`

function, and add its density plot on top, using the `lines()`

and `density()`

functions with their default options. The density plot of this type of variable is often expected to conform approximately to the bell-shaped curve, otherwise known as the Gaussian distribution. Let's find out whether that's the case for this dataset.

Instructions

**100 XP**

- Create the variable
`index16`

using the`which()`

function that selects records from the`ChickWeight`

data frame with`Time`

equal to 16. - Create the variable
`weights`

that gives the weights of the 16-week old chicks. - Use the
`truehist()`

function to generate a histogram from`weights`

. - Use the
`lines()`

and`density()`

functions to overlay a density plot of the`weights`

values on the histogram.