mle.demo | R Documentation |
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.
mle.demo(x = rnorm(10, 10, 2), start.mean = mean(x) - start.sd,
start.sd = 1.2 * sqrt(var(x)))
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. |
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.
This function is run for its side effects and returns NULL.
Greg Snow 538280@gmail.com
fitdistr
in package MASS, mle
in
package stats4, slider
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
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.