# lhobbslikn.R
# 4 parameter negative log likelihood for weeds problem in 
#  direct (non-log) scale, including sigma2
#  We still use simple scalings for the logistic parameters
## source("lhobbs.R")

lhobbsn.lik<-function(xaug,y=y0){ # likelihood function including sigma
  xx<-xaug[1:3]
  sigma2<-xaug[4]
  res<-lhobbs.res(xx,y)
  nll<-0.5*(length(res)*log(2*pi*sigma2)+sum(res*res)/sigma2)
}

lhobbsn.lg<-function(xaug,y=y0){ # gradient function including sigma
  xx<-xaug[1:3]
  sigma2<-xaug[4]
  res3<-lhobbs.res(xx,y)
  n<-length(res3)
  f3<-crossprod(res3)
#  cat("in lhobbs.lg: f3=",f3," n=",n," g3:\n")
  g3<-0.5*lhobbs.g(xx)/sigma2
#  print(g3)
  gg<-c(g3,0.5*(n - f3/sigma2)/sigma2)
}

