How Can I perform a multiple Linear Regression in Mathematica 9 with built-in functions?
(Note that this means multiple independent variables with a single dependent variable. This is distinct from multivariate linear regression, which involves a single independent variable with multiple dependent variables, as asked in this questions.)
For a single variable I can use Fit:
data = Import["myfile","Table"]
line = Fit[data, {1, x}, x]
My data looks like this (in the file), but I need to get rid of Indx:
Indx, X1, X2, X3, X4, X5, Y
0, 0.1580, 0.3650, 97.7500, 80.0000, 0.5020, 25.4054
1, 0.1430, 0.4040, 92.0000, 112.5000, 0.6640, 8.1968
2, 0.1245, 0.4090, 171.5000, 82.5000, 0.7154, 96.1452
3, 0.1125, 0.1990, 84.7500, 82.5000, 0.7273, 10.8764
...
and I need Y = b + m1X1 + m2X2 + m3X3 + m4X4 + m5X5 where b is the intercept and the m's are the coefficients of the X's.
It's pretty straightforward what I need, but I can't figure out how to accomplish this. I tried various forms like:
linfit = Fit[data, {1, a, b, c, d, e}, {a, b, c, d, e}]
which I had hoped would interpret the different variables as different linear columns of data, but no such luck. It seems to just return the initial data set.
How do I do this in Mathematica 9?
RLink
functionality. Here's a link as to how to perform such analyses in R: socserv.socsci.mcmaster.ca/jfox/Books/Companion/appendix/…. $\endgroup$NonlinearModelFit
will produce those with essentially the same syntax asFindFit
. Here's a good summary of the differences between the two: mathematica.stackexchange.com/questions/61340/…. $\endgroup$