MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Data preparation and statistics question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg41777] Re: [mg41741] Data preparation and statistics question
  • From: Tomas Garza <tgarza01 at prodigy.net.mx>
  • Date: Thu, 5 Jun 2003 07:31:22 -0400 (EDT)
  • References: <200306031113.HAA07330@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

I suggest the following, which no doubt will be improved upon by a number of
participants in this group. For the sake of example, take a grid of 10 x 5
(with x_increment = y_increment = 1). I will use a set of 20 random points
as your l1. Then

In[1]:=
data = Table[{Random[Real, {0, 10}], Random[Real, {0, 5}],
    Random[Real, {0, 10}]}, {20}];

The coordinates on the xy plane are

In[2]:=
pts = data /. {x_, y_, z_} -> {x, y};

which may be observed visually to see the position of the points with
respect to the grid (for checking purposes):

In[3]:=
vs = Show[Graphics[Table[Line[{{i, 0}, {i, 5}}], {i, 0, 10}]],
    DisplayFunction -> Identity];
hs = Show[Graphics[Table[Line[{{0, i}, {10, i}}], {i, 0, 5}]],
    DisplayFunction -> Identity];
Show[hs, vs, Graphics[{PointSize[0.015], Point /@ pts}],
   DisplayFunction -> $DisplayFunction, AspectRatio -> 0.5];

In[6]:=
incr = 1;
In[7]:=
xes = Table[x, {x, 0, 10, incr}];
yes = Table[y, {y, 0, 5, incr}];

Here you group the observations within each of the squares:

In[9]:=
grp = Table[Table[Select[Select[data, xes[[j]] < #1[[1]]
        <= xes[[j + 1]] & ], yes[[i]] < #1[[2]] <=
       yes[[i + 1]] & ], {i, 1, Length[yes] - 1}],
   {j, 1, Length[xes] - 1}]

These are the z values within each square:

In[10]:=
zval = Table[grp[[i]] /. {{x_, y_, z_} -> z, {} -> {0}},
   {i, 1, Length[grp]}]

In[10]:=
<< "Statistics`"

Here we compute the mean of the z values in each square:

In[11]:=
zavgs = Table[Mean /@ zval[[j]], {j, 1, Length[zval]}]

These are the centers of each square:

In[12]:=
centrs = Table[Table[{xes[[j]] + xes[[j + 1]], yes[[k]] + yes[[k + 1]]}/
     2, {k, 1, Length[yes] - 1}], {j, 1, Length[xes] - 1}]

And these are the triplets (one for each square), corresponding to the
center point in each square and with z value the average of the original
values within the square:

In[13]:=
finData = Flatten[MapThread[Append, {centrs, zavgs}, 2], 1]

So, finally you execute the regression procedure:

In[14]:=
Regress[finData, {1, x, y}, {x, y}]

This seems to work OK.

Tomas Garza
Mexico City



----- Original Message ----- 
From: <Moranresearch at aol.com>
To: mathgroup at smc.vnet.net
Subject: [mg41777] [mg41741] Data preparation and statistics question


> I have a set of data l1={xj,yj,zj} where {j,1,n}
> I would like to group the data into a uniform "grid" comprised of "cells".
> The dimension of a cell would be x_increment by y_increment.
> The center of the cell would be (x + x_increment/2,y + y_increment/2}
> The z value would be the Mean of all z values falling within that cell.
> Once I have this  "conditioned" data I wish to do a multiple regression of
> mean z of cells against x,y values of the center of the cells. Thank you.
>
>



  • Prev by Date: Re: Big problem in solving radicals.
  • Next by Date: Re: structs/records in mathematica
  • Previous by thread: Data preparation and statistics question
  • Next by thread: Re: Data preparation and statistics question