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
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:
> 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:
> 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:
> 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-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:
## 2010
> seats2010 = c(88,79,53,43,41,41,34,28,21,17,15,15,12,8,4,3,3,2,2,2,1,1)
> prop2010=seats2010/513
[1] 0.171539961 0.153996101 0.103313840 0.083820663 0.079922027
[6] 0.079922027 0.066276803 0.054580897 0.040935673 0.033138402
[11] 0.029239766 0.029239766 0.023391813 0.015594542 0.007797271
[16] 0.005847953 0.005847953 0.003898635 0.003898635 0.003898635
[21] 0.001949318 0.001949318
> get.enp(seats=prop2010, votes=NULL, total=1, method="Golosov")
> summary(mcmc)
forecast class object:
MCMC: 1000 draws with adaptation of 1000 and a thinning interval of 5.
Predicted at 2014-10-16, using 9 polls from 6 houses.
Evidence starting at 2014-10-06.
Election day 2014-10-26.
Machine runtime: ~ 7 minutes.
Expected results + swing voters:
> summary(mcmc)
forecast class object:
MCMC: 500 draws with adaptation of 500 and a thinning interval of 1.
Predicted at 2014-10-25, using 19 polls from 7 houses.
Evidence starting at 2014-10-06.
Election day 2014-10-26.
Machine runtime: ~ 2 minutes.
Expected results + swing voters:
# A vector of polls, the newer the better
pctDilma <- c(.53, .54, .52, .467, .52, .505, .436)
simVote = function(n){
# bernoulli: returns TRUE whenever Dilma wins
result = sample(c("Dilma","Aecio"),size=1000,
replace=TRUE, prob = c(pctDilma[n],1-pctDilma[n]))
return(length(result[result=='Dilma'])>500)
}
> summary(mcmc)
forecast class object:
MCMC: 1000 draws with adaptation of 500 and a thinning interval of 5.
Predicted at 2014-11-30, using 13 polls from 6 houses.
Evidence starting at 2014-07-15.
Election day 2014-11-30.
Machine runtime: ~ 7 minutes.
Expected results + swing voters:
Expected results