subtitle: "Purchasing power of English workers from the 16th to the 19th century"
author: "Yevheniya Nosyk (M2 MOSIG)"
date: "12 Dec 2020"
output: pdf_document
---
## The dataset
The goal of the exercise is to reproduce the study of William Playfair on the purchasing power of English workers. The scientist summarized his analysis on a graph (https://fr.wikipedia.org/wiki/William_Playfair#/media/File:Chart_Showing_at_One_View_the_Price_of_the_Quarter_of_Wheat,_and_Wages_of_Labour_by_the_Week,_from_1565_to_1821.png) but did not provide the raw data. We will load the dataset recreated later that represents the points on the original graph:
```{r}
data = read.csv("wheat.txt", header = TRUE)
head(data)
```
```{r}
sprintf("There are %s observations and %s features.", nrow(data), ncol(data))
```
Let's examine every column in more details. The column X does not hold any valuable information, except of numbering every row. Thus, we will remove it.
```{r}
data = subset(data, select = -c(X))
```
We see that for each column the datatype was inferred correctly (integer for Year and double for Wheat/Wages). We can print the minimum and maximum values of every column to check that they actually make sence. For example, we know that observations took place between 1565 and 1821. We also do not expect negative values for Wheat and Wages:
```{r}
sprintf("The minimum year is %s and the maximum %s",min(data$Year), max(data$Year))
sprintf("The minimum amout of wheat is %s and the maximum %s",min(data$Wheat),
max(data$Wheat))
sprintf("The minimum wage is %s and the maximum %s",min(data$Wages), max(data$Wages))
```
We just discovered that some of the observations do not contain data for wages. Locate those:
```{r}
subset(data, is.na(data$Wages))
```
There are three rows with missing data. Looking at the original graph, those correspond to the last observations on the bar chart and wages are indeed missing. We would usually remove such observations, but we will not do so to reproduce the original graph exactly. We still want to check the values of Wages column, disregarding missing ones:
```{r}
sprintf("The minimum wage is %s and the maximum %s",min(data$Wages,na.rm=TRUE),
max(data$Wages,na.rm=TRUE))
```
## Part 1: Recreate the original graph
Below is a graph drawn by William Playfair:

We will use ggplot to reproduce the following key points:
- X axis represents the years of observations, from 1565 to 1830. The axis tick labels are not homogeneous though. They are spaced out at different intervals - either 5 (at the very beginning and at the very end) or 10 years.
- Y axis represents the amount of shillings that measure the price of a quarter of a pound of wheat as well as the weekly salary.
- The red line illustrates the evolution of salaries in time.
- The bar chart illustrates the evolution of the price of a quarter of a pound of wheat.
annotate("text", x=1600, y=7, label= "Weekly Wages of a Good Mechanic",
size=1.25, angle=2, color="white") +
annotate("text", x=1735, y=15, label= "Weekly Wages of a Good Mechanic",
size=1.25, angle=9, color="white") +
labs(x=paste("5 Years each division",
" ",
"5 Years each division"),
y="Price of the Quarter of Wheat in Shillings")
```
## Part 2: Improve the original graph
There are several ways in which we can improve the original graph:
- use both the right and left parts of the Y axis to represent two different quantities - "shillings per week" and "the price of the quarter of a pound";
- improve the representation of the left Y axis by showing full numbers instead of "5"s;
- X axis will have it's ticks spaced out evenly, at the interval of 10 years (except for the very beginning, to make years end with 0s for better readability);
- X axis will end at year 1810, as there are no more observations after;
- use line charts for both Wages and Wheat and add legend;
- remove the three data points that do not have the corresponding wage values;
labs(title=paste("Chart, Showing at One View The Price of The Quarter",
"of Wheat \n and Wages of Labour by the Week"),
x="Year",
y="Price of the Quarter of Wheat in Shillings")
```
## Part 3: Evaluate the purchasing power
The current version of the plot shows how wheat price and weekly salary evolved with time. These absolute numbers do not give good intuition about the relationship between two variables. One may think that higher salary allows workers buy more wheat, but is it
really the case? We will see by plotting the purchasing power, that is the number of quarters of pound of wheat a typical worker can buy weekly.
We first introduce a new column to our data, namely PrPow, which is merely the number of quarters of Wheat that can be bought with weekly salary. We will round the result to two digits after comma:
title="The Purchasing Power of Workers from 1565 to 1810")
```
Even though we saw in the original graph that the salary has been constantly increasing, it did not always imply higher purchasing power. It is best seen during the last fifty years of observations - high salaries resulted in even higher wheat prices and, consequently, decreased purchasing power. This makes us doubt how well wages are correlated to wheat prices. We make a simple correlation test and pay a special attention to the correlation coefficient. It can be in the range [-1,1], where -1 means strong negative correlation, +1 is strong positive correlation and 0 is no correlation at all. The obtained value is 0.58, which signifies a moderate positive correlation between weekly wages and wheat prices. For 95% confidence interval, we want p-value to be less than 0.05 and it is indeed the case, meaning that the experiment results have a very low probability of being random.
We can plot the wages as a function of wheat price and add a regression line. To add the notion of Years, we will add labels to some of the data points: