Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Likelihood function of uniform distribution


From   "Stas Kolenikov" <[email protected]>
To   [email protected]
Subject   Re: st: Likelihood function of uniform distribution
Date   Tue, 1 Apr 2008 15:53:33 -0500

On 4/1/08, Bob Hammond <[email protected]> wrote:
>     program myunif
>     args lnf theta
>     quietly replace `lnf' =ln(`theta') if $ML_y1==1
>     quietly replace `lnf' =ln(1-`theta') if $ML_y1==0
>     end

what this does is

f(x|theta) = theta^y (1-theta)^{1-y)

that is, the binomial/Bernoulli likelihood.

What you need is

program myunif
    args lnf theta
    quietly replace `lnf' = 0 if $ML_y1>0 & $ML_y1 <1
    quietly replace `lnf' = . if $ML_y1<=0 & $ML_y1 >=1
end

Note that theta is not used. Which is proper since there are no
parameters to estimate, you know everything in perfection already.

As for the triangular distribution (again, nothing to estimate):

>  Also, how do you define the following triangular probability
>  distribution function?
>
>  f(x)= 4x if 0<x<0.5
>  =4-4x if 0.5<x<1
>  =0 otherwise.

prog def mytriang
  args lnf theta
  qui replace `lnf' = ln(4*$ML_y1) if $ML_y1 >0 & $ML_y1 < 0.5
  qui replace `lnf' = ln(4*(1-$ML_y1)) if $ML_y1 >=0.5 & $ML_y1 <=1
  qui replace `lnf' = . if $ML_y1 < 0 & $ML_y1 >1
end

Since the likelihood does not change with theta, either function will
fail -ml check-. You really need to estimate something. Stata's
optimizer does not handle non-smooth densities like those of uniform
or triangular very graciously; you'll see a lot of error messages
(derivatives cannot be computed) when it has to work near the boundary
of the support.

-- 
Stas Kolenikov, also found at http://stas.kolenikov.name
Small print: Please do not reply to my Gmail address as I don't check
it regularly.
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index