# Marginal likelihood code

**URL:** <https://forum.dynare.org/t/marginal-likelihood-code/3750>\
**Category:** ML/Bayesian estimation\
**Created:** [7 March 2014 09:00 UTC](https://forum.dynare.org/t/marginal-likelihood-code/3750 "2014-03-07T09:00:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![yaliallen](https://forum.dynare.org/letter_avatar_proxy/v4/letter/y/b38774/32.png) [@yaliallen](https://forum.dynare.org/u/yaliallen)\
**Post date:** [7 March 2014 09:00 UTC](https://forum.dynare.org/t/marginal-likelihood-code/3750/1 "2014-03-07T09:00:39Z")

</div>

I know it is a stupid question…but I really can not find the marginal data density code in manual or user guide.is it in the “estimate”?I don not think it works when I code “marginal\_density()” after "estimate"command. 😊  
I will be really grateful if someone can give a example.  
btw,Is it the same as marginal likelihood?I believe many people had compared two models by this index,really need a help!  
yaliallen

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [8 March 2014 11:29 UTC](https://forum.dynare.org/t/marginal-likelihood-code/3750/2 "2014-03-08T11:29:07Z")

</div>

The log marginal data density will be computed automatically by the estimation-command if you use Bayesian estimation. As written in the manual, it is stored in oo\_.MarginalDensity.  
Yes, this it the statistic used for model comparison and is also referred to a the marginal likelihood or model evidence.

---

<div class="post-metadata">

**Author:** ![yaliallen](https://forum.dynare.org/letter_avatar_proxy/v4/letter/y/b38774/32.png) [@yaliallen](https://forum.dynare.org/u/yaliallen)\
**Post date:** [18 March 2014 09:51 UTC](https://forum.dynare.org/t/marginal-likelihood-code/3750/3 "2014-03-18T09:51:51Z")

</div>

[quote=“jpfeifer”]The log marginal data density will be computed automatically by the estimation-command if you use Bayesian estimation. As written in the manual, it is stored in oo\_.MarginalDensity.  
Yes, this it the statistic used for model comparison and is also referred to a the marginal likelihood or model evidence.[/quote]

thank you mr pfeifer for helping me. but i cannot find where to see this output. if i should type a additional code “oo\_.MarginalDensity” under estimation? I try this,but it shows:

[quote]??? Reference to non-existent field ‘MarginalDensity’.

Error in ==\> LJWSIGEQZ at 1805  
oo\_.MarginalDensity;

Error in ==\> dynare at 120  
evalin(‘base’,fname) ;[/quote]

or

[quote]Starting Dynare (version 4.3.3).  
Starting preprocessing of the model file …  
ERROR: LJWSIGEQZ.mod:127.69-71: syntax error, unexpected NAME[/quote]

if not,as [[Marginal Data Density](http://forum.dynare.org/t/marginal-data-density/2768/3)) said,I didn’t say the same result with my code. 😮  
really want to know what goes wrong…Thank u!  
attachments is my code and data  
[LJWSIGEQZ.mod](https://forum.dynare.org/uploads/default/original/2X/6/69557c0f82df1de30ec005140113cb11b639a631.mod) (3.08 KB)  
[data07.m](https://forum.dynare.org/uploads/default/original/2X/f/fcaaef6c114143a68a3e6ac2b7861defb2739886.m) (294 Bytes)

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [18 March 2014 11:11 UTC](https://forum.dynare.org/t/marginal-likelihood-code/3750/4 "2014-03-18T11:11:38Z")

</div>

The marginal data density is a Bayesian concept. You are estimating the model with ML and not with Bayesian techniques. That won’t work.

---

<div class="post-metadata">

**Author:** ![sami2028](https://forum.dynare.org/letter_avatar_proxy/v4/letter/s/a88e4f/32.png) [@sami2028](https://forum.dynare.org/u/sami2028)\
**Post date:** [17 January 2026 15:34 UTC](https://forum.dynare.org/t/marginal-likelihood-code/3750/5 "2026-01-17T15:34:49Z")

</div>

> [@jpfeifer](#):
>
> oo\_.MarginalDensity.

where I can find the script. Thank you .

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [18 January 2026 09:17 UTC](https://forum.dynare.org/t/marginal-likelihood-code/3750/6 "2026-01-18T09:17:33Z")

</div>

Which script are you looking for?
