| Title: | Estimate the First-Exposure Effect (FEE) using Count Data Models |
|---|---|
| Description: | Estimates the first-exposure effect (FEE) using a one-inflated positive Poisson model, or a one-inflated zero-truncated negative binomial model. In addition, estimates the marginal FEE, and standard errors for the FEE and marginal FEE. |
| Authors: | Ryan T. Godwin [aut, cre] |
| Maintainer: | Ryan T. Godwin <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.0.0 |
| Built: | 2026-05-21 07:41:46 UTC |
| Source: | https://github.com/rtgodwin/fee |
Computes marginal first-exposure effects from a fitted oneinfl model.
Dummy variables are automatically detected as those with exactly two unique values
in the data, and corresponding marginal effects are instead calculated by differencing
the FEE between both values of the dummy.
dfee(model, data, at = "AE")dfee(model, data, at = "AE")
model |
A fitted model object of class |
data |
A data frame containing the variables used to fit the model. |
at |
A character string or list. Specifies where the marginal FEE should be evaluated.
Options are |
The marginal effects can be evaluated in three ways, determined by the at argument:
"AE": Average over all data points (default).
"EM": Evaluate at the sample means of the covariates.
list: Evaluate at a user-specified set of covariate values.
A list with components:
dfeeA named numeric vector of estimated marginal first-exposure effects for each variable.
sefeeA numeric vector of standard errors corresponding to the marginal effects.
whereA character string describing the evaluation point.
df <- data.frame(x = runif(10,0,10), d = sample(c(0,1), 10, replace=TRUE), y = rpois(10, 3) + 1) model <- oneinfl::oneinfl(formula = y ~ x + d | x + d, df = df, dist = "Poisson") dfee(model, data = df)df <- data.frame(x = runif(10,0,10), d = sample(c(0,1), 10, replace=TRUE), y = rpois(10, 3) + 1) model <- oneinfl::oneinfl(formula = y ~ x + d | x + d, df = df, dist = "Poisson") dfee(model, data = df)
Computes the first-exposure effect (FEE) from a fitted 'oneinfl' model object. The FEE measures the difference between the expected count for a first-time exposure and the expected count under the baseline (non-inflated) model. The function supports models estimated using either a one-inflated positive Poisson distribution or a one-inflated zero-truncated negative binomial distribution.
fee(model, data, at = "AE")fee(model, data, at = "AE")
model |
A fitted model object of class |
data |
The original data frame used to fit the model. |
at |
A character string or list. Specifies how the first-exposure effect should be evaluated.
Options are |
The effect can be evaluated in three ways, determined by the 'at' argument:
"AE": Average the FEE over all data points (default).
"EM": Evaluate the FEE at the sample means of the covariates.
list: Evaluate the FEE at a user-specified set of covariate values.
If 'at = "AE"', the returned object also includes the total number of treatment visits implied by the FEE across all observations.
A list with components:
feeThe estimated first-exposure effect.
sefeeThe standard error of the estimated effect.
whereA character string describing the evaluation point.
treatment_visits(Optional) Total implied treatment visits if at = "AE".
# Example usage df <- data.frame(x = runif(10,0,10), d = sample(c(0,1), 10, replace=TRUE), y = rpois(10, 3) + 1) model <- oneinfl::oneinfl(formula = y ~ x + d | x + d, df = df, dist = "Poisson") fee(model, data = df)# Example usage df <- data.frame(x = runif(10,0,10), d = sample(c(0,1), 10, replace=TRUE), y = rpois(10, 3) + 1) model <- oneinfl::oneinfl(formula = y ~ x + d | x + d, df = df, dist = "Poisson") fee(model, data = df)
Creates a bar plot of the observed count data overlaid with fitted values from
a oneinfl model and its associated counterfactual (non-inflated) model.
feeplot(model, data, maxpred, ylimit, cex = 1.5, lwd = 1.5, ...)feeplot(model, data, maxpred, ylimit, cex = 1.5, lwd = 1.5, ...)
model |
A fitted object of class |
data |
A data frame containing the original data used to fit the model. |
maxpred |
Optional integer indicating the maximum count value to include on the x-axis.
Defaults to the maximum observed value in |
ylimit |
Optional numeric value specifying the upper limit of the y-axis. Defaults to 110% of the maximum observed count frequency. |
cex |
A numeric value for point size in the overlay plot. Defaults to |
lwd |
A numeric value for line width in the overlay plot. Defaults to |
... |
Additional arguments passed to |
The factual predictions come from the fitted oneinfl model, while the
counterfactual distribution is obtained by transforming the model into a non-inflated
counterpart using the same estimated parameters.
The function detects whether the model is based on a Poisson or negative binomial distribution and selects the appropriate counterfactual model.
A barplot with overlaid predicted values from the factual and counterfactual distributions, including a legend identifying each component.
df <- data.frame(x = runif(10,0,10), d = sample(c(0,1), 10, replace=TRUE), y = rpois(10, 3) + 1) model <- oneinfl::oneinfl(formula = y ~ x + d | x + d, df = df, dist = "Poisson") feeplot(model, data = df)df <- data.frame(x = runif(10,0,10), d = sample(c(0,1), 10, replace=TRUE), y = rpois(10, 3) + 1) model <- oneinfl::oneinfl(formula = y ~ x + d | x + d, df = df, dist = "Poisson") feeplot(model, data = df)
Computes the predicted count distribution from a fitted model of class "oneinflmodel",
"truncmodel", or "basicPoisson". The function returns the expected frequency
for each count value from 1 up to maxpred, based on the model's parameters.
feepred(model, data, maxpred)feepred(model, data, maxpred)
model |
A fitted model object of class |
data |
A data frame containing the covariates used to fit the model. |
maxpred |
Optional integer specifying the maximum count value for which to compute predicted frequencies. If not supplied, defaults to the maximum observed count in the data. |
The function determines the model type based on its class and the dist attribute, and applies the appropriate
density function:
For oneinflmodel (Poisson): one-inflated positive Poisson distribution.
For oneinflmodel (negbin): one-inflated zero-truncated negative binomial.
For truncmodel (Poisson): truncated positive Poisson.
For truncmodel (negbin): zero-truncated negative binomial.
A numeric vector of length maxpred, giving the predicted expected frequency of each count from 1 to maxpred.
df <- data.frame(x = runif(10,0,10), d = sample(c(0,1), 10, replace=TRUE), y = rpois(10, 3) + 1) model <- oneinfl::oneinfl(formula = y ~ x + d | x + d, df = df, dist = "Poisson") feepred(model, data = df)df <- data.frame(x = runif(10,0,10), d = sample(c(0,1), 10, replace=TRUE), y = rpois(10, 3) + 1) model <- oneinfl::oneinfl(formula = y ~ x + d | x + d, df = df, dist = "Poisson") feepred(model, data = df)