Learn R Programming

maxLik (version 0.7-2)

maxLik: Maximum likelihood estimation

Description

This is just a wrapper for maximisation routines which return object of class "maxLik". Corresponding methods can correctly handle the likelihood-specific properties of the estimate including the fact that inverse of negative hessian is the variance-covariance matrix.

Usage

maxLik(logLik, grad = NULL, hess = NULL, start, method,
constraints=NULL, ...)

Arguments

logLik
log-likelihood function. Must have the parameter vector as the first argument. Must return either a single log-likelihood value or a numeric vector where each component is log-likelihood corresponding to individual observations.
grad
gradient of log-likelihood. Must have the parameter vector as the first argument. Must return either single gradient vector with length equal to the number of parameters, or a matrix where each row corresponds to gradient vector of individua
hess
hessian of log-likelihood. Must have the parameter vector as the first argument. Must return a square matrix. If NULL, numeric gradient will be used.
start
numeric vector, initial value of parameters.
method
maximisation method, currently either "Newton-Raphson", "BFGS", "BHHH", "SANN" or "NM" (for Nelder-Mead). Lower-case letters and shortcuts (as 'nr' for Newton-Raphson) allowed. If missing, a suitable method is selected automathically.
constraints
either NULL for unconstrained maximization or a list, specifying the constraints. See maxBFGS.
...
further arguments for the maximisation routine.

Value

  • object of class 'maxLik' which inherits from class 'maxim'. Components are identical to those of class 'maxim', see maxNR.

Warning

The constrained maximum likelihood estimation should be considered as experimental. In particular, the variance-covariance matrix is not corrected for constrained parameter space.

Details

maxLik "support" constrained optimization in the sense that constraints are passed further to the underlying optimization routines, and suitable default method is selected. However, no attempt is made to correct the resulting variance-covariance matrix. Hence, the inference may be wrong. A corresponding warning is issued by the summary method.

See Also

maxNR, nlm and optim for different non-linear optimisation routines.

Examples

Run this code
## ML estimation of exponential duration model:
t <- rexp(100, 2)
loglik <- function(theta) log(theta) - theta*t
gradlik <- function(theta) 1/theta - t
hesslik <- function(theta) -100/theta^2
## Estimate with numeric gradient and hessian
a <- maxLik(loglik, start=1, print.level=2)
print( a )
coef( a )
## Estimate with analytic gradient and hessian
a <- maxLik(loglik, gradlik, hesslik, start=1)
print( a )
coef( a )
##
##
## Next, we give an example with vector argument:  Estimate the mean and
## variance of a random normal sample by maximum likelihood
##
loglik <- function(param) {
  mu <- param[1]
  sigma <- param[2]
  ll <- -0.5*N*log(2*pi) - N*log(sigma) - sum(0.5*(x - mu)^2/sigma^2)
  ll
}
x <- rnorm(1000, 1, 2) # use mean=1, stdd=2
N <- length(x)
res <- maxLik(loglik, start=c(0,1)) # use 'wrong' start values
print( res )
coef( res )

Run the code above in your browser using DataLab