Subscribe Bookmark RSS Feed

Running average by data series using For Loop and same script on multiple columns

gutloja

Community Trekker

Joined:

Jul 31, 2015

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:

9377_Screen Shot 2015-08-01 at 9.20.43 AM.png

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 ACCEPTED SOLUTION

Accepted Solutions
robot

Community Trekker

Joined:

Feb 27, 2012

Solution

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()] ) ) );"

         )

      )

   );

);

1 REPLY
robot

Community Trekker

Joined:

Feb 27, 2012

Solution

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()] ) ) );"

         )

      )

   );

);