In-class exercise 1.

Run the following R script to see what happens. Change the ‘df’ parameter to a slightly larger integer and do it again. What statistical concept does this script illustrate?

[Solution and Answer]

Put plotting codes into a function to avoid massive replicated codes.

Use different values of df to call f_plot to find the change.

From these plots, we can know that these codes try to illustrate that the t distribution gets closer to the standard normal distribution as the degree of freedom increases.


In-class exercise 2.

Doll (1955) showed per capita consumption of cigarettes in 11 countries in 1930, and the death rates from lung cancer for men in 1950. Use R base graphics to generate the plot shown below.
Source: Freedman, et al. (1997). Statistics. pp. 148-150.

  • Column 1: Country names
  • Column 2: Cigarettes consumption (per million)
  • Column 3: Death rate (per capita)


[Solution and Answer]

Load in the data set

'data.frame':   11 obs. of  3 variables:
 $ Country    : Factor w/ 11 levels "Australia","Canada",..: 1 2 3 4 10 5 6 7 8 9 ...
 $ consumption: int  480 500 380 1100 1100 230 490 250 300 510 ...
 $ death      : int  180 150 170 350 460 60 240 90 110 250 ...

In-class exercise 4.

Run the R script to see what happens first and then explain how the effect is achieved by the script.

[Solution and Answer]

This script drew n (e.g., 60 here) plots to demonstrate a point roll along with a 8-shape curve. The color of the point get lighter when rolling.


In-class exercise 5.

Draw a pie chart to represent 50 shades of gray. Hint: Use ?gray to examine the gray level specification documented for the gray{grDevices}. Use ?pie to study the function for making pie charts documented for pie{graphics}.

[Solution and Answer]