TeachingDemos (version 2.12)

mle.demo: Demonstrate the basic concept of Maximum Likelihood Estimation

Description

This function graphically shows log likelihoods for a set of data and the normal distribution and allows you to interactively change the parameter estimates to see the effect on the log likelihood.

Usage

mle.demo(x = rnorm(10, 10, 2), start.mean = mean(x) - start.sd,
  start.sd = 1.2 * sqrt(var(x)))

Value

This function is run for its side effects and returns NULL.

Arguments

x

A vector of data (presumably from a normal distribution).

start.mean

The initial value for estimating the mean.

start.sd

The initial value for estimating the standard deviation.

Author

Greg Snow 538280@gmail.com

Details

The function creates a plot with 3 panels: the top panel shows a normal curve based on the current values of the mean and standard deviation along with a vertical line for each point in x (the product of the heights of these lines is the likelihood, the sum of the logs of their heights is the log likelihood).

The lower 2 plots show the profiles of the mean and standard deviation. The y-axis is the likelihoods of the parameters tried so far, and the x-axes are the mean and standard deviation tried. The point corresponding to the current parameter estimates will be solid red.

A Tk slider box is also created that allows you to change the current estimates of the mean and standard deviation to show the effect on the log likelihood and find the maximum likelihood estimate.

See Also

fitdistr in package MASS, mle in package stats4, slider

Examples

Run this code

if(interactive()){
mle.demo()

m <- runif(1, 50,100)
s <- runif(1, 1, 10)
x <- rnorm(15, m, s)

mm <- mean(x)
ss <- sqrt(var(x))
ss2 <- sqrt(var(x)*11/12)
mle.demo(x)
# now find the mle from the graph and compare it to mm, ss, ss2, m, and s
}

Run the code above in your browser using DataLab