This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(MCMCpack) | |
## Coping with polls: the more recent, the better they are. | |
##http://en.wikipedia.org/wiki/Opinion_polling_for_the_Scottish_independence_referendum,_2014 | |
polls = NULL | |
polls <- data.frame( rbind( | |
Survation = c(37, 50, 1010), | |
YouGov = c(35, 55, 1142), | |
TNSBMRB = c(32, 45, 1003), | |
IpsosMORI = c(40, 54, 1006), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/Library/Frameworks/Python.framework/Versions/3.3/bin/python3 | |
# -*- coding: utf-8 -*- | |
from urllib.request import urlopen | |
from bs4 import BeautifulSoup | |
import csv | |
from pymongo import MongoClient | |
from pandas import DataFrame | |
def rodaPesquisa(): | |
client = MongoClient() | |
my_db = client["pesquisas_tse"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> summary(mcmc) | |
forecast class object: | |
MCMC: 500 draws with adaptation of 500 and a thinning interval of 5. | |
Predicted at 2014-10-24, using 16 polls from 5 houses. | |
Evidence starting at 2014-03-10. | |
Election day 2014-10-26. | |
Machine runtime: ~ 7 minutes. | |
Expected results + swing voters: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############## ################## | |
# Qual é a probabilidade de A estar a frente de B dada a diferença entre eles e o erro amostral? | |
# Abaixo, a diferença é de .505 - .495 = 1% | |
A = .505 | |
B = .495 | |
n = c(2500, 1111, 625, 400) | |
# Resolve a margem de erro por N | |
(moe = sqrt((A*(1-A)/n)+(B*(1-B)/n)+(2*((A*B)/n)) ) ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doInstall <- TRUE | |
require(Amelia) | |
require(ggplot2) | |
ANES <- read.csv("ANES.csv") | |
ANES <- ANES[ANES$year == 2008, -c(1, 11, 17)] # Limit to just 2008 respondents, | |
head(ANES) # remove some non-helpful variables | |
with(ANES, plot(jitter(pid7), jitter(ideo7))) | |
myModel <- lm(pid7 ~ ideo7 + female + age + south, data = ANES) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
forecast class object: | |
MCMC: 1000 samples with a burnin of 500 and a thinning of 5. | |
Predicted at 2014-09-20, using 79 polls from 9 houses. | |
Evidence starting at 2014-02-19. | |
Election day 2014-10-05. | |
Machine runtime: ~ 42 minutes. | |
Expected results + swing voters: | |
Expected results: (Pooled) National samples only |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Data latest polls | |
polls = NULL | |
polls <- data.frame( rbind( | |
Opinium = c(43, 47, 1156), | |
Survation = c(44, 48, 1000), | |
ICM = c(41, 45, 1175) | |
)) | |
# set up for decimals | |
polls[, 1:2] <- polls[, 1:2]/100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
R> summary(mcmc2014) | |
forecast class object: | |
MCMC: 1000 samples with a burnin of 500 and a thinning of 5. | |
Predicted at 2014-09-20, using 33 polls from 5 houses. | |
Evidence starting at 2014-02-19. | |
Election day 2014-10-05. | |
Machine runtime: ~ 28 minutes. | |
Expected results + swing voters: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
R> summary(mcmc2014) | |
forecast class object: | |
MCMC: 1000 samples with a burnin of 500 and a thinning of 10. | |
Predicted at 2014-09-25, using 36 polls from 5 houses. | |
Evidence starting at 2014-02-19. | |
Election day 2014-10-05. | |
Machine runtime: ~ 57 minutes. | |
Expected results + swing voters: |
OlderNewer