Published
Edited
Jun 15, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import {sondages, desc as descNspPolls} from '@taniki/regionales2021-donnees-nsppolls'
Insert cell
Insert cell
confiance = 0.95
Insert cell
Inputs.table(t1Hypothese.tetes_liste)
Insert cell
liste = t1Hypothese.tetes_liste[1]
Insert cell
Z = jStat.normal.inv((1+confiance)/2, 0, 1)
Insert cell
${ t1Hypothese
.tetes_liste
.slice()
.sort((a,b) => b.intentions - a.intentions)
.map(liste => t1ListGraph(liste, t1Hypothese.sous_echantillon))
}
Insert cell
t1ListGraph = (liste, n) => {
let N = listN(liste.intentions/100, n)
let ic = [N.inv(0.025), N.inv(1-(1-confiance)/2)] // pour vérification
//return [p, s, ic]
return Plot.plot({
caption: `densité de probabilité d'intention de vote pour la liste de ${liste.tete_liste} (${liste.parti})`,
height: 200,
x: {
domain: [0, 50]
},
y:{
domain: [0,50]
},
marks: [
Plot.ruleX([5], { stroke: 'red'}),
Plot.ruleX([10], { stroke: 'green'}),
Plot.areaY(d3.range(0, 5, 0.1), { x: d => d, y: d => N.pdf(d/100), fill: 'red' }),
Plot.areaY(d3.range(5, 10, 0.1), { x: d => d, y: d => N.pdf(d/100), fill: '#999' }),
Plot.areaY(d3.range(10,100, 0.1), { x: d => d, y: d => N.pdf(d/100), fill: 'green'})
]
})
}
Insert cell
t1ListRidgeline(t1Hypothese, 'premier tour')
Insert cell
t1ListRidgeline = (hypothese, tour, row = 25) => {
let yStep = 15
return Plot.plot({
caption: html`
densité de probabilité d'intentions de vote au ${ tour } des élections régionales 2021<br>
données : <a href="https://twitter.com/nsppolls">NspPolls</a> · <a href="${ sondage.lien }">${ sondage.nom_institut }</a>`,
height: hypothese.tetes_liste.length * row,
marginLeft: 150,
x: {
domain: [0, 50],
label: 'intentions de vote (%)',
grid: true,
ticks: 10,
},
y:{
axis: false,
domain: [0, hypothese.tetes_liste.length * row]
},
marks: [
Plot.ruleX([5], { stroke: 'red', strokeOpacity: 0.3}),
Plot.ruleX([10], { stroke: 'green', strokeOpacity: 0.3}),
hypothese.tetes_liste.slice().sort((a,b)=>b.intentions - a.intentions).map((liste,i) => {
let N = listN(liste.intentions/100, hypothese.sous_echantillon)
let y0 = i*yStep
return [
Plot.area(d3.range(0, 5, 0.1), { x1: d => d, x2: d => d, y1: d => y0, y2: d => y0+N.pdf(d/100), fill: 'red', fillOpacity: 0.5 }),
Plot.area(d3.range(5, 10, 0.1), { x1: d => d, x2: d => d, y1: d => y0, y2: d => y0+N.pdf(d/100), fill: '#999', fillOpacity: 0.5 }),
Plot.area(d3.range(10,100, 0.1), { x1: d => d, x2: d => d, y1: d => y0, y2: d => y0+N.pdf(d/100), fill: 'green', fillOpacity: 0.5}),
Plot.text([[i, liste.tete_liste]], {
text: d => d[1],
textAnchor: 'end',
dy: 0,
y: d => y0,
x: d => N.inv(0.001) * 100
})
]
})

]
})
}
Insert cell
listN = (p,n) => {
//let p = liste.intentions / 100
let s = p * (1-p) / n
let N = jStat.normal(p, Math.sqrt(s,2))
let ic = [N.inv(0.025), N.inv(1-(1-confiance)/2)] // pour vérification

return N
}
Insert cell
import { eDiff } from '@taniki/regionales2021-ecarts-checker'
Insert cell
jStat = require('jStat')
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more