Jump to content

Multiple regression: Difference between revisions

m
Line 2,176:
 
## create design matrix
X <- model.matrix(attr(mf, "terms"), mf)
 
## create dependent variable
Line 2,203:
A numerically more stable way is to use the QR decomposition of the design matrix:
 
<lang Rrsplus>qrlm.coefimpl <- function(qr(Xformula), y)</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}}==
1,336

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.