compute_SensIAT_expected_values: Compute Conditional Expected Values based on Outcome Model

View source: R/sensitivity_expected_values.R

compute_SensIAT_expected_valuesR Documentation

Compute Conditional Expected Values based on Outcome Model

Description

Compute Conditional Expected Values based on Outcome Model

Usage

compute_SensIAT_expected_values(
  model,
  alpha = 0,
  new.data = model.frame(model),
  ...
)

## S3 method for class 'lm'
compute_SensIAT_expected_values(model, alpha, new.data, ...)

## S3 method for class 'glm'
compute_SensIAT_expected_values(
  model,
  alpha,
  new.data,
  ...,
  y.max = NULL,
  eps = .Machine$double.eps
)

## S3 method for class 'negbin'
compute_SensIAT_expected_values(
  model,
  alpha,
  new.data,
  ...,
  y.max = NULL,
  eps = .Machine$double.eps^(1/4)
)

Arguments

model

An object representing the output of the outcome model.

alpha

The sensitivity parameter

new.data

Data to compute conditional means for, defaults to the model frame for the fitted model.

...

passed onto methods.

y.max

The maximum value of the outcome variable for the Poisson and Negative Binomial models. If omitted it is chosen from the quantile function for the distribution at 1-eps.

eps

The tolerance for the quantile function used to estimate y.max, default is .Machine$double.eps.

Details

Compute the conditional expectations needed for predictions in the models. Two additional values/expectations are computed:

  • ⁠$E \big[ Y(t) \exp \{ \alpha Y(t) \} | A(t)=1, \bar{O}(t) \big]$⁠, returned as E_Yexp_alphaY, and

  • ⁠$E \big[ \exp \{ \alpha Y(t) \} \ | A(t)=1, \bar{O}(t) \big]$⁠, returned as E_exp_alphaY.

For the methods shown here

Value

The new.data frame with additional columns alpha, E_Yexp_alphaY, and E_exp_alphaY appended.

Methods (by class)

  • compute_SensIAT_expected_values(lm): (Gaussian) Linear Model method The stats::integrate method is used to compute the conditional expectations.

  • compute_SensIAT_expected_values(glm): Generalized Linear Model method

  • compute_SensIAT_expected_values(negbin): Negative Binomial Model method

Examples

model <- lm(mpg ~ as.factor(cyl)+disp+wt, data=mtcars)
compute_SensIAT_expected_values(model, alpha= c(-0.3, 0, 0.3), new.data = mtcars[1:5, ])
model <- glm(cyl ~ mpg+disp+wt, data=mtcars, family=poisson())
compute_SensIAT_expected_values(model, alpha= c(-0.3, 0, 0.3), new.data = mtcars[1:5, ]) |>
    dplyr::mutate('E(y|alpha)' = .data$E_Yexp_alphaY/.data$E_exp_alphaY)

SensIAT documentation built on Sept. 9, 2025, 5:50 p.m.