French Election data.
Load packages
library("rprojroot")
root<-has_file(".ROS-Examples-root")$make_fix_file()
Load data
ps <- read.table(root("FrenchElection/data","ps_primaire.txt"), header=TRUE)
Analyze
J <- nrow(ps)
n1 <- ps[J,2]
n2 <- ps[J,3] - ps[J,2]
p1 <- ps[1:(J-1),2]/n1
p2 <- (ps[1:(J-1),3] - ps[1:(J-1),2])/n2
diff <- p2 - p1
se_diff <- sqrt(p1*(1-p1)/n1 + p2*(1-p2)/n2)
round(cbind(diff, se_diff)*10000)
diff se_diff
[1,] 2 9
[2,] 1 9
[3,] -1 7
[4,] 0 5
[5,] -2 4
[6,] -2 3
[7,] 0 2
[8,] 0 2
print(cbind(p1*n2, p2*n2))
[,1] [,2]
[1,] 127893.610 127973
[2,] 109461.129 109511
[3,] 61655.209 61634
[4,] 24104.642 24103
[5,] 13667.325 13603
[6,] 6945.348 6885
[7,] 3551.685 3563
[8,] 4573.051 4580
LS0tCnRpdGxlOiAiUmVncmVzc2lvbiBhbmQgT3RoZXIgU3RvcmllczogRnJlbmNoIEVsZWN0aW9uIgphdXRob3I6ICJBbmRyZXcgR2VsbWFuLCBBa2kgVmVodGFyaSIKZGF0ZTogImByIGZvcm1hdChTeXMuRGF0ZSgpKWAiCm91dHB1dDoKICBodG1sX2RvY3VtZW50OgogICAgdGhlbWU6IHJlYWRhYmxlCiAgICB0b2M6IHRydWUKICAgIHRvY19kZXB0aDogMgogICAgdG9jX2Zsb2F0OiB0cnVlCiAgICBjb2RlX2Rvd25sb2FkOiB0cnVlCi0tLQpGcmVuY2ggRWxlY3Rpb24gZGF0YS4KCi0tLS0tLS0tLS0tLS0KCgpgYGB7ciBzZXR1cCwgaW5jbHVkZT1GQUxTRX0Ka25pdHI6Om9wdHNfY2h1bmskc2V0KG1lc3NhZ2U9RkFMU0UsIGVycm9yPUZBTFNFLCB3YXJuaW5nPUZBTFNFLCBjb21tZW50PU5BKQpgYGAKCiMjIyMgTG9hZCBwYWNrYWdlcwoKYGBge3IgfQpsaWJ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