1. Create a new Rmarkdown document in Rstudio. Load the ‘tidyverse’ and ‘knitr’ packages. Install and load the ‘devtools’ and then the ‘CEPESP-R’ package.
library(tidyverse)
library(knitr)

install.packages("devtools")
library(devtools)

devtools::install_github("Cepesp-Fgv/cepesp-r")
library(cepespR)
  1. Let’s use the CEPESP-R API to download the prefeito candidate voting data from the 2016 municipal elections. See here and the code below.
data <- cepespdata(year=2016, position="Prefeito", regional_aggregation="Municipality",political_aggregation="Candidate")
  1. On average, how many people voted in any municipality in the first round of the 2016 election?

  2. What percentage of the votes cast in each region (NOME_MACRO) of the country were won by PMDB prefeito candidates?

  3. Now compare the previous result to the percentage of elected prefeitos (DESC_SIT_TOT_TURNO) who were from the PMDB in each region.

  4. How do male candidates differ from female candidates (DESCRICAO_SEXO)? Compare averages on two variables: The number of votes (QTDE_VOTOS) and age (IDADE_DATA_ELEICAO). Report the averages in a simple table. Hint: Remember to use summarise_at.

  5. Conduct a t-test to assess if women prefeitos receive a statistically different quantity of votes to men. Report a simple table of the results. Hint: Remember the tidy() action after a messy statistical test.

  6. Conduct a difference-in-means t-test between men and women of both number of votes and age at the same time. Report the p-values of each t-test.

  7. Create a neat, well-labelled, table of the average age of elected prefeitos in each region (NOME_MACRO) and by gender (DESCRICAO_SEXO). The table should have regions in the rows and gender in the columns.

  8. Are married candidates (DESCRICAO_ESTADO_CIVIL) for prefeito more likely to be elected than unmarried (all groups except married) candidates? Provide a well-formatted, labelled, table.