Type: | Package |
Title: | Estimate the First-Exposure Effect (FEE) using Count Data Models |
Version: | 1.0.0 |
Author: | Ryan T. Godwin [aut, cre] |
Maintainer: | Ryan T. Godwin <ryan.godwin@umanitoba.ca> |
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. |
License: | GPL (≥ 3) |
Imports: | graphics, oneinfl |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.2 |
NeedsCompilation: | no |
Packaged: | 2025-07-21 21:06:00 UTC; ryang |
Repository: | CRAN |
Date/Publication: | 2025-07-22 11:50:06 UTC |
Marginal First-Exposure Effects
Description
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.
Usage
dfee(model, data, at = "AE")
Arguments
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 |
Details
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.
Value
A list with components:
dfee
A named numeric vector of estimated marginal first-exposure effects for each variable.
sefee
A numeric vector of standard errors corresponding to the marginal effects.
where
A character string describing the evaluation point.
See Also
Examples
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)
Marginal First-Exposure Effects for One-Inflated Zero-Truncated Negative Binomial model
Description
This function is used internally by dfee
. The function computes
analytical derivatives of the FEE with respect to covariates, and uses discrete
differences for binary indicators.
Usage
dfee_nb(b, g, a, X, Z, dummies)
Arguments
b |
A numeric vector of estimated coefficients for the rate. |
g |
A numeric vector of estimated coefficients for inflation. |
a |
A dispersion parameter from the negative binomial model. |
X |
A numeric matrix of covariates for the rate. |
Z |
A numeric matrix of covariates for inflation. |
dummies |
A character vector naming the binary (dummy) variables to compute marginal effects for. |
Value
A matrix of marginal first-exposure effects. Each column corresponds to a covariate, and each row corresponds to an observation in the data.
See Also
Marginal First-Exposure Effects for One-Inflated Poisson Model
Description
This function is used internally by dfee
. The function computes
analytical derivatives of the FEE with respect to covariates, and uses discrete
differences for binary indicators.
Usage
dfee_pois(b, g, X, Z, dummies)
Arguments
b |
A numeric vector of estimated coefficients for the rate. |
g |
A numeric vector of estimated coefficients for inflation. |
X |
A numeric matrix of covariates for the rate. |
Z |
A numeric matrix of covariates for inflation. |
dummies |
A character vector naming the binary (dummy) variables to compute marginal effects for. |
Value
A matrix of marginal first-exposure effects. Each column corresponds to a covariate, and each row corresponds to an observation in the data.
See Also
First-Exposure Effect
Description
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.
Usage
fee(model, data, at = "AE")
Arguments
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 |
Details
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.
Value
A list with components:
fee
The estimated first-exposure effect.
sefee
The standard error of the estimated effect.
where
A character string describing the evaluation point.
treatment_visits
(Optional) Total implied treatment visits if
at = "AE"
.
Examples
# 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)
First-Exposure Effect for One-Inflated Zero-Truncated Negative Binomial Model
Description
Computes the first-exposure effect (FEE) for a model estimated using the
one-inflated zero-truncated negative binomial distribution. The FEE represents
the change in expected counts associated with the first exposure to treatment,
relative to the counterfactual zero-truncated negative binomial model. This
function is used internally by fee
at given covariate values.
Usage
fee_negbin(b, g, a, X, Z)
Arguments
b |
A numeric vector of estimated coefficients for the rate. |
g |
A numeric vector of estimated coefficients for inflation. |
a |
A dispersion parameter from the negative binomial model. |
X |
A numeric matrix of covariates for the rate. |
Z |
A numeric matrix of covariates for inflation. |
Value
A numeric vector of first-exposure effect(s).
See Also
First-Exposure Effect for One-Inflated Positive Poisson Model
Description
Computes the first-exposure effect (FEE) for a model estimated using the
one-inflated positive Poisson distribution. The FEE represents the change in
expected counts associated with the first exposure to treatment, relative to
the counterfactual positive Poisson model.This function is used internally by
fee
at given covariate values.
Usage
fee_pois(b, g, X, Z)
Arguments
b |
A numeric vector of estimated coefficients for the rate. |
g |
A numeric vector of estimated coefficients for inflation. |
X |
A numeric matrix of covariates for the rate. |
Z |
A numeric matrix of covariates for inflation. |
Value
A numeric vector of first-exposure effect(s).
See Also
Plot First-Exposure Effect Distribution
Description
Creates a bar plot of the observed count data overlaid with fitted values from
a oneinfl
model and its associated counterfactual (non-inflated) model.
Usage
feeplot(model, data, maxpred, ylimit, cex = 1.5, lwd = 1.5, ...)
Arguments
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 |
Details
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.
Value
A barplot with overlaid predicted values from the factual and counterfactual distributions, including a legend identifying each component.
See Also
Examples
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)
Predicted Counts from One-Inflated or Truncated Count Models
Description
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.
Usage
feepred(model, data, maxpred)
Arguments
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. |
Details
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.
Value
A numeric vector of length maxpred
, giving the predicted expected frequency of each count from 1 to maxpred
.
See Also
Examples
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)