# tiny example of regression, last column contains 'y'
xy <- matrix(c(1, 1, 1, 1,
1, 2, 1, 3,
1, 3, 1, 3,
1, 1,-1, 2,
1, 2,-1, 2,
1, 3,-1, 1), ncol = 4, byrow = TRUE)
z <- crossprod(xy)
z <- sweep.operator(z, k = 1:3)
cf <- z[1:3,4] # regression coefficients
RSS <- z[4,4] # residual sum of squares
# an example not that small
x <- matrix(rnorm(1000 * 100), ncol = 100)
xx <- crossprod(x)
z <- sweep.operator(xx, k = 1)
Run the code above in your browser using DataLab