# Now get the average difference between these interactions
data %>%
reframe(
# Get the TC interaction when K is A
d1a = y[t==180&k=="A"&c==40] - y[t==160&k=="A"&c==40],
d0a = y[t==180&k=="A"&c==20] - y[t==160&k=="A"&c==20],
dbar_a = (d1a - d0a)/2,
# Get the TC interaction when K is B
d1b = y[t==180&k=="B"&c==40] - y[t==160&k=="B"&c==40],
d0b = y[t==180&k=="B"&c==20] - y[t==160&k=="B"&c==20],
dbar_b = (d1b - d0b)/2,
# Get three way interaction effect
dbar = (dbar_b - dbar_a) / 2
)
# Now get the average difference between these interactions
d, y = data, data["y"]
def at(t, k, c):
return y[(d.t == t) & (d.k == k) & (d.c == c)].iat[0]
# Get the TC interaction when K is A
d1a = at(180, "A", 40) - at(160, "A", 40)
d0a = at(180, "A", 20) - at(160, "A", 20)
dbar_a = (d1a - d0a) / 2
# Get the TC interaction when K is B
d1b = at(180, "B", 40) - at(160, "B", 40)
d0b = at(180, "B", 20) - at(160, "B", 20)
dbar_b = (d1b - d0b) / 2
# Get three way interaction effect
dbar = (dbar_b - dbar_a) / 2
d1a d0a dbar_a d1b d0b dbar_b dbar
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
14 12 1 35 31 2 0.5