RosettaCodeData/Task/Multiple-regression/R/multiple-regression-2.r
Ingy döt Net db842d013d A-M baby
2013-04-10 21:29:02 -07:00

16 lines
341 B
R

simpleMultipleReg <- function(formula) {
## parse and evaluate the model formula
mf <- model.frame(formula)
## create design matrix
X <- model.matrix(attr(mf, "terms"), mf)
## create dependent variable
Y <- model.response(mf)
## solve
solve(t(X) %*% X) %*% t(X) %*% Y
}
simpleMultipleReg(y ~ x + I(x^2))