R/estfun_cluster.R

#------------------------------------------------------------------------------#
#' Estimating Equations for clustered data
#'
#' @param x \code{lm} or \code{glm} object
#' @param groups vector of groupings
#' @export
#------------------------------------------------------------------------------#
estfun_cluster <- function(x, clusters, ...)
{
  if(!any(class(x) %in% c('lm', 'glm'))){
    stop('Model must be of class lm or glm')
  }
  out <- apply(estfun(x), 2, function(psi) tapply(psi, clusters, sum))
  return(out)
}
bsaul/sandwichShop documentation built on May 13, 2019, 8:13 a.m.