maxlik.R

shige — Oct 3, 2013, 4:01 PM

# Example on pages 45-46, "Methods of Statistical Model Estimation"

jll.watson <- function(theta, x) {
  sum(log(1 + theta) - log(theta) - 2*log(1 + x / theta))
}

watson.fit <- function(x, ...) {
    optim(0.5,
            jll.watson,
            x = x,
            method = "Brent",
            lower = 0, upper = 1,
            control = list(fnscale= -1), ...)
}

large.sample <- rep(1:10, 10)/20

large.sample.fit <- watson.fit(large.sample)

large.sample.fit
$par
[1] 0.489

$value
[1] 25.76

$counts
function gradient 
      NA       NA 

$convergence
[1] 0

$message
NULL

# Using maxLik

library(maxLik)
Loading required package: miscTools

Please cite the 'maxLik' package as:
Henningsen, Arne and Toomet, Ott (2011). maxLik: A package for maximum likelihood estimation in R. Computational Statistics 26(3), 443-458. DOI 10.1007/s00180-010-0217-1.

If you have questions, suggestions, or comments regarding the 'maxLik' package, please use a forum or 'tracker' at maxLik's R-Forge site:
https://r-forge.r-project.org/projects/maxlik/

mle <- maxLik(logLik = jll.watson, start=.1, x=large.sample)

summary(mle)
--------------------------------------------
Maximum Likelihood estimation
Newton-Raphson maximisation, 8 iterations
Return code 1: gradient close to zero
Log-Likelihood: 25.76 
1  free parameters
Estimates:
     Estimate Std. error t value Pr(> t)    
[1,]    0.489      0.112    4.38 1.2e-05 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
--------------------------------------------