library(inferference)
head(vaccinesim)
##   y     X1    X2 A B group
## 1 1 5.3607 1.716 0 0     1
## 2 0 0.1965 1.731 0 1     1
## 3 0 0.4846 1.770 1 1     1
## 4 0 0.8013 1.716 0 1     1
## 5 0 2.1427 1.772 1 1     1
## 6 0 1.2861 1.716 0 1     1
example1 <- interference(
    formula = y | A | B ~ X1 + X2 + (1|group) | group, 
    allocations = seq(.2,.8, by = .1), 
    data = vaccinesim, 
    randomization = 2/3,
    method = 'simple')
## [1] "Calculating matrix of IP weights..."
## [1] "Calculating array of IP weight derivatives..."
## [1] "Calculating matrix of scores..."
## [1] "Computing effect estimates..."
## [1] "Interference complete"

Direct Effects

deff <- direct_effect(example1)
x <- deff$alpha1
y <- as.numeric(deff$estimate)
u <- as.numeric(deff$conf.high)
l <- as.numeric(deff$conf.low)
plot(c(min(x), max(x)),c(-.15, .25), type = 'n',
     xlab = expression(alpha), 
     ylab = expression(widehat(DE) * "(" * alpha * ")"),
     bty = 'n')
polygon(c(x, rev(x)), c(u, rev(l)), col = 'skyblue', border = NA)
lines(x, y, cex = 2)

plot of chunk unnamed-chunk-3

Indirect Effects

ieff.4 <- ie(example1, allocation1 = .4)
x <- ieff.4$alpha2
y <- as.numeric(ieff.4$estimate)
u <- as.numeric(ieff.4$conf.high)
l <- as.numeric(ieff.4$conf.low)
plot(c(min(x), max(x)),c(-.15, .25), type = 'n',
     xlab = expression(alpha * "'"), 
     ylab = expression(widehat(IE) * "(" * 0.4 * "," * alpha * "'" * ")"))
polygon(c(x, rev(x)), c(u, rev(l)), col = 'skyblue', border = NA)
lines(x, y, cex = 2)

plot of chunk unnamed-chunk-4

ieff <- subset(example1$estimates, effect == 'indirect')
x <- sort(unique(ieff$alpha1))
y <- sort(unique(ieff$alpha2))
z <- xtabs(as.numeric(estimate) ~ alpha1 + alpha2, data= ieff)
contour(x, y, z,
        xlab = expression(alpha), ylab = expression(alpha * "'"))

plot of chunk unnamed-chunk-5