Skip to content

Instantly share code, notes, and snippets.

@stevenpollack
Created February 24, 2014 18:20
Show Gist options
  • Save stevenpollack/9193820 to your computer and use it in GitHub Desktop.
Save stevenpollack/9193820 to your computer and use it in GitHub Desktop.
Code to build (X' X)^{-1} for problem #2.
table_5.1 <- matrix(0, nrow=4, ncol=4)
column_names <- c("Pres", "Educ", "Inc", "%W")
upper_tri <- c(253618, 55326, 12513, 37748108, 8121410,
6534383460, 131909, 32281, 14093097, 187312)
table_5.1[upper.tri(table_5.1, diag=TRUE)] <- upper_tri
table_5.1[lower.tri(table_5.1)] <- t(table_5.1)[lower.tri(table_5.1)]
colnames(table_5.1) <- rownames(table_5.1) <- column_names
sums <- matrix(c(4777, 1095, 693386, 2956), nrow=1, dimnames=list("Sum"))
n <- 102 # number of observations in Canadian dataset
Sum <- c(n,sums[-1])
XTX <- cbind(Sum,rbind(sums[-1],table_5.1[-1,-1]))
XTX_inv <- solve(XTX)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment