Skip to content

Commit

Permalink
countreg sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Apr 1, 2023
1 parent 1b3a86d commit 347672c
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions sandbox/methods_countreg.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# marginaleffects extension to zerotrunc model class from countreg package
# Following https://vincentarelbundock.github.io/marginaleffects/articles/extensions.html

library(marginaleffects)
options("marginaleffects_model_classes" = "zerotrunc")

get_coef.zerotrunc <- function(model, ...) {
b <- coef(model)
return(b)
}

set_coef.zerotrunc <- function(model, coefs, ...) {
out <- model
out$b <- coefs
return(out)
}

get_vcov.zerotrunc <- function(model, ...) {
return(model$vcov)
}

get_predict.zerotrunc <- function(model, newdata, ...) {
Yhat<-as.matrix(predict(model,type="response",newdata=newdata))
out <- data.frame(
predicted = as.vector(Yhat),
rowid = seq_len(nrow(Yhat)))
return(out)
}

0 comments on commit 347672c

Please sign in to comment.