Re: Fit vs Regress
- To: mathgroup at smc.vnet.net
- Subject: [mg4356] Re: Fit vs Regress
- From: rubin at msu.edu (Paul A. Rubin)
- Date: Thu, 11 Jul 1996 01:02:01 -0400
- Organization: Michigan State University
- Sender: owner-wri-mathgroup at wolfram.com
In article <4qqnlu$49m at dragonfly.wolfram.com>, "Prof. L. Seiford, IEOR, UMass, 413/545-1658" <SEIFORD at ecs.umass.edu> wrote: ->I received the following from a colleague. ->I'm not that familiar with the package. ->Does anyone have an explanation? ->thanks ->--larry -> ->>Wayne and I are trying to do a little linear regression, and having trouble. ->>What we want is to fit a linear form to 49 independent variables. We succeed in ->>using the Fit[ ] function as follows: ->> A = ReadList["test3624.mat", Number, RecordLists ->True] ->> y = Array[x,49] ->> z = Fit[A, y, y] ->>which results in ->> z = 0.178173 x[1] + 0.178173 x[2] - 0.0380162 x[3] + ->> 0.0713675 x[4] + 0.178173 x[5] ET CETERA ... x[49] ->> ->>However, the Function Browser window shows us that we can load in the package ->> <<"Statistics`LinearRegression`" ->>and use the Regress[ ] function. We tried this on a super-small data set first, ->>without using any subscripting of the independent variables, and it worked ->>nicely and gave us lots more data about the fit than Fit[ ] gives. ->> ->>However, if we try the full data set with the subscripted variables as above, ->>to wit: ->> A = ReadList["test3624.mat", Number, RecordLists ->True] ->> y = Array[x,49] ->> z = Regress[A, y, y] ->>we get nothing but error messages, in spite of the fact that the function ->>browser suggests that Fit[ ] and Regress[ ] have identical input formats! ->> ->>Any ideas? Regress[ ..., ..., {x, y, z, ...} ] uses Function[ {x, y, z, ...}, ... ], in which the variables names from the regression equation are used as formal parameters to Function. When the variable list has the form y = {x[1], x[2], ..., x[49]}, those formal parameters are actually function calls; e.g., x[1] is the (undefined) function x evaluated at argument 1. This is ok mathematically (after all, subscripting is just treating a symbol as a function of an integer argument), but syntactically it causes Function[] indigestion, hence the error messages. One workaround is to type in the variable names they want: y = {x1, x2, ..}. Another is to change y = Array[ x, 49 ] to y0 = Table[ Unique["x"], 49 ] both places it occurs in the call to Regress, which will give them 49 symbols of the form x$nnn (but not necessarily x$1, x$2, ...). If that's a big deal, they can convert to the other notation after Regress gets done with Regress[ A, y0, y0 ] /. Thread[ Rule[ y0, y ] ] Paul ************************************************************************** * Paul A. Rubin Phone: (517) 432-3509 * * Department of Management Fax: (517) 432-1111 * * Eli Broad Graduate School of Management Net: RUBIN at MSU.EDU * * Michigan State University * * East Lansing, MI 48824-1122 (USA) * ************************************************************************** Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. J. W. v. GOETHE ==== [MESSAGE SEPARATOR] ====