# Confounded 4 factor factorial designs # Open this file in R, click on 'Save', then on Edit -> Run all. # 16 runs in 4 blocks with ABC and ACD confounded: A <- rep(c(-1,1), times=8) B <- rep(c(-1,1), each = 2, times=4) C <- rep(c(-1,1), each = 4, times=2) D <- rep(c(-1,1), each = 8) ABC <- A*B*C ACD <- A*C*D BD <- B*D y <- c(25, 71, 48, 45, 68, 40, 60, 65, 43, 80, 25, 14, 55, 86, 20, 76) blocks <- vector(length=16) for(i in 1:16) { if(ABC[i]==-1 & ACD[i]==-1) blocks[i]=1 if(ABC[i]==1 & ACD[i]==-1) blocks[i]=2 if(ABC[i]==-1 & ACD[i]==1) blocks[i]=3 if(ABC[i]==1 & ACD[i]==1) blocks[i]=4 } blocks <- as.factor(blocks) data <- data.frame(A, B, C, D, blocks, ABC, ACD,BD, y) data g <- lm(y ~ blocks + A + B + C + D + A*B + A*C + A*D + B*C + C*D + A*B*D + B*C*D + A*B*C*D) anova(g) g$effects effects <- abs(g$effects[-1]) windows() qq <- qqnorm(effects, type="n") # "n" means no plotting text(qq$x, qq$y, labels = names(effects)) h <- lm(y ~ blocks + A + B + C + B*C + A*B + A*D + C*D) anova(h)