# CrudeOil Example -- source code file crude-oil.R # Find the estimated regression parameters using # proc reg and also using the matrix regression model. # Also find the residuals and predicted values. x1 <- c(1000, 1000, 1000, 2000, 2000, 2000, 3000, 3000, 3000) x2 <- c(0, 15, 30, 0, 15, 30, 0, 15, 30) y <- c(60.58, 72.72, 79.99, 66.83, 80.78, 89.78, 69.68, 80.31, 91.99) model <- lm(y ~ x1 + x2) cat("MultiReg regression output\n") print(summary(model)) cat("\n\nEstimated regression parameters\n") cat("using beta = (X'X)^-1 X'Y.\n") X <- cbind(rep(1, length(x1)), x1, x2) cat("\nMatrix X:\n") print(X) Y <- matrix(y, length(y), 1) cat("Matrix Y:\n") print(Y) beta <- solve(t(X) %*% X) %*% (t(X) %*% Y) cat("\nEstimated Parameter Vector beta:\n") print(beta)