# Deterministic synthetic linear-model illustration; base R.
x <- rep(0:7, 2); g <- rep(0:1, each=8)
X <- cbind(1,x,g,x*g)
z <- sin(seq_along(x))
e <- qr.resid(qr(X),z)*2
response <- as.vector(X %*% c(40,2,5,-1)+e)
fit <- lm(response ~ x*g)
print(coef(fit))
contrast <- function(L,label) {
 est <- sum(L*coef(fit)); se <- sqrt(drop(t(L)%*%vcov(fit)%*%L))
 ci <- est+c(-1,1)*qt(.975,df.residual(fit))*se
 cat(sprintf("%s estimate=%.6f SE=%.6f CI=[%.6f,%.6f]\n",label,est,se,ci[1],ci[2]))
}
contrast(c(0,1,0,0),"slope g=0")
contrast(c(0,1,0,1),"slope g=1")
contrast(c(0,0,0,1),"slope difference")
for(h in c(2,6)) contrast(c(0,0,1,h),paste("group difference x=",h))
