Skip to content
Snippets Groups Projects
Commit f47d0eb8 authored by Walmes Marques Zeviani's avatar Walmes Marques Zeviani
Browse files

Corrige problema de offset.

parent 094f9b13
Branches
No related tags found
No related merge requests found
......@@ -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)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment