knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" )
The goal of pollofpolls is to make it easy to make a poll of polls.
This package is open sourced and all contributions are welcome. I have made some methodological choices in this implementation that you are more than welcome to challenge.
Please do so by raising issues here on github and / or by creating new functions and doing a pull request.
In the code of each function I have tried to document my choices as good as possible. Please raise an issue if you feel something is wrong or missing.
There are now two methods available for calculating poll of polls:
The methodology used is based on these two articles:
https://greenbookblog.org/2018/01/16/the-prediction-how-nate-silver-does-it/
https://fivethirtyeight.com/features/the-polls-are-all-right/
This is the way used in example one and two
The methodology there is based on hear say. It is pretty intuitive - read the documentation for the function: pp_poll_of_poll_summariser()
This is the way used in example three.
You can install pollofpolls from github with:
# install.packages("devtools") devtools::install_github("mikkelkrogsholm/pollofpolls")
This is hands free driverless poll of polls calculation.
library(pollofpolls) pollofpoll <- suppressMessages(pp_auto_poll_of_poll()) # Round the digits so it looks pretty pollofpoll[, 1:2] <- purrr::map(pollofpoll[, 1:2], round, 2) # Make a better looking table knitr::kable(pollofpoll)
This is basically a run through of each part of the driverless poll of polls.
library(pollofpolls) # Download the raw polls raw_polls <- pp_get_raw_polls() # Do a check on the polls checked_polls <- pp_check_raw_polls(raw_polls = raw_polls, silent = TRUE) # Calculate the pollster rating pollster_rating <- pp_calc_pollster_rating() # Add weights to the polls polls_with_wt <- pp_add_weights(checked_polls = checked_polls, pollster_rating = pollster_rating) # Calculate the final pole final_poll <- pp_calc_poll(polls_with_wt = polls_with_wt) # Round the digits so it looks pretty final_poll[, 1:2] <- purrr::map(final_poll[, 1:2], round, 2) # Make a better looking table knitr::kable(final_poll)
This is the way I hear they do it at altinget.
library(pollofpolls) polls <- pp_get_raw_polls() my_pp <- pp_poll_of_poll_summariser(polls) # Round the digits so it looks pretty my_pp[, 1:2] <- purrr::map(my_pp[, 1:2], round, 2) # Make a better looking table knitr::kable(my_pp)
The two methods are very alike when it comes to predicting the results
library(tidyverse) plotdata <- inner_join(pollofpoll, my_pp, by = "party") ggplot(plotdata) + geom_point(aes(pred.x, pred.y)) + theme_minimal() + labs(y = "Altinget", x = "FiveThirtyEight") + expand_limits(x = c(0, max(plotdata$pred.y)), y = c(0, max(plotdata$pred.x))) + geom_abline(intercept = 0, slope = 1, linetype = "dashed", color = "gray") + coord_equal()
... but very different when it comes to estimating the error. One uses a formula based error and the other a more empirically derived one. And it shows.
ggplot(plotdata) + geom_point(aes(error.x, error.y)) + theme_minimal() + labs(y = "Altinget", x = "FiveThirtyEight") + expand_limits(x = c(0, max(plotdata$error.y)), y = c(0, max(plotdata$error.x))) + geom_abline(intercept = 0, slope = 1, linetype = "dashed", color = "gray") + coord_equal()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.