A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
16
Task/Multiple-regression/R/multiple-regression-2.r
Normal file
16
Task/Multiple-regression/R/multiple-regression-2.r
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
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))
|
||||
Loading…
Add table
Add a link
Reference in a new issue