Hi all
I have a column vector (let call that X) that contains rows(X) i.i.d variables with Geometric distribution in Stata. I try to use optimize to find the parameter (let call that p) that maximizes the likelihood function of the sample.
Here is my codes:
I know in advance that the sample was created with p = 0.3 (I checked the mean and variance of the sample, and it surely was created by Geometric distribution with the chance of success is 0.3). What surprised me are: first, the
returns the true parameter for p is 0.5 (which is the initial value set for p and it is wrong). Second, the column vector x, which is a view on X, contains no value despite the fact that X has not changed. I know this is the setup of g-type optimization, but I want to learn whether d-type could work with extra parameter like the g-type.
Can anyone help me to explain this.
Thank you
I have a column vector (let call that X) that contains rows(X) i.i.d variables with Geometric distribution in Stata. I try to use optimize to find the parameter (let call that p) that maximizes the likelihood function of the sample.
Here is my codes:
Code:
mata mata clear
mata:
x = st_view(x=0,.,"X",0)
void MLE_geo_dtype(todo,p,x,ll,g,H)
{
ll = rows(x)*ln(p)+(sum(x)-rows(x))*ln(1-p)
if (todo>=1) {
g = rows(x)/p-(sum(x)-rows(x))/(1-p)
if (todo==2) {
H = (-rows(x)/p^2)-(sum(x)-rows(x))/((1-p)^2)
}
}
}
S = optimize_init()
optimize_init_evaluator(S, &MLE_geo_dtype())
optimize_init_evaluatortype(S,"d2")
optimize_init_params(S,0.5)
optimize_init_argument(S,1,x)
p = optimize(S)
end
Code:
p=optimize(S)
Can anyone help me to explain this.
Thank you

Comment