Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Fitting a stretched exponential model by Maximum likelihood

    Dear Statalisters,

    I would very much appreciate help regarding the following problem:


    I want use ml to fit a stretched exponential function to different datasets:

    y = exp(b0 * x(b1 - 1) + b2)


    b0, b1 and b2 denote the parameters of the function, while "x" and "y" are variables.

    I already tried to use the nl-command to fit the function:

    Code:
    nl (y = exp({b0}*chars^({b1}-1)+{b2}))

    In many cases, however, there are convergence issues and other problems. That's why I want to try using ml.
    I have already used the ml-command, but I am not very familiar with it.

    I first would like to define a program to calculate the log likelihood

    Code:
    program define stretched
        args lnf x
    qui replace `lnf' = /* fill in likelihood function here */
    end

    Using this program,I would try to fit the model like this
    Code:
    ml model lf stretchedexp (x=y)
    ml maximize

    As you can see in the program above, I don't know the likelihood function of this particular stretched exponential function... unfortunately, my "statistical" skills are not sufficient in this area...

    So if anyone can tell me the likelihood or has any tips, please let me know, I would be very grateful.

    Many thanks

    Ali


    Last edited by Alexander Koplenig; 12 Sep 2017, 07:25.

  • #2
    With the help of https://www.stata.com/support/faqs/s...dels-using-ml/, I managed to fill in the log-likelihood in the code above.

    Code:
    capture program drop mlstretched
    program mlstretched
        version 14
        args lnf x b0 b1 b2 sigma
        tempvar res
        quietly gen double `res' = $ML_y1 - exp(`b0'*`x'^(`b1'-1)+`b2')
        quietly replace `lnf' = -0.5*ln(2*_pi)-ln(`sigma')-0.5*`res'^2/`sigma'^2
    end
    I tried to follow the FAQ description as closely as possible. However, ml does not converge, as the following test demonstrates:

    Code:
    /* Generate some test data */
    clear
    set obs 100
    gen n=_n
    
    gen rate=exp(2*n^(.6-1)+1.5)
    
    /*Estimate the model */
    
    ml model lf mlstretched (x: rate = n, nocons) (b1: rate = n, nocons) (b0: rate = n) (b2:) (sigma:)
    ml max
    I believe that there must be some error in my model specification...

    If anyone has any tips, please let me know, thank you very much.

    Ali

    Comment

    Working...
    X