I want to find the least square estimate for an over-determined system of linear equations the way Matlab does with \
.
What I am trying to reproduce in R:
% matlab code
X = [3.8642 9.6604;
14.2000 35.5000;
41.7832 104.4580;
0.4084 1.0210];
y = [1.2300
4.5200
13.3000
0.1300];
X\y % => [0, 0.1273]
I tried R's lsfit
method, the generalized Inverse (ginv
) from the MASS
package, and using the QR compositon (R-1Q'y), but all returns different results.
Data in R format:
x <- matrix(c(3.8642, 14.2, 41.7832, 0.4084, 9.6604, 35.5, 104.458, 1.021),
ncol = 2)
y <- c(1.23, 4.52, 13.3, 0.13)