Skip to content

Instantly share code, notes, and snippets.

View dmarcelinobr's full-sized avatar
💭
I may be slow to respond

Daniel Marcelino dmarcelinobr

💭
I may be slow to respond
View GitHub Profile
> summary(mcmc)
forecast class object:
MCMC: 1000 samples with a burnin of 500 and a thinning of 5.
Predicted at 2014-10-05, using 50 polls from 5 houses.
Evidence starting at 2014-02-19.
Election day 2014-10-05.
Machine runtime: ~ 46 minutes.
Expected results + swing voters:
> print(wtd.polls)
PT PSDB PSB OTHERS WASTE n SWING
VoxPopuli 0.3800000 0.1700000 0.2540000 0.02000000 0.07000000 2000 0.1060
Sensus 0.3510000 0.2070000 0.2500000 0.02500000 0.08350000 2000 0.0835
MDA 0.4040000 0.1980000 0.2520000 0.02300000 0.05900000 2002 0.0640
Datafolha 0.4000000 0.2000000 0.2500000 0.03000000 0.10000000 7520 0.0200
5 0.4103400 0.2063354 0.2637111 0.02811200 0.09150146 13522 0.0000
6 0.4516684 0.2271169 0.2902713 0.03094336 0.00000000 13522 0.0000
> summary(mcmc)
forecast class object:
MCMC: 1000 samples with a burnin of 500 and a thinning of 5.
Predicted at 2014-10-04, using 89 polls from 9 houses.
Evidence starting at 2014-02-19.
Election day 2014-10-05.
Machine runtime: ~ 45 minutes.
Expected results + swing voters:
> summary(mcmc2014)
forecast class object:
MCMC: 1000 samples with a burnin of 500 and a thinning of 5.
Predicted at 2014-09-27, using 37 polls from 5 houses.
Evidence starting at 2014-02-19.
Election day 2014-10-05.
Machine runtime: ~ 45 minutes.
Expected results + swing voters:
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:
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:
# 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
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
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)
@dmarcelinobr
dmarcelinobr / prob_AvsB_0.R
Last active August 29, 2015 14:06
Resolve por aproximação o tal do empate técnico estatístico da margem de erro
############## ##################
# 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)) ) )