Corrige problema de offset.

parent 094f9b13
......@@ -238,6 +238,11 @@ dgcnt <- function(y, lambda, alpha) {
#'
#' @importFrom stats glm.fit model.frame model.matrix model.offset model.response poisson
gcnt <- function(formula, data, start = NULL, ...) {
if (!requireNamespace("bbmle", quietly = TRUE)){
stop(paste("`bbmle` \u00e9 necess\u00e1rio para",
"essa fun\u00e7\u00e3o. Por favor, instale-o."),
call. = FALSE)
}
frame <- model.frame(formula, data)
terms <- attr(frame, "terms")
y <- model.response(frame)
......@@ -247,9 +252,10 @@ gcnt <- function(formula, data, start = NULL, ...) {
m0 <- glm.fit(x = X, y = y, offset = off, family = poisson())
start <- c("alpha" = 0, m0$coefficients)
}
off <- if (is.null(off)) { NULL } else { exp(off) }
bbmle::parnames(llgcnt) <- names(start)
model <- bbmle::mle2(minuslogl = llgcnt, start = start,
data = list(y = y, X = X, offset = exp(off)),
data = list(y = y, X = X, offset = off),
vecpar = TRUE, ...)
return(model)
}
......@@ -216,6 +216,11 @@ dpgnz <- function(y, lambda, alpha) {
#'
#' @importFrom stats glm.fit model.frame model.matrix model.offset model.response poisson
pgnz <- function(formula, data, start = NULL, ...) {
if (!requireNamespace("bbmle", quietly = TRUE)){
stop(paste("`bbmle` \u00e9 necess\u00e1rio para",
"essa fun\u00e7\u00e3o. Por favor, instale-o."),
call. = FALSE)
}
frame <- model.frame(formula, data)
terms <- attr(frame, "terms")
y <- model.response(frame)
......@@ -225,9 +230,10 @@ pgnz <- function(formula, data, start = NULL, ...) {
m0 <- glm.fit(x = X, y = y, offset = off, family = poisson())
start <- c("alpha" = 0, m0$coefficients)
}
off <- if (is.null(off)) { NULL } else { exp(off) }
bbmle::parnames(llpgnz) <- names(start)
model <- bbmle::mle2(minuslogl = llpgnz, start = start,
data = list(y = y, X = X, offset = exp(off)),
data = list(y = y, X = X, offset = off),
vecpar = TRUE, ...)
return(model)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment