locked
Dirichlet-Multinomial: UK Politics RRS feed

  • Question

  • Adapted from Farrow (2008):

    In a survey 1000 English voters are asked to say for which party they would vote if there were a general election next 
    week. The choices offered were 1: Labour, 2:  Liberal, 3:  Conservative, 4: Other, 5: None, 6: Undecided. We assume that 
    the population is large enough so that the responses may be considered independent given the true underlying proportions. 
    Let θ1, . . . , θ6 be the probabilities that a randomly selected voter would give each of the responses. Our prior 
    distribution for θ1, . . . , θ6  is a Dirichlet(5,  3,  5,  1,  2,  4) distribution. 
    Suppose our observed data are as follows.
    Labour    Liberal    Conservative    Other    None    Undecided
    256           131       266                  38         114       195

    How would I encode these details using a dirichlet-multinomial model in order to answer questions such as what is the 95% 
    credible interval for a conservative-liberal coalition?

    Please advise?

    matekus


    Illiud Latine dici non potest.

    Tuesday, September 3, 2013 5:33 AM

Answers

  • double[] alpha = new double[] { 1.2, 3.4 };
    Range dim = new Range(alpha.Length).Named("dim");
    Variable<Vector> p = Variable.Dirichlet(dim, alpha).Named("p");
    int n = 10;
    VariableArray<int> x = Variable.Multinomial(n, p).Named("x");
    InferenceEngine engine = new InferenceEngine(new VariationalMessagePassing());
    int[] k = new int[] { 3, 7 };
    x.ObservedValue = k;
    Dirichlet pPost = engine.Infer<Dirichlet>(p);
    This should get you started.
    • Marked as answer by _matekus_ Friday, September 6, 2013 12:55 PM
    Friday, September 6, 2013 11:23 AM
    Owner

All replies

  • Infer.NET can be used compute the posterior distribution of theta, although in this simple example you could do it by hand.  It doesn't compute credible intervals though.  You'd have to compute these from the resulting Dirichlet posterior.
    Thursday, September 5, 2013 12:03 PM
    Owner
  • Tom,

    Thanks for the follow-up reply.

    I agree the toy example is readily solved by hand - what I was hoping for was a basic, generic infer.net template for handling dirichlet-multinomial models. While I have successfully implemented a generic beta-binomial model, I am struggling with the dirichlet-multinomial model equivalent. Any guidance would be welcome.

    Best wishes,

    matekus



    Illiud Latine dici non potest.


    • Edited by _matekus_ Thursday, September 5, 2013 5:21 PM Typo.
    Thursday, September 5, 2013 5:20 PM
  • double[] alpha = new double[] { 1.2, 3.4 };
    Range dim = new Range(alpha.Length).Named("dim");
    Variable<Vector> p = Variable.Dirichlet(dim, alpha).Named("p");
    int n = 10;
    VariableArray<int> x = Variable.Multinomial(n, p).Named("x");
    InferenceEngine engine = new InferenceEngine(new VariationalMessagePassing());
    int[] k = new int[] { 3, 7 };
    x.ObservedValue = k;
    Dirichlet pPost = engine.Infer<Dirichlet>(p);
    This should get you started.
    • Marked as answer by _matekus_ Friday, September 6, 2013 12:55 PM
    Friday, September 6, 2013 11:23 AM
    Owner