anm.loglik {asbio}R Documentation

Animated plots of log-likelihood functions


Plots the normal, exponential, Poisson, binomial, and "custom" log-likelihood functions. By definition, likelihoods for parameter estimates are calculated by holding data constant and varying estimates. For the normal distribution a fixed value for the parameter which is not being estimated (μ or σ^2) is established using MLEs.


anm.loglik(X, dist = c("norm", "poi", "bin", "exp", "custom"), 
plot.likfunc = TRUE, parameter = NULL, func = NULL, poss = NULL, 
plot.density = TRUE, plot.calc = FALSE, xlab = NULL, ylab = NULL, 
conv = diff(range(X))/70, anim = TRUE, est.col = 2, density.leg = TRUE, 
cex.leg = 0.9, interval = 0.01, ...)

loglik.norm.plot(X, parameter = c("mu", "sigma.sq"), poss = NULL, 
plot.likfunc = TRUE, plot.density = TRUE, plot.calc = FALSE, 
xlab = NULL, ylab = NULL, conv = 0.01, anim = TRUE, est.col = 2, 
density.leg = TRUE, cex.leg = 0.9, interval = 0.01, ...)

loglik.pois.plot(X, poss = NULL, plot.likfunc = TRUE, 
plot.density = TRUE, plot.calc = FALSE, xlab = NULL, ylab = NULL, 
conv = 0.01, anim = TRUE, interval = 0.01, ...)

loglik.binom.plot(X, poss = NULL, xlab = NULL, ylab = NULL, 
plot.likfunc = TRUE, plot.density = TRUE, conv = 0.01, anim = TRUE, 
interval = 0.01, ...)

loglik.exp.plot(X, poss = NULL, plot.likfunc = TRUE, 
plot.density = TRUE, plot.calc = FALSE, xlab = NULL, ylab = NULL, 
conv = 0.01, anim = TRUE, est.col = 2, density.leg = TRUE, 
cex.leg = 0.9, interval = 0.01, ...)

loglik.custom.plot(X, func, poss, anim = TRUE, interval = 0.01, 
xlab, ylab, ...)




A vector of quantitative data. The function does not currently handle extremely large datasets, n > 500. Data should be integers (counts) for the Poisson log-likelihood function, and binary responses (0,1) for the binomial log likelihood function. Data elements for the exponential log likelihood function must be greater than zero.


The parameter for which ML estimation is desired in loglik.norm.plot. Specification of either "mu" or "sigma.sq" is required for the normal log-likelihood function. No specification is required for exponential, Poisson, and binomial log-likelihood functions since these distributions are generally specified with a single parameter, i.e., θ for the exponential, λ for the Poisson distribution, and p (the probability of a success) for the binomial distribution.


An optional vector containing a sequence of possible parameter estimates. Elements in the vector must be distinct. If poss is not specified a vector of appropriate possibilities is provided by the function. This argument can be used to set xlim in the likelihood function and density plots.


The type of assumed distribution there are currently five possibilities: "norm", "poi", "binom", "exp", and "custom". Use of custom distributions requires specification of a custom likelihood function in the argument func.


A logical command for indicating whether a graph of the log-likelihood function should be created.


A logical command for indicating whether a second graph, in which densities are plotted on the pdf, should be created.


A logical command for indicating whether a third graph, in which log-densities are added to one another, should be created.


Optional X-axis label.


Optional Y-axis label.


Precision of likelihood function. Decreasing conv increases the smoothness and precision of the ML function. Decreasing conv will also slow the animation.


A logical command indicating whether animation should be used in plots.


Color used in depicting estimation.


Logical. Should the legend for density be shown?


Character expansion for legend.


Speed of animation, in seconds per frame. May not work in all systems; see Sys.sleep.


Custom likelihood function to be specified when using loglik.custom.plot. The function should have two arguments. An optional call to data, and the likelihood function parameter (see example below).


Additional arguments from plot can be specified for likelihood function plots.


These plots are helpful in explaining the workings of ML estimation for parameters. Animation is included as an option to further clarify processes. When specifying poss be sure to include the estimate that you "want" the log-likelihood function to maximize in the vector of possibilities, e.g. mean(X) for estimation of μ.


Three animated plots can be created simultaneously. The first plot shows the normal, Poisson, exponential, binomial, or custom log-likelihood functions. The second plot shows the pdf with ML estimates for parameters. On this graph densities of observations are plotted as pdf parameters are varied. By default these two graphs will be created simultaneously on a single graphics device. By specifying plot.calc = TRUE a third plot can also be created which shows that log-likelihood is the sum of the log-densities. Animation in this third plot will be automatically sped up, using a primitive routine, for large datasets, and slowed for small datasets. The third plot will not be created for the binomial pdf because there will only be a single outcome from the perspective of likelihood (e.g. 10 successes out of 22 trials). The second and third plots will not be created for custom likelihood functions. Loading package tcltk allows use of the function anm.loglik.tck which provides an interactive GUI to run anm.loglik.


Ken Aho

See Also

dnorm, dpois, dexp, dbinom


## Not run: 
##Normal log likelihood estimation of mu.

##Add a plot describing log-likelihood calculation.

##Normal log likelihood estimation of sigma squared.

##Exponential log likelihood estimation of theta

##Poisson log likelihood estimation of lambda.

##Binomial log likelihood estimation of p.
X<-c(1,1,0,0,0,1,0,0,0,0)#where 1 = a success

##Custom log-likelihood function

##Interactive GUI, requires package 'tcltk'

## End(Not run)

[Package asbio version 1.7 Index]