Re: Regressions in Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg91969] Re: Regressions in Mathematica
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Mon, 15 Sep 2008 03:42:14 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <gag2m5$3a8$1@smc.vnet.net>
Gregory Lypny wrote: > I'm having trouble understanding the syntax of the Regress command. > If data is an nx2 matrix where the first column is the explanatory > variable and the second is the dependent variable, then either > > Regress[data, {1, x}, x] > > or > > Regress[data, x, x] > > performs a standard regression of the second column on the first with > a constant thrown in. But how do I write the command for the case of > more than one explanatory variable? Say that my data matrix is now > nx3, so that the first two columns are the explanatory variables and > the last is the dependent variable. > > Regress[data, {x,x}, x] or Regress[data, {1, x,x}, x] gives the error > message "Number of coordinates (2) is not equal to the number of > variables (1)". I'm not sure how I'm supposed to identify each > explanatory variable. I hope the following will help: In[1]:= Needs["LinearRegression`"] In[2]:= data = Flatten[Table[{x, y, x^2 + y^2}, {x, -1, 2}, {y, 3}], 1] Out[2]= {{-1, 1, 2}, {-1, 2, 5}, {-1, 3, 10}, {0, 1, 1}, {0, 2, 4}, {0, 3, 9}, {1, 1, 2}, {1, 2, 5}, {1, 3, 10}, {2, 1, 5}, {2, 2, 8}, {2, 3, 13}} In[3]:= Regress[data, {1, x, y}, {x, y}] Out[3]= {ParameterTable -> Estimate SE TStat PValue , 1 -2.33333 0.988826 -2.3597 0.0426223 x 1. 0.329609 3.0339 0.014157 -6 y 4. 0.451335 8.86259 9.68155 10 RSquared -> 0.906977, AdjustedRSquared -> 0.886305, EstimatedVariance -> 1.62963, ANOVATable -> DF SumOfSq MeanSq FRatio PValue } Model 2 143. 71.5 43.875 0.0000228382 Error 9 14.6667 1.62963 Total 11 157.667 In[4]:= Regress[data, {1, x, y, x^2, y^2}, {x, y}] Out[4]= {ParameterTable -> Estimate SE TStat PValue , -15 -15 1 -5.3843 10 6.47747 10 -0.831234 0.433276 -16 -15 x -5.93487 10 1.13915 10 -0.520992 0.618443 -15 -15 y 4.74751 10 7.27927 10 0.652197 0.535096 2 -16 15 x 1. 8.49071 10 1.17776 10 0. 2 -15 14 y 1. 1.80115 10 5.552 10 0. RSquared -> 1., AdjustedRSquared -> 1., -30 EstimatedVariance -> 8.65106 10 , ANOVATable -> DF SumOfSq MeanSq FRatio PValue} 30 Model 4 157.667 39.4167 4.55628 10 0. -29 -30 Error 7 6.05574 10 8.65106 10 Total 11 157.667 Best regards, -- Jean-Marc