#  lhobbliktest.R
#  test the function and gradient computation for Hobbs 4 parameter
#  maximum likelihood estiomation of a 3 parameter logistic in
#  log-form parameters
source("../R/lhobbs.R") # This form works with both make and Sweave
source("../R/lhobbslik.R")
require(numDeriv)
y0 <- c(5.308, 7.24, 9.638, 12.866, 17.069, 23.192, 31.443, 38.558, 50.156, 62.948,
        75.995, 91.972)

xxax<-c(2,5,3,1)
xxa<-log(xxax)
xl3<-xxa[1:3] # 3 params only
res0<-lhobbs.res(xl3, y=y0)
print(res0)
ss0<-lhobbs.f(xl3,y=y0)
print(ss0)
jj0<-lhobbs.jac(xl3,y=y0)
jj0n<-jacobian(lhobbs.res,xl3,y=y0)
print(jj0-jj0n)
g0<-lhobbs.g(xl3,y=y0)
g0n<-grad(lhobbs.f,xl3,y=y0)
print(g0)
print(g0-g0n)



f<-lhobbs.lik(xxa,y=y0)
f
ga<-lhobbs.lg(xxa,y=y0)
ga
gn<-grad(lhobbs.lik, xxa, y=y0)
gn


