0
     ˆ¾�þB g„tN�•ÏçÉƒh¹Æ¿Ã      1
     ˆÊ�þFü¥Y²”A#ièÞóÉ„i–Â÷Æ¿Ã ?÷     ---
title: "Using Amelia"
date: "`r Sys.Date()`"
link-citations: yes
bibliography: amelia.bib
output:
  rmarkdown::html_vignette:
    keep_md: true
vignette: >
  %\VignetteIndexEntry{Using Amelia}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, echo = FALSE, include = FALSE}
knitr::opts_chunk$set(fig.width = 5, fig.height = 4, fig.align = "center")
options(digits = 4, show.signif.stars = FALSE)
set.seed(12345)
```


## Data 

We now demonstrate how to use Amelia using data from @MilKub05 which studies the effect of democracy on trade policy. For the purposes of this user's guide, we will use a subset restricted to nine developing countries in Asia from 1980 to 1999[^freetrade]. This dataset includes 9 variables:

| Variable   | Description                                         |
|:-----------|:----------------------------------------------------|
| `year`     | year                                                |
| `country`  | country                                             |
| `tariff`   | average tariff rates                                |
| `polity`   | Polity IV Score[^polity]                            |
| `pop`      | total population                                    |
| `gdp.pc`   | gross domestic product per capita                   |
| `intresmi` | gross international reserves                        |
| `signed`   | dummy variable if signed an IMF agreement that year |
| `fivop`    | measure of financial openness                       |
| `usheg`    | measure of US hegemony[^hegemony]                   |

 These variables correspond to the variables used in the analysis model of @MilKub05 in table 2.

[^freetrade]: We have artificially addedsome missingness to these data for presentational purposes. You can access the original data at
  [https://scholar.princeton.edu/hvmilner/data](https://scholar.princeton.edu/hvmilner/data).

[^polity]: The Polity score is a number between -10 and 10 indicating how democratic a country is. A fully autocratic country would be a -10 while a fully democratic country would be 1 10.

[^hegemony]: This measure of US hegemony is the US imports and exports as a percent of the world total imports and exports.

We first load the Amelia and the data:

```{r load_data, results = "hide"}
library(Amelia)
data(freetrade)
```



We can check the summary statistics of the data to see that there is missingness on many of the variables:

```{r summarize_data}
summary(freetrade)
```

In the presence of missing data, most statistical packages use *listwise deletion*, which removes any row that contains a missing value from the analysis. Using the base model of @MilKub05 Table 2, we run a simple linear model in R, which uses listwise deletion:

```{r mk_lm}
summary(lm(tariff ~ polity + pop + gdp.pc + year + country,
          data = freetrade))
```


Note that 60 of the 171 original observations are deleted due to missingness. These observations, however, are partially observed, and contain valuable information about the relationships between those variables which are present in the partially completed observations. Multiple imputation will help us retrieve that information and make better, more efficient, inferences.


## Multiple Imputation


When performing multiple imputation, the first step is to identify the variables to include in the imputation model. It is crucial to include at least as much information as will be used in the analysis model. That is, any variable that will be in the analysis model should also be in the imputation model. This includes any transformations or interactions of variables that will appear in the analysis model.

In fact, it is often useful to add more information to the imputation model than will be present when the analysis is run. Since imputation is predictive, any variables that would increase predictive power should be included in the model, even if including them in the analysis model would produce bias in estim