turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Running average by data series using For Loop and ...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Aug 1, 2015 6:23 AM
(864 views)

Hello,

I am running a three-point moving average [MA] in data series of fixed length, and collected at fixed time intervals [i.e., series of 150 data points collected every 30 minutes for weeks at the time]. A traditional MA would merge two data series together, so I ended up adding a new column with data series [incrementing numbers using "Sequence( , , ,)"], and using it as a limiter for the range where the MA should run. The script works and it is quite simple, but I want to use a more effective one.

Is there a way to do this using a For Loop where "i" is the data series ID?

How do I run the same script on multiple columns without having to change the variable name?

This is the script I am currently using:

If( :Time > 1 & :Time < 149, |

Mean(

:T1_F[Row() - 1, Empty()],

:T1_F[Row(), Empty()],

:T1_F[Row() + 1, Empty()],),

.)

Where "T1_F" is my Y variable to smooth, and I have a couple of hundred Y's to smooth.

Any advise would be appreciated.

-JGL

1 REPLY

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Aug 4, 2015 5:00 PM
(522 views)

Hi JGL,

One solution is to build a loop using Eval(Parse(Eval Insert())) to insert your desired columns into a formula. An example script is below.

// Example.

Names Default To Here**(** **1** **)**;

bigClass = Open**(** "$SAMPLE_DATA/Big Class.jmp" **)**;

colList = List**(** :height, :weight **)**; // Columns to create moving averages.

For**(** i = **1**, i <= Length**(** colList **)**, i++,

col = Column**(** colList**[**i**]** **)**;

colName = Concat**(** "MA(", colList**[**i**]** << **Get Name()**, ")" **)**;

Eval**(**

Parse**(**

Eval Insert**(**

"bigClass << New Column( \!"^colName^\!",

Numeric,

Continuous,

Format( \!"Best\!", 12 ),

Formula( Mean( As Column( ^col^ )[Row() -1, Empty()],

As Column( ^col^ )[Row(), Empty()],

As Column( ^col^ )[Row() + 1, Empty()] ) ) );"

**)**

**)**

**)**;

**)**;