locked
Neophyte: Simple Bayes Model RRS feed

  • Question

  • How do I generate a simple beta prediction model based on a beta prior (mean=0.33333, variance=0.00132) of 900 trials and an observed value of binomial(true=200, false=300)?

    Please advise?

    matekus


    Illiud Latine dici non potest.
    • Edited by _matekus_ Tuesday, November 29, 2011 5:54 PM
    Tuesday, November 29, 2011 5:23 PM

Answers

  • // The model

    var pPrior = Variable.New<Beta>();

    var p = Variable<double>.Random(pPrior);

    var numTrials = Variable.New<int>();

    var numSuccess = Variable.Binomial(numTrials, p);

     

    // Hook up the observations and learn the posterior on p

    var engine = new InferenceEngine();

    pPrior.ObservedValue = Beta.FromMeanAndVariance(0.33333, 0.00132);

    numTrials.ObservedValue = 500;

    numSuccess.ObservedValue = 200;

    Beta pPost = engine.Infer<Beta>(p);

    Console.WriteLine("Probability of success = {0}", pPost);

    • Marked as answer by _matekus_ Tuesday, November 29, 2011 9:34 PM
    Tuesday, November 29, 2011 8:52 PM
    Owner

All replies

  • // The model

    var pPrior = Variable.New<Beta>();

    var p = Variable<double>.Random(pPrior);

    var numTrials = Variable.New<int>();

    var numSuccess = Variable.Binomial(numTrials, p);

     

    // Hook up the observations and learn the posterior on p

    var engine = new InferenceEngine();

    pPrior.ObservedValue = Beta.FromMeanAndVariance(0.33333, 0.00132);

    numTrials.ObservedValue = 500;

    numSuccess.ObservedValue = 200;

    Beta pPost = engine.Infer<Beta>(p);

    Console.WriteLine("Probability of success = {0}", pPost);

    • Marked as answer by _matekus_ Tuesday, November 29, 2011 9:34 PM
    Tuesday, November 29, 2011 8:52 PM
    Owner
  • John,

    Thanks for the benefit of your expertise.

    matekus


    Illiud Latine dici non potest.
    Tuesday, November 29, 2011 9:35 PM