---
title: "Mini-Monopoly"
author: "Matthew Wright"
date: "April 18, 2018"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Mini-Monopoly definition
Mini-Monopoly is defined as follows.
* The board consists of eight states numbered 1, 2, 3, 4, 5, 6, 7, 8.
* _Go_ is state 1
* _Jail_ is state 3
* _Go to Jail_ is state 7
* _Chance_ is state 6
* _Chance_ has 16 cards:
+ 1 _Go to Jail_,
+ 1 _Go to Go_,
+ 1 _Go to 4_,
+ 13 result in no move
* On each turn, roll a fair 4-sided die to determine how many spaces you move.
## Initial exploration
### Creating a transition matrix
At first, simply create a transition matrix `rollTrans` for a Markov chain with eight states and moves determined by rolls of a fair 4-sided die.
Rather than typing out all of the numbers in the matrix, write a function that will do it for you, and which we can generalize later.
Your function should accept two arguments: a number of states and a number of sides on the die.
The function should return the transition matrix.
### Investigating the steady-state distribution
Investigate the steady-state distribution of your transition matrix `rollTrans`.
Do this in three different ways:
1. Simulate a large number of 'agents' that start in any state(s) and move around probabilistically for a long time.
2. Raise your matrix to a high power (using matrix multiplication) and look at the entries in any column.
3. Find the eigenvector corresponding to eigenvalue 1.
## Add the Jail
### Use matrix multiplication to create a new transition matrix
Instead of modifying `rollTrans` to account for the _Go to Jail_ move, we can use matrix multiplication.
The idea is simple. As the game describes, first we move by rolling a die, and if we land on state 7, then we move to jail.
The move from the die roll is given by `rollTrans`, and the _Go to Jail_ move will be given by a new matrix `jailTrans`.
The matrix `jailTrans` is not much different from the 8x8 identity matrix.
Most of the time there is no transition ($i->i$ with probability 1).
Only if we land on the special go to jail site (site 7) do we transition to jail (site 3). This means $7->3$ with probability 1.
Thus, build `jailTrans` by first creating an identity matrix, and then modify column 7.
After you have created the `jailTrans` matrix, multiply `jailTrans %*% rollTrans` to obtain the new transition matrix.
Note that `jailTrans` is multiplied on the _left_.
### Steady state for the Roll+Jail transition matrix
Investigate the steady-state distribution using your favorite method.
## Add Chance
### Create a new transition matix
Use the same idea as last time: Create a transition matrix, `chanceTrans`, to represent the effect of selecting a _Chance_ card and moving accordingly.
Recall that _Chance_ is state 6. If you land on this state, you draw one of 16 cards. One card results in _Go to Jail_, one results in _Go to Go_, one results in _Go to 4_, and the remaining 13 result in no further move on this turn.
The matrix `chanceTrans` should represent only these moves that result from _Chance_ cards.
After you have created this matrix, the final transition matrix will be the product `chanceTrans %*% jailTrans %*% rollTrans`.
### Steady state for the Roll+Jail+Chance transition matrix
Investigate the steady-state distribution using your favorite method.
## Comparing all three steady-state distributions
Use ggplot2 to make a bar chart that compares the three steady-state distributions.
You will need to create a data frame to store the three steady-state distributions.
Suppose that you have these distributions in the vectors `rollDist`, `rollJailDist`, and `rollJailChanceDist`.
Then you can create the data frame like this:
```{r eval=FALSE}
monopolyData <- data.frame(prob=c(rollDist, rollJailDist, rollJailChanceDist),
site=rep(1:numStates, 3),
type=rep(c("Roll", "Roll+Jail", "Roll+Jail+Chance"), each=8))
```
After creating the data frame, you can make a bar chart like this:
```{r, eval=FALSE}
ggplot(monopolyData) +
geom_bar(aes(site, prob, fill=type), stat="identity", position="dodge", width=0.75) +
scale_x_continuous(breaks=1:8) +
ggtitle("Steady-state distribution for Mini-monopoly")
```
We can see the effect of the additional rules:
* For the roll-only variant, all the sites are equally likely.
* If we add just the jail, then no one stays on state 7, and state 3 becomes the most likely. States right after 3 are more likely than states before 3.
* If we add _Chance_, then the probability of state 6 decreases, while certain other probabilities increase.
## Assignment for Friday:
Re-do the analysis of mini-Monopoly making the following adjustments. You only need to compute the steady-state values one way (powers or agents or eigenstuff)
* Increase the number of sites to ten or more.
* Change the roll probability--- use a die with more sides, or perhaps not a fair die.
* Add more _Chance_ cards.