Re: Regressions in Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg91971] Re: [mg91932] Regressions in Mathematica
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Mon, 15 Sep 2008 03:42:36 -0400 (EDT)
- Reply-to: hanlonr at cox.net
Needs["LinearRegression`"]; data = Table[{x = Random[], y = Random[], 5 x + 17 y + 6 + (2 Random[] - 1)}, {50}]; x =.; y =.; param = FindFit[data, a*x + b*y + c, {a, b, c}, {x, y}] {a->5.17687,b->16.9869,c->5.92077} ({c, a, b} /. param) == (ParameterTable /. Regress[data, {x, y}, {x, y}])[[1, All, 1]] True Bob Hanlon ---- Gregory Lypny <gregory.lypny at videotron.ca> wrote: ============= Hello everyone, 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. Regards, Gregory -- Bob Hanlon