Overview
On this submit, I present the best way to use mlexp to estimate the diploma of freedom parameter of a chi-squared distribution by most probability (ML). One instance is unconditional, and one other instance fashions the parameter as a perform of covariates. I additionally present the best way to generate information from chi-squared distributions and I illustrate the best way to use simulation strategies to grasp an estimation method.
The information
I wish to present how to attract information from a (chi^2) distribution, and I wish to illustrate that the ML estimator produces estimates near the reality, so I take advantage of simulated information.
Within the output under, I draw a (2,000) remark random pattern of knowledge from a (chi^2) distribution with (2) levels of freedom, denoted by (chi^2(2)), and I summarize the outcomes.
Instance 1: Producing (chi^2(2)) information
. drop _all
. set obs 2000
variety of observations (_N) was 0, now 2,000
. set seed 12345
. generate y = rchi2(2)
. summarize y
Variable | Obs Imply Std. Dev. Min Max
-------------+---------------------------------------------------------
y | 2,000 2.030865 1.990052 .0028283 13.88213
The imply and variance of the (chi^2(2)) distribution are (2) and (4), respectively. The pattern imply of (2.03) and the pattern variance of (3.96=1.99^2) are near the true values. I set the random-number seed to (12345) in an effort to replicate my instance; sort assist seed for particulars.
mlexp and the log-likelihood perform
The log-likelihood perform for the ML estimator for the diploma of freedom parameter (d) of a (chi^2(d)) distribution is
[
{mathcal L}(d) = sum_{i=1}^N ln[f(y_i,d)]
]
the place (f(y_i,d)) is the density perform for the (chi^2(d)) distribution. See Trivedi, 2005 and Wooldridge, 2010 for directions to ML.
The mlexp command estimates parameters by maximizing the required log-likelihood perform. You specify the contribution of an remark to the log-likelihood perform inside parentheses, and also you enclose parameters contained in the curly braces ({) and (}). I take advantage of mlexp to estimate (d) in instance 2.
Instance 2: Utilizing mlexp to estimate (d)
. mlexp ( ln(chi2den({d},y)) )
preliminary: log probability = - (couldn't be evaluated)
possible: log probability = -5168.1594
rescale: log probability = -3417.1592
Iteration 0: log probability = -3417.1592
Iteration 1: log probability = -3416.7063
Iteration 2: log probability = -3416.7063
Most probability estimation
Log probability = -3416.7063 Variety of obs = 2,000
------------------------------------------------------------------------------
| Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
/d | 2.033457 .0352936 57.62 0.000 1.964283 2.102631
------------------------------------------------------------------------------
The estimate of (d) may be very near the true worth of (2.0), as anticipated.
Modeling the diploma of freedom as a perform of a covariate
When utilizing ML in utilized analysis, we virtually at all times wish to mannequin the parameters of a distribution as a perform of covariates. Beneath, I draw a covariate (x) from Uniform(0,3) distribution, specify that (d=1+x), and draw (y) from a (chi^2(d)) distribution conditional on (x). Having drawn information from the DGP, I estimate the parameters utilizing mlexp.
Instance 3: Utilizing mlexp to estimate (d=a+b x_i)
. drop _all
. set obs 2000
variety of observations (_N) was 0, now 2,000
. set seed 12345
. generate x = runiform(0,3)
. generate d = 1 + x
. generate y = rchi2(d)
. mlexp ( ln(chi2den({b}*x +{a},y)) )
preliminary: log probability = - (couldn't be evaluated)
possible: log probability = -4260.0685
rescale: log probability = -3597.6271
rescale eq: log probability = -3597.6271
Iteration 0: log probability = -3597.6271
Iteration 1: log probability = -3596.5383
Iteration 2: log probability = -3596.538
Most probability estimation
Log probability = -3596.538 Variety of obs = 2,000
------------------------------------------------------------------------------
| Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
/b | 1.061621 .0430846 24.64 0.000 .9771766 1.146065
/a | .9524136 .0545551 17.46 0.000 .8454876 1.05934
------------------------------------------------------------------------------
The estimates of (1.06) and (0.95) are near their true values.
mlexp makes this course of simpler by forming a linear mixture of variables that you simply specify.
Instance 4: A linear mixture in mlexp
. mlexp ( ln(chi2den({xb: x _cons},y)) )
preliminary: log probability = - (couldn't be evaluated)
possible: log probability = -5916.7648
rescale: log probability = -3916.6106
Iteration 0: log probability = -3916.6106
Iteration 1: log probability = -3621.2905
Iteration 2: log probability = -3596.5845
Iteration 3: log probability = -3596.538
Iteration 4: log probability = -3596.538
Most probability estimation
Log probability = -3596.538 Variety of obs = 2,000
------------------------------------------------------------------------------
| Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
x | 1.061621 .0430846 24.64 0.000 .9771766 1.146065
_cons | .9524138 .0545551 17.46 0.000 .8454878 1.05934
------------------------------------------------------------------------------
The estimates are the identical as in instance 3, however the command was simpler to put in writing and the output is less complicated to learn.
Carried out and undone
I’ve proven the best way to generate information from a (chi^2(d)) distribution when (d) is a set quantity or a linear perform of a covariate and the best way to estimate (d) or the parameters of the mannequin for (d) by utilizing mlexp.
The examples mentioned above present the best way to use mlexp and illustrate an instance of conditional most probability estimation.
mlexp can do rather more than I’ve mentioned right here; see [R] mlexp for extra particulars. Estimating the parameters of a conditional distribution is barely the start of any analysis mission. I’ll talk about deciphering these parameters in a future submit.
References
Cameron, A. C., and P. Ok. Trivedi. 2005. Microeconometrics: Strategies and functions. Cambridge: Cambridge College Press.
Wooldridge, J. M. 2010. Econometric Evaluation of Cross Part and Panel Information. 2nd ed. Cambridge, Massachusetts: MIT Press.
