Plot a causal diagram. See Chapter 19 in Regression and Other Stories.


Load packages

library("rprojroot")
root<-has_file(".ROS-Examples-root")$make_fix_file()

Plot causal diagram

par(mar=c(0,0,0,0))
plot(c(-.5,4), c(0,1.8), xlab="", ylab="", xaxt="n", yaxt="n", bty="n", type="n")
text(0, 1, "x", cex=2.4)
text(1, 1, "z", cex=2.4)
text(3.5, .5, expression (y^0), cex=2)
text(3.5, 1.5, expression (y^1), cex=2)
text(c(0,1,3.5), c(1.8,1.8,1.8), c("Before","Treatment","Outcome"), cex=2)
text(1.9, .72, "Treatment 0 (z=0)", cex=2, srt=-16)
text(1.9, 1.27, "Treatment 1 (z=1)", cex=2, srt=14.3)
arrows(c(1.1,1.1), c(1,1), c(3.3,3.3), c(.5, 1.5))
arrows(-.3,.2,4,.2, length=.2)
text(1.8, .1, "Time", cex=2)

LS0tCnRpdGxlOiAiUmVncmVzc2lvbiBhbmQgT3RoZXIgU3RvcmllczogQ2F1c2FsRGlhZ3JhbSIKYXV0aG9yOiAiQW5kcmV3IEdlbG1hbiwgSmVubmlmZXIgSGlsbCwgQWtpIFZlaHRhcmkiCmRhdGU6ICJgciBmb3JtYXQoU3lzLkRhdGUoKSlgIgpvdXRwdXQ6CiAgaHRtbF9kb2N1bWVudDoKICAgIHRoZW1lOiByZWFkYWJsZQogICAgdG9jOiB0cnVlCiAgICB0b2NfZGVwdGg6IDIKICAgIHRvY19mbG9hdDogdHJ1ZQogICAgY29kZV9kb3dubG9hZDogdHJ1ZQotLS0KUGxvdCBhIGNhdXNhbCBkaWFncmFtLiBTZWUgQ2hhcHRlciAxOSBpbiBSZWdyZXNzaW9uIGFuZCBPdGhlcgpTdG9yaWVzLgoKLS0tLS0tLS0tLS0tLQoKCmBgYHtyIHNldHVwLCBpbmNsdWRlPUZBTFNFfQprbml0cjo6b3B0c19jaHVuayRzZXQobWVzc2FnZT1GQUxTRSwgZXJyb3I9RkFMU0UsIHdhcm5pbmc9RkFMU0UsIGNvbW1lbnQ9TkEpCi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