{"id":46,"date":"2015-01-06T19:56:00","date_gmt":"2015-01-06T19:56:00","guid":{"rendered":"http:\/\/blog.rickstafford.com\/?p=46"},"modified":"2015-01-06T19:56:00","modified_gmt":"2015-01-06T19:56:00","slug":"elections-again-bayesian-belief-networks-and-combining-data-types","status":"publish","type":"post","link":"http:\/\/blog.rickstafford.com\/?p=46","title":{"rendered":"Elections again &#8211; Bayesian belief networks and combining data types"},"content":{"rendered":"<p>One method of how to combine different types of data \u2013 especially qualitative and quantitative, is to convert both types into belief about a given event. The previous blog posts have demonstrated how to do this using different types of quantitative data \u2013 essentially they involve working out an actual percentage of a given event occurring, given some data which doesn\u2019t directly lend itself to doing this. <\/p>\n<p>However, converting qualitative data into beliefs (or probabilities between 1 and 0 of an event occurring) is actually easier. Essentially it is just educated guess work. An easy example \u2013 expert opinion on who will win the most votes in the general election is largely  &#8211; It is too close to call. A justification of that can be found in this paragraph from the Observer newspaper (see here for full article &#8211; <a href=\"http:\/\/www.theguardian.com\/politics\/2014\/dec\/27\/2015-general-election-unpredictable-green-party-ukip\">http:\/\/www.theguardian.com\/politics\/2014\/dec\/27\/2015-general-election-unpredictable-green-party-ukip<\/a>:<\/p>\n<p>\u201cPolitical pundits are hedging their bets as never before. Their crystal balls reveal only a thick fog of uncertainty. They can agree on one thing \u2013 that it is impossible to say who will be prime minister after the election in five months\u2019 time. \u201cThe 2015 election is the most unpredictable in living memory,\u201d says Robert Ford, co-author of a book about the rise of Ukip, Revolt on the Right. \u201cPast elections have been close but none has featured as many new and uncertain factors with the capacity to exert a decisive impact on the outcome.\u201d\u201d<\/p>\n<p>So, in answer to the question \u2013 will the Conservatives get the most votes \u2013 the belief is simple \u2013 0.5, or I have no idea\u2026 there\u2019s a 50:50 chance\u2026<\/p>\n<p>It\u2019s easy enough to combine this (possibly not insightful, but at least honest) expert opinion with our predictions from yesterday\u2019s opinion poll analysis using a Bayesian belief network (BBN). The following diagram (and parameterised belief network) was made in the free JavaBayes software, available here: <a href=\"http:\/\/www.cs.cmu.edu\/~javabayes\/Home\/\">http:\/\/www.cs.cmu.edu\/~javabayes\/Home\/<\/a><\/p>\n<p>You can download the code for the network (in XML format) here<br \/>\n<a href=\"http:\/\/www.rickstafford.com\/software\/basic_network.xml\">http:\/\/www.rickstafford.com\/software\/basic_network.xml<\/a><\/p>\n<p><a href=\"http:\/\/blog.rickstafford.com\/wp-content\/uploads\/2015\/01\/Network.jpg\"><img loading=\"lazy\" src=\"http:\/\/blog.rickstafford.com\/wp-content\/uploads\/2015\/01\/Network.jpg\" alt=\"Network\" width=\"677\" height=\"572\" class=\"alignnone size-full wp-image-49\" srcset=\"http:\/\/blog.rickstafford.com\/wp-content\/uploads\/2015\/01\/Network.jpg 677w, http:\/\/blog.rickstafford.com\/wp-content\/uploads\/2015\/01\/Network-300x253.jpg 300w\" sizes=\"(max-width: 677px) 100vw, 677px\" \/><\/a><\/p>\n<p>It\u2019s not as scary as it all looks, essentially a BBN is just a way of formalising combining probabilities, although it does use the standard Bayesian equation to do so. However, the \u2018Beliefs\u2019 from yesterday\u2019s opinion poll analysis are combined with the \u2018expert\u2019 opinion (the 50:50 split) to give an overall probability of each party winning the most votes. The final node then tells us the probability of Labour or the Conservatives having the most votes (in this case, they do add to one, as no other party is thought to be able to actually get the highest number of votes).<\/p>\n<p>There are some simple functions to include here \u2013 for example, how do we weight the different types of evidence? The function is simple enough to complete, and looks like this:<\/p>\n<p><a href=\"http:\/\/blog.rickstafford.com\/wp-content\/uploads\/2015\/01\/Function.jpg\"><img loading=\"lazy\" src=\"http:\/\/blog.rickstafford.com\/wp-content\/uploads\/2015\/01\/Function.jpg\" alt=\"Function\" width=\"245\" height=\"224\" class=\"alignnone size-full wp-image-47\" \/><\/a><\/p>\n<p>What it means is, given that the opinion poll data AND expert opinion both indicate labour is definitely winning (i.e. have values of 1) then the probability of labour winning in reality (given the election is a long time away) will be 90%. In practice, the input values (or priors, if you like) are not 1, but are 0.97 and 0.5 respectively. Combining these gives a probability of labour getting the most votes of 69%. Such an approach seems realistic \u2013 if expert opinion was absolutely certain that Labour would win, and they were even higher in the opinion polls, then even with 4 months to the election, it would seem right that we would be 90% sure of the final result. Incidentally, the odds of the Conservatives getting the most votes is 0.312 (essentially through the same parameter set) \u2013 at this point they add up to 1, but this isn\u2019t essential at this point, as there is a final node to consider.<\/p>\n<p>The final node in the BBN provides the result \u2013 the function for working this out looks like this:<\/p>\n<p><a href=\"http:\/\/blog.rickstafford.com\/wp-content\/uploads\/2015\/01\/Function2.jpg\"><img loading=\"lazy\" src=\"http:\/\/blog.rickstafford.com\/wp-content\/uploads\/2015\/01\/Function2.jpg\" alt=\"Function2\" width=\"270\" height=\"221\" class=\"alignnone size-full wp-image-48\" \/><\/a><\/p>\n<p>Essentially, if the node has data from the two feeding nodes that Labour win (with probability 1) and Conservatives lose (with probability 0 of winning) then it calls a Labour win. If the two nodes disagree, then it doesn\u2019t know what to make of it. The final node here gives the following outcome:<br \/>\nLabour 69%, Conservatives 31% &#8211; identical to before, but this is because both sides of the network are in agreement. If they weren\u2019t, then we\u2019d get a different result here. <\/p>\n<p>As you can see, we\u2019ve now combined two types of data to get a better prediction of the current state of knowledge (based on data on or before 4th Jan) as to who will win the election. Why is this a better prediction? Because the opinion poll alone is a snapshot in time, and very likely to change once campaign starts. The expert opinion recognises this and moderates the results. <\/p>\n<p>Next I\u2019ll look at how to combine semi-opinion, semi-quantitative data together. The election story becomes a bit more complicated, as experts haven\u2019t stopped at the \u2018I don\u2019t know\u2019 stage, but have taken a more in depth analysis \u2013 and obviously football pundits have a lot to say\u2026<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One method of how to combine different types of data \u2013 especially qualitative and quantitative, is to convert both types into belief about a given event. The previous blog posts have demonstrated how to do this using different types of &hellip; <a href=\"http:\/\/blog.rickstafford.com\/?p=46\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/blog.rickstafford.com\/index.php?rest_route=\/wp\/v2\/posts\/46"}],"collection":[{"href":"http:\/\/blog.rickstafford.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.rickstafford.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.rickstafford.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.rickstafford.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=46"}],"version-history":[{"count":2,"href":"http:\/\/blog.rickstafford.com\/index.php?rest_route=\/wp\/v2\/posts\/46\/revisions"}],"predecessor-version":[{"id":51,"href":"http:\/\/blog.rickstafford.com\/index.php?rest_route=\/wp\/v2\/posts\/46\/revisions\/51"}],"wp:attachment":[{"href":"http:\/\/blog.rickstafford.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=46"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.rickstafford.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=46"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.rickstafford.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=46"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}