Re: Wald test on mathematica

*To*: mathgroup at smc.vnet.net*Subject*: [mg82525] Re: Wald test on mathematica*From*: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>*Date*: Tue, 23 Oct 2007 05:35:35 -0400 (EDT)*Organization*: The Open University, Milton Keynes, UK*References*: <ffhr2h$4pb$1@smc.vnet.net>

Mauricio Esteban Cuak wrote: > Hello there. I've been trying to make a Wald test, but I got into some > problems. Lists are sort of vectors I guess, but they don't always function > that way.Here is my ordinary least squares function: > > ols[x_, y_] := (Inverse[Transpose[x].x]).Transpose[x].y; > > And my wald test: > > wald[r_, q_, x_, > y_] := (Transpose[(r.ols[x, y]) - q].Inverse[ > r.Inverse[Transpose[x].x].Transpose[r]].(r.ols[x, y] - q)*(Part[ > Dimensions[x], 1] - > Part[Dimensions[xdmda], 2]))/((errors[x, y].errors[x, y])* > Part[Dimensions[r], 1]) > > Where r and q make up the linear restrictions as in rb = q > The thing that bothers me is (and it's the same with ols) that I can't use > this same function if x is a vector instead of a matrix or if r is a vector, > because mathematica will not allow me to transpose a one-dimensional list. > What should I do? Should I make a "If, then" thingy or is there some simpler > way I'm not aware of for dealing with this kind of situatitions? Mauricio, Lists are pervasive in Mathematica. A one dimensional list might represent a vector but not necessarily (the element of the list can be numbers, symbols, strings of characters, names of functions, and so forth). However, vectors are represented by one dimensional lists without the explicit notion of column or row vector: the correct interpretation will be determined by Mathematica according to the specific context when such interpretation is required. Say we have a column vector x = (1, 2, 3)^T. If we want the dot product x.x (a scalar), we just use the *Dot* function. If we want the dot product x'.x (a square matrix), we use the *Outer* function, as in the following example. In[1]:= x = {1, 2, 3}; Outer[Times, x, x] Out[2]= {{1, 2, 3}, {2, 4, 6}, {3, 6, 9}} If you want that one function behaves differently according to the structure and/or value of its arguments, you can had some tests one the argument patterns. For instance, ols[x_, y_] := ... (* General case *) ols[x_/;VectorQ[x], y_] := ... (* To be call only if the first argument is a one dimensional list *) Having said that, I am not sure to understand what you would like to do with the first argument as a vector since the resulting matrix x'.x is going to be singular (rank one) that is not invertible. I may have overlook something in your request, though. Hope this helps, -- Jean-Marc