R/methods.R

Defines functions .count_var logLik.cotram as.mlt.cotram mkgrid.cotram

Documented in as.mlt.cotram logLik.cotram

mkgrid.cotram <- function(object, n, ...)
  mkgrid(object$count_response, n = n, ...)

as.mlt.cotram <- function(object) {
  cls <- which(class(object) == "mlt_fit")
  class(object) <- class(object)[-(1:(cls - 1))]
  object
}

logLik.cotram <- function(object, parm = coef(as.mlt(object), fixed = FALSE), newdata, ...){
  response <- variable.names(object, "response")
  if (!missing(newdata)) {
    ## check that response is non-negative integer
    if (any(newdata[, response] < 0)) stop("response is non-positive")
    if (!all(newdata[, response] %% 1 == 0)) stop("response is non-integer")
    
    newdata[, response] <- .count_var(y = newdata[, response], plus_one = as.integer(object$log_first))
    return(logLik(as.mlt(object), parm = parm, newdata = newdata, ...))
  }
  logLik(as.mlt(object), parm = parm, ...)
}

.count_var <- function(y, plus_one) {
  ## count response as interval-censored object
  y <- as.integer(y)
  yleft <- y - 1L
  yleft[yleft < 0] <- -Inf
  
  Surv(yleft + plus_one, y + plus_one, type = "interval2")
}

Try the cotram package in your browser

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

cotram documentation built on July 14, 2022, 5:07 p.m.