Hello. I am new to Stan and I try to solve simple inference problem.
I would like to solve a simple one before applying Stan to making inference in more complex models.
About the problem. The task is to estimate posterior destibution for variables given some observed values.
Given:
a ~ normal(mu=1, std =1);
b ~ normal(mu=2, std = 1.5);
In our single observation we get information that a+b = sumValue. Let’s fix it at 4.
What is pdf for a variable now? I mean pdf(a | a+b==sumValue).
I have solved this problem with Matlab and Infer.Net library, but I can’t reproduce it with Stan.
I have read the manual, and especially part 20. on Problematic Posteriors, on and some threads ( https://groups.google.com/forum/#!topic/stan-users/rKxrs2gsPr4.) on Forum. But I still can’t understand if Stan is suitable for this inference task.
The problem can be easily solved analytically:
pdfOf(a | a+b== sumValue)By(x) = pdfA(x).*pdfB(2-sumValue-x) / k, where k = Integral(pdfA(x).*pdfB(sumValue-x)).
See matlab
code for this:
x = [-2:0.01:8];
pdfA = @(x)normpdf(x, 1, 1);
pdfB = @(x)normpdf(x, 2, 1.5);
sumValue = 4;
pdfA_condNoAdj = @(x)pdfA(x).*pdfB(sumValue-x);
pdfA_condTotal = integral(pdfA_condNoAdj ,-10,10);
pdfA_cond = @(x)pdfA_condNoAdj(x)/pdfA_condTotal;
figure(1);clf
hold on;
plot(x, pdfA(x));
plot(x, pdfB(x));
plot(x, pdfA_cond(x));
hold off;
grid on;
legend('pdfA','pdfB','pdfA cond');
So we see that posterior distribution for A is easily calculated.
Now let’s try to that in infer.net
static void Main(string[] args)
{
Variable<double> a = Variable.GaussianFromMeanAndVariance(1, 1).Named("a");
Variable<double> b = Variable.GaussianFromMeanAndVariance(2, 1.5).Named("b");
Variable<double> c;
c = a + b;
c.ObservedValue = 4;
InferenceEngine engine = new InferenceEngine();
engine.Algorithm = new ExpectationPropagation();
Console.WriteLine("Dist over x=" + engine.Infer(a));
Console.ReadKey();
}
The engine makes inference that is close to Matlab’s version, but not identical. Posterior PdfA is normal with mu=1.4, std = 0.6.
How can I get posterior distribution for a in Stan?
I try to do something like following:
data { real cInput; // s.e. of effect estimates }
parameters { real a; real b; }
model {
a ~ normal(0,1);
b ~ normal(0,1);
cInput<-a + b;
}
And I would NOT like use model where C = a+b + noise, because it would change the problem.
Can Stan solve the problem above the way Matlab and Infer.Net did?
How can I infer posterior probability density function?
Is there some way to assign observed value to linear combination (or any function) of parameters?
Regards,
Nikolay
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/Qhw0A2gr67g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.