Message Boards Message Boards

0
|
4964 Views
|
1 Reply
|
2 Total Likes
View groups...
Share
Share this post:

Problem averaging multiple series of data

Hi,

Recently I'm having trouble figuring out a certain problem in Mathematica. I have a table of data in the following arrangement:

{series no., x, y}

Now, each series of data has exactly the same x values, with different y. What I am trying to achieve is averaging the y values for all series of data for each x, so that the final table looks like this:

{x, average y}

Do you have any ideas on how to solve it efficiently?

POSTED BY: Igor Wlasny

Time series approach:

series1 = Table[{i, y1[i]}, {i, 1, 10}];
series2 = Table[{i, y2[i]}, {i, 1, 10}];
series3 = Table[{i, y3[i]}, {i, 1, 10}];

Create multivariate TemporalData with y's component and x's as times:

td = TemporalData[
  Transpose@{series1[[All, 2]], series2[[All, 2]], 
    series3[[All, 2]]}, {series1[[All, 1]]}, ValueDimensions -> 3];

td["Paths"]

Out[30]= {{{1, {y1[1], y2[1], y3[1]}}, {2, {y1[2], y2[2], y3[2]}}, {3, {y1[3], y2[3], y3[3]}}, {4, {y1[4], y2[4], y3[4]}}, {5, {y1[5], y2[5], y3[5]}}, {6, {y1[6], y2[6], y3[6]}}, {7, {y1[7], y2[7], y3[7]}}, {8, {y1[8], y2[8], y3[8]}}, {9, {y1[9], y2[9], y3[9]}}, {10, {y1[10], y2[10], y3[10]}}}}

Now map the mean over each vector of y values for each value of x:

res = TimeSeriesMap[Mean, td];

res["Path"]

Out[33]= {{1, 1/3 (y1[1] + y2[1] + y3[1])}, {2, 1/3 (y1[2] + y2[2] + y3[2])}, {3, 1/3 (y1[3] + y2[3] + y3[3])}, {4, 1/3 (y1[4] + y2[4] + y3[4])}, {5, 1/3 (y1[5] + y2[5] + y3[5])}, {6, 1/3 (y1[6] + y2[6] + y3[6])}, {7, 1/3 (y1[7] + y2[7] + y3[7])}, {8, 1/3 (y1[8] + y2[8] + y3[8])}, {9, 1/3 (y1[9] + y2[9] + y3[9])}, {10, 1/3 (y1[10] + y2[10] + y3[10])}}

POSTED BY: Gosia Konwerska
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract