R/logLik.glmb.R

Defines functions logLik.glmb

Documented in logLik.glmb

#' Extract Log-Likelihood
#'
#' This function is a method function for the \code{"glmb"} class used to 
#' Extract the log-Likelihood from a Bayesian Generalized Linear Model.
#' @param object an object of class \code{glmb}, typically the result of a call to \link{glmb}
#' @param ... further arguments to or from other methods
#' @return The function returns a vector, \code{logLikout} with the estimated log-likelihood for each draw.
#' @seealso \code{\link{glmb}}, \code{\link{glmbayes-package}}; \code{\link{rglmb}}, \code{\link{rlmb}},
#'   \code{\link{lmb}}; \code{\link[stats]{logLik}}.
#' @example inst/examples/Ex_logLik.glmb.R
#' @export
#' @method logLik glmb


## This method follows stats::logLik() method conventions for model objects,
## returning draw-wise Bayesian log-likelihood values. See inst/COPYRIGHTS.
logLik.glmb<-function(object,...){
  
  y<-object$y
  x<-object$x
  wt<-object$prior.weights
  dispersion<-object$dispersion
  
  
  #alpha # to be updated 
  f1<-object$famfunc$f1
  n<-length(object$coefficients[,1])
  
  logLikout<-matrix(0,nrow=n,ncol=1)

  if(length(dispersion)==1){  
    for(i in 1:n){
    logLikout[i,1]<--f1(object$coefficients[i,],y=y,x=x,wt=wt/dispersion)
    }
  }
  
  if(length(dispersion)>1){  
    for(i in 1:n){
      logLikout[i,1]<--f1(object$coefficients[i,],y=y,x=x,wt=wt/dispersion[i])
    }
  }
  
  logLikout
}

Try the glmbayes package in your browser

Any scripts or data that you put into this service are public.

glmbayes documentation built on Aug. 5, 2026, 1:07 a.m.