Multiple regression: Difference between revisions
m
→{{header|R}}
m (→{{header|R}}) |
|||
Line 2,176:
## create design matrix
X <- model.matrix
## create dependent variable
Line 2,203:
A numerically more stable way is to use the QR decomposition of the design matrix:
<lang
mf <- model.frame(formula)
X <- model.matrix(mf)
Y <- model.response(mf)
qr.coef(qr(X), Y)
}
lm(y ~ x + I(x^2))
# Call:
# lm(formula = y ~ x + I(x^2))
#
# Coefficients:
# (Intercept) x I(x^2)
# 128.81 -143.16 61.96
lm.impl(y ~ x + I(x^2))
# (Intercept) x I(x^2)
# 128.81280 -143.16202 61.96033</lang>
=={{header|Racket}}==
|