How about combining Col Max (to find the Peak) with Col Moving Average (to stretch the search window)
In addition:
- to mark the peak position, compare individual values with the maximum value
quick & dirty:
- maybe: 2 matches
- maybe [but unlikely]: a wrong match with the max value of another station - for Weekly Weather Data, one has to invest some extra effort:
for every station some weeks are missing - so to search within the correct window, one has to inform Jmp about the missing data via split & stack (works as none of the weeks is completely missing).
dt = Open( "$SAMPLE_DATA/Functional Data/Weekly Weather Data.jmp" );
half_window_size = 2;
dtsplit = dt << Split(
Split By( :week of year ),
Split( :TAVG ),
Group( :STATION ),
Remaining Columns( Drop All )
);
myNames=dt split << get column names();
myNames= myNames[2::Nitems(myNames)];
dtstack = dtsplit <<
Stack(
columns(myNames)
);
New Column( "window",Formula(Col Moving Average( :Data, 1, half_window_size, half_window_size, :STATION )));
New Column( "max_window",Formula( Col Maximum( :window, :STATION ) ));
New Column( "marker",Nominal,Formula( :window == :max_window ));
:Label << Set Data Type(Numeric) << set name ("week of year");
Graph Builder(
Variables(
X( :week of year ),
Y( :Data ),
Y( :window, Position( 1 ) ),
Y( :max_window, Position( 1 ) ),
Group X( :STATION, N View Levels( 1 )),
Overlay( :marker )
),
Elements(
Points( X, Y( 1 ), Overlay( 0 ) ),
Points( X, Y( 2 )),
Smoother( X, Y( 3 ) )
)
)