-
Notifications
You must be signed in to change notification settings - Fork 10
Description
Hello!
In implementing the interactionR_boot() function I encounter an error when a recode of the exposure/modifier variables is required. Consider the following example, which works without issue:
# Loading interactionR
if (!require("interactionR")) install.packages("interactionR")
library(interactionR)
# Loading RHC data
df <-
## Importing data & subsetting columns
read.csv("https://hbiostat.org/data/repo/rhc.csv", header = TRUE) |>
## Subsetting columns
subset(select = c(death, swang1, sex, adld3p)) |>
## Recoding binary values to 0/1
transform(death = ifelse(death == 'Yes', 1, 0)) |>
transform(swang1 = ifelse(swang1 == 'RHC', 1, 0)) |>
transform(sex = ifelse(sex == 'Male', 1, 0))
# Implementing a logistic regression model and interactionR_boot()
## The logistic regression model
mod.x <- glm(death ~ sex * swang1, family = binomial, data = df)
## Summarizing the model estimates
cbind(Est. = exp(coef(mod.x)), exp(confint.default(mod.x)))
## THE ABOVE CODE RETURNS THE FOLLOWING OUTPUT
##
## Est. 2.5 % 97.5 %
## (Intercept) 1.6150160 1.4617940 1.784298
## sex 1.1008802 0.9603613 1.261960
## swang1 1.2954362 1.0915900 1.537349
## sex:swang1 0.9358933 0.7452079 1.175372
## Implementing interactionR::interactionR_boot()
interactionR_boot(mod.x, em = TRUE, recode = TRUE, s = 100)$dframe
## THE ABOVE CODE RETURNS THE FOLLOWING OUTPUT
##
## Measures Estimates CI.ll CI.ul p
## 1 OR00 1.00000000 NA NA NA
## 2 OR01 1.29543621 1.0915900 1.537349 0.0030448253
## 3 OR10 1.10088016 0.9603613 1.261960 0.1677553438
## 4 OR11 1.33469612 1.1438060 1.557444 0.0002691867
## 5 OR(swang1 on outcome [sex==0] 1.29543621 1.0915900 1.537349 0.0030448253
## 6 OR(swang1 on outcome [sex==1] 1.21239002 1.0431779 1.409050 0.0119902673
## 7 Multiplicative scale 0.93589326 0.7452079 1.175372 0.5687153854
## 8 RERI -0.06162025 -0.3162320 0.211492 NA
## 9 AP -0.04616800 -0.2494047 0.155587 NA
In the above example, there is no need to recode either swang1 or sex because they are risk factors for the outcome, i.e., their corresponding ORs are >1.
However, when a recode is indeed required, as shown below:
# Implementing a logistic regression model and interactionR_boot()
## The logistic regression model, subset to complete case observations
mod.x <- glm(death ~ sex * swang1, family = binomial, data = na.omit(df))
## Summarizing the model estimates
cbind(Est. = exp(coef(mod.x)), exp(confint.default(mod.x)))
## THE ABOVE CODE RETURNS THE FOLLOWING OUTPUT
##
## Est. 2.5 % 97.5 %
## (Intercept) 0.8390805 0.7011339 1.004168
## sex 1.2651876 0.9917632 1.613994
## swang1 0.9852055 0.6728274 1.442613
## sex:swang1 1.0430454 0.6434684 1.690749
Then the following code:
## Implementing interactionR::interactionR_boot()
interactionR_boot(mod.x, em = TRUE, recode = TRUE, s = 100)$dframe
Yields the following error:
Error in eval(mf, parent.frame()) : object 'dat.ir' not found
I have found a work-around whereby I manually specify dat.ir <- model.frame(mod.x) and then implement library(car), which seems to resolve the problem. However, I don't think this is the intended behavior or solution.
Note, this issue does not arise with interactionR::interactionR().