Calculates the log-likelihood of \(X\) following a normal distribution.

normll(mu, sigma, x, neg = TRUE)

Arguments

mu

Numeric. Location parameter mean \(\mu\).

sigma

Numeric. Positive number. Scale parameter standard deviation \(\sigma = \sqrt{\sigma^2}\).

x

Numeric vector. Values of the random variable \(X\).

neg

Logical. If TRUE, returns, negative log-likelihood.

Details

The natural log of the likelihood function for the normal (or Gaussian or Gauss or Laplace–Gauss) distribution is given by $$ \ln \mathcal{L} \left( \mu, \sigma^2 \mid x \right) = \mathcal{l} \left( \mu, \sigma^2 \mid x \right) \\ \mathcal{l} \left( \mu, \sigma^2 \mid x \right) = \ln \left\{ \left( \frac{1}{\sqrt{2 \pi \sigma^2}} \right)^n \exp \left[ - \frac{1}{2 \sigma^2} \sum_{i = 1}^{n} \left( x_i - \mu \right)^2 \right] \right\} \\ = - \frac{n}{2} \ln 2 \pi \sigma^2 - \frac{1}{2 \sigma^2} \sum_{i = 1}^{n} \left( x_i - \mu \right)^2 . %(\#eq:dist-normll) $$ with independent and identically distributed sample data \(x \in \mathbf{R}\), \(\mu\) is the location parameter mean being estimated \(\left( \mu \in \mathbf{R} \right)\), and \(\sigma^2\) is the scale parameter variance being estimated \(\left( \sigma^2 > 0 \right)\).

The negative log-likelihood is given by $$ - \mathcal{l} \left( \mu, \sigma^2 \mid x \right) = - \left[ - \frac{n}{2} \ln 2 \pi \sigma^2 - \frac{1}{2 \sigma^2} \sum_{i = 1}^{n} \left( x_i - \mu \right)^2 \right] \\ = \frac{n}{2} \ln 2 \pi \sigma^2 + \frac{1}{2 \sigma^2} \sum_{i = 1}^{n} \left( x_i - \mu \right)^2 . %(\#eq:dist-normnegll) $$

References

Wikipedia: Normal Distribution

Wikipedia: IID

Wikipedia: Likelihood Function

See also

Other normal likelihood functions: norm2ll(), normL(), normobj(), normpdf()