0
|
6884 Views
|
3 Replies
|
2 Total Likes
View groups...
Share
GROUPS:

# Running a simple regresson

Posted 11 years ago
 Hi, I'm new to the estimation modules in Mathematica and am trying to run a simple multivariate regression using Excel imported data with a header line. I can import the data, but am having trouble getting the data in the right shape to run a regression using LinearModelFit.  Below are my commands and Mathematica output. Any help you can provide would be very much appreciated. d2 = Import["C:\\Users\\pm91\\Downloads\\test1.csv"] {{1, 1610, 1, 0, 32, 12}, {1, 1656, 0, 2, 30, 12}, {1, 1980, 1, 3, 35,    12}, {1, 456, 0, 3, 34, 12}, {1, 1568, 1, 2, 31, 14}, {1, 2032, 0,    0, 54, 12}, {1, 1440, 0, 2, 37, 16}, {1, 1020, 0, 0, 54, 12}, {1,    1458, 0, 2, 48, 12}, {1, 1600, 0, 2, 39, 12}, {1, 1969, 0, 1, 33,    12}, {1, 1960, 0, 1, 42, 11}, {1, 240, 1, 2, 30, 12}, {1, 997, 0, 2,    43, 12}, {1, 1848, 0, 1, 43, 10}, {1, 1224, 0, 3, 35, 11}, {1,    1400, 0, 2, 43, 12}, {1, 640, 0, 5, 39, 12}, {1, 2000, 0, 0, 45,    12}}y = Transpose[d2][[1]] ;kids1 = Transpose[d2][[3]];kids2 = Transpose[d2][[4]];age = Transpose[d2][[5]];example = Transpose[{kids1, kids2, age, y}]LInearModelFit[example, {1, kids1, kids2, age, y}, {kids1, kids2, age,   y}]{{1, 0, 32, 1}, {0, 2, 30, 1}, {1, 3, 35, 1}, {0, 3, 34, 1}, {1, 2,   31, 1}, {0, 0, 54, 1}, {0, 2, 37, 1}, {0, 0, 54, 1}, {0, 2, 48,   1}, {0, 2, 39, 1}, {0, 1, 33, 1}, {0, 1, 42, 1}, {1, 2, 30, 1}, {0,   2, 43, 1}, {0, 1, 43, 1}, {0, 3, 35, 1}, {0, 2, 43, 1}, {0, 5, 39,   1}, {0, 0, 45, 1}}LInearModelFit[{{1, 0, 32, 1}, {0, 2, 30, 1}, {1, 3, 35, 1}, {0, 3,    34, 1}, {1, 2, 31, 1}, {0, 0, 54, 1}, {0, 2, 37, 1}, {0, 0, 54,    1}, {0, 2, 48, 1}, {0, 2, 39, 1}, {0, 1, 33, 1}, {0, 1, 42, 1}, {1,    2, 30, 1}, {0, 2, 43, 1}, {0, 1, 43, 1}, {0, 3, 35, 1}, {0, 2, 43,    1}, {0, 5, 39, 1}, {0, 0, 45, 1}}, {1, {1, 0, 1, 0, 1, 0, 0, 0, 0,    0, 0, 0, 1, 0, 0, 0, 0, 0, 0}, {0, 2, 3, 3, 2, 0, 2, 0, 2, 2, 1,    1, 2, 2, 1, 3, 2, 5, 0}, {32, 30, 35, 34, 31, 54, 37, 54, 48, 39,    33, 42, 30, 43, 43, 35, 43, 39, 45}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1,    1, 1, 1, 1, 1, 1, 1, 1, 1}}, {{1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0,    1, 0, 0, 0, 0, 0, 0}, {0, 2, 3, 3, 2, 0, 2, 0, 2, 2, 1, 1, 2, 2,    1, 3, 2, 5, 0}, {32, 30, 35, 34, 31, 54, 37, 54, 48, 39, 33, 42,    30, 43, 43, 35, 43, 39, 45}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,    1, 1, 1, 1, 1, 1, 1}}]
3 Replies
Sort By:
Posted 11 years ago
 Hi Pat,Offhand I don't have experience with any Mathematica-oriented books specifi to regression analysis.  It seems mostly that you are on the path to getting greater familiarity with Mathematica.  This, I think is key.  Recently I have been reading Paul Wellin's bookhttp://www.amazon.com/Programming-Mathematica-Introduction-Paul-Wellin/dp/1107009464/which I think is quite good.Best regards,David
Posted 11 years ago
 Dear David, thanks very much for the help. I know there are many books on mathematica programming. Do you know of nay books, papers and related that provdes the nuts and bolts of regression and related analyses. Most of my difficulty is associated, as above, with getting the data in the right form for mathematica. Thanks again! Pat
Posted 11 years ago
 Note that (1) you need LinearModelFit rather than LInearModelFit (i.e., you have a misspelling with a capital "i")(2) kids1, kids2, age, and y are not unassigned parameters: they have values and you cannot use them as the fitting parameters.  The following works: d2 = {{1, 1610, 1, 0, 32, 12}, {1, 1656, 0, 2, 30, 12}, {1, 1980, 1,      3, 35, 12}, {1, 456, 0, 3, 34, 12}, {1, 1568, 1, 2, 31, 14}, {1,      2032, 0, 0, 54, 12}, {1, 1440, 0, 2, 37, 16}, {1, 1020, 0, 0, 54,      12}, {1, 1458, 0, 2, 48, 12}, {1, 1600, 0, 2, 39, 12}, {1, 1969,      0, 1, 33, 12}, {1, 1960, 0, 1, 42, 11}, {1, 240, 1, 2, 30,      12}, {1, 997, 0, 2, 43, 12}, {1, 1848, 0, 1, 43, 10}, {1, 1224, 0,      3, 35, 11}, {1, 1400, 0, 2, 43, 12}, {1, 640, 0, 5, 39, 12}, {1,      2000, 0, 0, 45, 12}}; y = Transpose[d2][[1]];kids1 = Transpose[d2][[3]];kids2 = Transpose[d2][[4]];age = Transpose[d2][[5]];example = Transpose[{kids1, kids2, age, y}];LinearModelFit[example, {x1, x2, x3}, {x1, x2, x3}]