cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
%3CLINGO-SUB%20id%3D%22lingo-sub-275257%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3E%E7%A7%BB%E5%8B%95%E6%9C%80%E5%B0%8F%E5%80%A4%EF%BC%88%E7%A7%BB%E5%8B%95%E3%82%A6%E3%82%A3%E3%83%B3%E3%83%89%E3%82%A6%EF%BC%89%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-275257%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3E%3CP%3E%E7%A7%BB%E5%8B%95%E6%9C%80%E5%B0%8F%E5%80%A4%E3%82%92%E8%A8%88%E7%AE%97%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95%20(%E3%81%BE%E3%81%9F%E3%81%AF%E3%80%81X%20%E5%80%8B%E3%81%AE%E9%81%85%E5%BB%B6%E8%A1%8C%3CSPAN%3E%E3%82%92%E7%B9%B0%E3%82%8A%E8%BF%94%E3%81%97%3C%2FSPAN%3E%E9%81%B8%E6%8A%9E%E3%81%97%E3%81%A6%E3%80%81%E6%9C%80%E5%B0%8F%E5%80%A4%E3%80%81%E6%9C%80%E5%A4%A7%E5%80%A4%E3%80%81%E7%AF%84%E5%9B%B2%E3%81%AA%E3%81%A9%E3%82%92%E8%A8%88%E7%AE%97%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95)%20%E3%82%92%E7%9F%A5%E3%81%A3%E3%81%A6%E3%81%84%E3%82%8B%E4%BA%BA%E3%81%AF%E3%81%84%E3%81%BE%E3%81%9B%E3%82%93%E3%81%8B%E3%80%82%E3%81%93%E3%81%AE%E7%89%B9%E5%AE%9A%E3%81%AE%E4%BE%8B%E3%81%A7%E3%81%AF%E3%80%81%E6%9C%80%E5%BE%8C%E3%81%AE%20100%20%E8%A1%8C%E3%82%92%E3%81%95%E3%81%8B%E3%81%AE%E3%81%BC%E3%81%A3%E3%81%A6%E6%9C%80%E5%B0%8F%E5%80%A4%E3%82%92%E5%8F%96%E5%BE%97%E3%81%97%E3%80%81%E6%AC%A1%E3%81%AE%E8%A1%8C%E3%81%AB%E7%A7%BB%E5%8B%95%E3%81%97%E3%81%A6%E5%90%8C%E3%81%98%E3%81%93%E3%81%A8%E3%82%92%E7%B9%B0%E3%82%8A%E8%BF%94%E3%81%97%E3%81%BE%E3%81%99%20(%E4%BD%95%E5%BA%A6%E3%82%82%E7%B9%B0%E3%82%8A%E8%BF%94%E3%81%97%E3%81%BE%E3%81%99)%E3%80%82%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-275257%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3E%3CLINGO-LABEL%3E%E5%AE%9F%E9%A8%93%E8%A8%88%E7%94%BB%E6%B3%95%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-275272%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%EF%BC%9A%E6%9C%80%E5%B0%8F%E5%80%A4%E3%81%AE%E7%A7%BB%E5%8B%95%EF%BC%88%E3%82%A6%E3%82%A3%E3%83%B3%E3%83%89%E3%82%A6%E3%81%AE%E7%A7%BB%E5%8B%95%EF%BC%89%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-275272%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E4%BB%A5%E4%B8%8B%E3%81%AE%E3%83%9E%E3%82%AF%E3%83%AD%E3%81%AF%E7%89%B9%E3%81%AB%E3%82%A8%E3%83%AC%E3%82%AC%E3%83%B3%E3%83%88%E3%81%A7%E3%81%AF%E3%81%82%E3%82%8A%E3%81%BE%E3%81%9B%E3%82%93%E3%81%8C%E3%80%81%E6%A9%9F%E8%83%BD%E3%81%97%E3%81%BE%E3%81%99%E3%80%82%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3EFor%20(%20i%3D%20100%2C%20i%20%26lt%3B%3D%20N%20Rows%20(%20dt%20)%2C%20i%2B%2B%2C%0A%0A%20dt%20%26lt%3B%26lt%3B%20Select%20Rows%20(Index%20(i-99%2C%20i))%3B%0A%20%0A%20dt%20%26lt%3B%26lt%3B%20Subset(%0A%20Selected%20Rows(%201%20)%2C%0A%20Selected%20Columns%20(%200%20)%2C%0A%20Output%20Table%20(%22out%22)%0A)%3B%0A%0ACurrent%20Data%20Table%20(%20Data%20Table%20(%22out%22))%3B%0A%0Ax%20%3D%20Col%20Minimum%20(%20%3AYourDataColumn%20)%3B%0A%0AClose%20(%20Data%20Table%20(%20%22out%22)%2C%20no%20save)%3B%0A%0AColumn%20(%20%20%22YourMovingWindow%22%20)%5Bi%5D%20%3D%20x%3B%0A%0A)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%E9%81%B8%E6%8A%9E%E3%81%97%E3%81%9F%E3%83%87%E3%83%BC%E3%82%BF%E3%81%AE%E3%82%B5%E3%83%96%E3%82%BB%E3%83%83%E3%83%88%E5%8C%96%E3%80%81%E3%81%A4%E3%81%BE%E3%82%8A%E7%A7%81%E3%81%8C%E8%A1%8C%E3%81%A3%E3%81%9F%E6%96%B9%E6%B3%95%E3%81%AF%E9%81%85%E3%81%84%E3%81%A7%E3%81%99%E3%80%82%E3%81%8A%E3%81%9D%E3%82%89%E3%81%8F%E3%80%81%E5%88%A5%E3%81%AE%E3%83%A6%E3%83%BC%E3%82%B6%E3%83%BC%E3%81%8C%E3%80%81%E9%81%B8%E6%8A%9E%E3%81%97%E3%81%9F%E3%83%87%E3%83%BC%E3%82%BF%E3%81%AB%E3%82%A2%E3%82%AF%E3%82%BB%E3%82%B9%E3%81%97%E3%81%A6%E7%9B%AE%E7%9A%84%E3%81%AE%E8%A3%BD%E5%93%81%E3%82%92%E6%8A%BD%E5%87%BA%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6%E3%82%88%E3%82%8A%E8%89%AF%E3%81%84%E3%82%A2%E3%82%A4%E3%83%87%E3%82%A2%E3%82%92%E6%8C%81%E3%81%A3%E3%81%A6%E3%81%84%E3%82%8B%E3%81%A7%E3%81%97%E3%82%87%E3%81%86%E3%80%82%3C%2FP%3E%3CP%3E%E3%81%BE%E3%81%9F%E3%80%81%E5%88%97%E3%81%AE%E6%95%B0%E5%BC%8F%E3%81%8C%E3%83%9E%E3%82%AF%E3%83%AD%E3%81%AA%E3%81%97%E3%81%A7%E7%B5%90%E6%9E%9C%E3%82%92%E9%81%94%E6%88%90%E3%81%99%E3%82%8B%E3%81%9F%E3%82%81%E3%81%AB%E3%81%A9%E3%81%AE%E3%82%88%E3%81%86%E3%81%AB%E8%A6%8B%E3%81%88%E3%82%8B%E3%81%8B%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6%E3%82%82%E7%96%91%E5%95%8F%E3%81%AB%E6%80%9D%E3%81%84%E3%81%BE%E3%81%99%E3%80%82%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%E4%B9%BE%E6%9D%AF%E3%80%81%3C%2FP%3E%3CP%3E%E3%82%B3%E3%83%95%E3%82%A3%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-275287%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%EF%BC%9A%E6%9C%80%E5%B0%8F%E5%80%A4%E3%81%AE%E7%A7%BB%E5%8B%95%EF%BC%88%E3%82%A6%E3%82%A3%E3%83%B3%E3%83%89%E3%82%A6%E3%81%AE%E7%A7%BB%E5%8B%95%EF%BC%89%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-275287%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E3%81%93%E3%81%AE%E3%82%88%E3%81%86%E3%81%AA%E3%82%82%E3%81%AE%E3%81%AF%E5%8B%95%E4%BD%9C%E3%81%97%E3%81%BE%E3%81%99%E3%81%8B%EF%BC%9F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20default%20to%20here(%201%20)%3B%0Adt%20%3D%20open(%22%24SAMPLE_DATA%5CBig%20Class.jmp%22)%3B%0A%0Adt%20%26lt%3B%26lt%3B%20New%20Column(%22Min%20height%205%20back%22%2C%20%0A%20Formula(%0A%20%20Min(%20%2F%2F%20since%20we%20want%20a%20minumum%20%0A%20%20%20%3Aheight%5B%2F%2F%20the%20column%20we%20want%20the%20minimum%20of%0A%20%20%20%20%2F%2F%20a%20slice%20of%20the%20current%20row%20minus%205%20(minimum%201%20so%20it's%20still%20on%20the%20datatable)%0A%20%20%20%20%2F%2F%20and%20current%20row%0A%20%20%20%20Min(%20Row()%20-%205%20)%3A%3ARow()%20%0A%20%20%20%5D%20%0A%20%20)%0A%20)%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
RVhydrA
Level III

Moving minimum (moving window)

Does anyone know how to calculate a moving minimum (or for that matter how to iteratively select X number of lag rows and do anything to them such as calculate a min, max, range, etc. In this specific example i want to look back over say the last 100 rows and get the minimum value, then move to the next row down and do the same again (over and over). 

1 ACCEPTED SOLUTION

Accepted Solutions
vince_faller
Super User (Alumni)

Re: Moving minimum (moving window)

Would something like this work?

 

Names default to here( 1 );
dt = open("$SAMPLE_DATA\Big Class.jmp");

dt << New Column("Min height 5 back", 
	Formula(
		Min( // since we want a minumum 
			:height[// the column we want the minimum of
				// a slice of the current row minus 5 (minimum 1 so it's still on the datatable)
				// and current row
				Min( Row() - 5 )::Row() 
			] 
		)
	)
);
Vince Faller - Predictum

View solution in original post

2 REPLIES 2
Monomorphist
Level III

Re: Moving minimum (moving window)

The macro below isn't particularly elegant, but will do the job. 

 

For ( i= 100, i <= N Rows ( dt ), i++,

 dt << Select Rows (Index (i-99, i));
 
 dt << Subset(
	Selected Rows( 1 ),
	Selected Columns ( 0 ),
	Output Table ("out")
);

Current Data Table ( Data Table ("out"));

x = Col Minimum ( :YourDataColumn );

Close ( Data Table ( "out"), no save);

Column (  "YourMovingWindow" )[i] = x;

)

Sub-setting the selected data, the way I've done it, is slow. Perhaps another user has a better idea how to access the selected data and extract the desired product.

I also wonder how a column formula could look like to achieve the results without a macro.

 

Cheers,

Kofi

vince_faller
Super User (Alumni)

Re: Moving minimum (moving window)

Would something like this work?

 

Names default to here( 1 );
dt = open("$SAMPLE_DATA\Big Class.jmp");

dt << New Column("Min height 5 back", 
	Formula(
		Min( // since we want a minumum 
			:height[// the column we want the minimum of
				// a slice of the current row minus 5 (minimum 1 so it's still on the datatable)
				// and current row
				Min( Row() - 5 )::Row() 
			] 
		)
	)
);
Vince Faller - Predictum