TransWikia.com

Does MMA have a maximum likelihood estimation function?

Mathematica Asked on February 14, 2021

I want to use MMA to solve question 23 in this post:

enter image description here

enter image description here

The English translation of this question is as follows:

Let the probability density function of population $X$ be $fleft(x, sigma^{2}right)=left{begin{array}{cc}
frac{mathrm{A}}{sigma} e^{-frac{(x-mu)^{2}}{2 sigma^{2}}} & x geq mu
0 & x<mu
end{array}right.$
, where $mu$ is a known parameter, $sigma$ is an unknown parameter, and $sigma>0$, $A$ is constant $sqrt{frac{2}{pi}}$ (I’ve got the value of $A$ in advance). $X1$, $X2$,…,$Xn$ are simple random samples from $X$.

How to use the built-in probability theory function of MMA to calculate the maximum likelihood estimator of $sigma^2$.

2 Answers

This is done with EstimatedDistribution and the ParameterEstimator -> "MaximumLikelihood" option:

data = RandomVariate[NormalDistribution[], 100];
EstimatedDistribution[data, NormalDistribution[0, σ], 
  ParameterEstimator -> "MaximumLikelihood"
]

NormalDistribution[0, 0.918944]

Use ProbabilityDistribution if you need to define a distribution from a custom probability density function.

Correct answer by Sjoerd Smit on February 14, 2021

The density you have is related to a half Normal distribution but that is not essential to know to obtain the maximum likelihood estimates and obtain an estimate of precision for that estimator.

First create a distribution based on the density:

dist = ProbabilityDistribution[(Sqrt[(2/π)]/σ) Exp[-(x - μ)^2/(2 σ^2)], {x, μ, ∞}, 
  Assumptions -> σ > 0]

Take a random sample from that distribution.

SeedRandom[12345];
data = RandomVariate[dist /. {μ -> 4, σ -> 3}, 1000];

Now find the maximum likelihood estimate of $sigma$ (as you say that $mu$ is known.

mle = FindDistributionParameters[data, dist /. μ -> 4]
(* {σ -> 2.93267} *)

To get an estimate of the standard error of the estimator perform the following:

logL = LogLikelihood[dist /. μ -> 4, data];
stdErr = Sqrt[-1/(D[logL, {σ, 2}]) /. mle]
(* 0.0655764 *)

If you did recognize that the distribution was related to a half normal distribution (with $X-mu$ having a half normal distribution with parameter $frac{sqrt{frac{pi }{2}}}{sigma }$), then you could use the following:

FindDistributionParameters[data - μ /. μ -> 4, HalfNormalDistribution[Sqrt[π/2]/σ]]
(* {σ -> 2.93267} *)

You'd still need to use the LogLikelihood function to obtain an estimate of the standard error.

Answered by JimB on February 14, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP