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%EC%9D%B4%EB%8F%99%20%EC%B5%9C%EC%86%8C%EA%B0%92(%EC%9D%B4%EB%8F%99%20%EC%B0%BD)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-275257%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3E%3CP%3E%EC%9D%B4%EB%8F%99%20%EC%B5%9C%EC%86%8C%EA%B0%92%EC%9D%84%20%EA%B3%84%EC%82%B0%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95(%EB%98%90%EB%8A%94%20X%EA%B0%9C%EC%9D%98%20%EC%A7%80%EC%97%B0%20%ED%96%89%EC%9D%84%20%3CSPAN%3E%EB%B0%98%EB%B3%B5%EC%A0%81%EC%9C%BC%EB%A1%9C%3C%2FSPAN%3E%20%EC%84%A0%ED%83%9D%ED%95%98%EA%B3%A0%20%EC%B5%9C%EC%86%8C%EA%B0%92%2C%20%EC%B5%9C%EB%8C%80%EA%B0%92%2C%20%EB%B2%94%EC%9C%84%20%EB%93%B1%EC%9D%84%20%EA%B3%84%EC%82%B0%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95)%EC%9D%84%20%EC%95%84%EB%8A%94%20%EC%82%AC%EB%9E%8C%EC%9D%B4%20%EC%9E%88%EC%8A%B5%EB%8B%88%EA%B9%8C%3F%20%EC%9D%B4%20%ED%8A%B9%EC%A0%95%20%EC%98%88%EC%97%90%EC%84%9C%EB%8A%94%20%EB%8B%A4%EC%8B%9C%20%EC%82%B4%ED%8E%B4%EB%B3%B4%EA%B3%A0%20%EC%8B%B6%EC%8A%B5%EB%8B%88%EB%8B%A4.%20%EB%A7%88%EC%A7%80%EB%A7%89%20100%EA%B0%9C%20%ED%96%89%EC%9D%84%20%EB%A7%90%ED%95%98%EA%B3%A0%20%EC%B5%9C%EC%86%8C%EA%B0%92%EC%9D%84%20%EC%96%BB%EC%9D%80%20%EB%8B%A4%EC%9D%8C%20%EC%95%84%EB%9E%98%EC%9D%98%20%EB%8B%A4%EC%9D%8C%20%ED%96%89%EC%9C%BC%EB%A1%9C%20%EC%9D%B4%EB%8F%99%ED%95%98%EA%B3%A0%20%EB%8F%99%EC%9D%BC%ED%95%9C%20%EC%9E%91%EC%97%85%EC%9D%84%20%EB%8B%A4%EC%8B%9C%20%EB%B0%98%EB%B3%B5%ED%95%A9%EB%8B%88%EB%8B%A4.%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%EC%8B%A4%ED%97%98%20%EC%84%A4%EA%B3%84%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%3E%EC%9E%AC%20%3A%20%EC%B5%9C%EC%86%8C%20%EC%9D%B4%EB%8F%99%20(%EC%9D%B4%EB%8F%99%20%EC%B0%BD)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-275272%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%EC%95%84%EB%9E%98%EC%9D%98%20%EB%A7%A4%ED%81%AC%EB%A1%9C%EB%8A%94%20%ED%8A%B9%EB%B3%84%ED%9E%88%20%EC%9A%B0%EC%95%84%ED%95%98%EC%A7%80%EB%8A%94%20%EC%95%8A%EC%A7%80%EB%A7%8C%20%EC%9E%91%EC%97%85%EC%9D%84%20%EC%88%98%ED%96%89%ED%95%A9%EB%8B%88%EB%8B%A4.%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%EB%82%B4%EA%B0%80%20%ED%95%9C%20%EB%B0%A9%EC%8B%9D%EC%9C%BC%EB%A1%9C%20%EC%84%A0%ED%83%9D%ED%95%9C%20%EB%8D%B0%EC%9D%B4%ED%84%B0%EC%9D%98%20%ED%95%98%EC%9C%84%20%EC%84%A4%EC%A0%95%EC%9D%B4%20%EB%8A%90%EB%A6%BD%EB%8B%88%EB%8B%A4.%20%EB%8B%A4%EB%A5%B8%20%EC%82%AC%EC%9A%A9%EC%9E%90%EA%B0%80%20%EC%84%A0%ED%83%9D%ED%95%9C%20%EB%8D%B0%EC%9D%B4%ED%84%B0%EC%97%90%20%EC%95%A1%EC%84%B8%EC%8A%A4%ED%95%98%EA%B3%A0%20%EC%9B%90%ED%95%98%EB%8A%94%20%EC%A0%9C%ED%92%88%EC%9D%84%20%EC%B6%94%EC%B6%9C%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%84%20%EB%8D%94%20%EC%9E%98%20%EC%95%8C%EA%B3%A0%EC%9E%88%EC%9D%84%20%EA%B2%83%EC%9E%85%EB%8B%88%EB%8B%A4.%3C%2FP%3E%3CP%3E%EB%98%90%ED%95%9C%20%EC%97%B4%20%EC%88%98%EC%8B%9D%EC%9D%B4%20%EB%A7%A4%ED%81%AC%EB%A1%9C%EC%97%86%EC%9D%B4%20%EA%B2%B0%EA%B3%BC%EB%A5%BC%20%EC%96%BB%EB%8A%94%20%EA%B2%83%EC%B2%98%EB%9F%BC%20%EB%B3%B4%EC%9D%BC%20%EC%88%98%20%EC%9E%88%EB%8A%94%EC%A7%80%20%EA%B6%81%EA%B8%88%ED%95%A9%EB%8B%88%EB%8B%A4.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%EA%B1%B4%EB%B0%B0%2C%3C%2FP%3E%3CP%3E%EC%BD%94%ED%94%BC%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-275287%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%EC%9E%AC%20%3A%20%EC%B5%9C%EC%86%8C%20%EC%9D%B4%EB%8F%99%20(%EC%9D%B4%EB%8F%99%20%EC%B0%BD)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-275287%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%EC%9D%B4%EB%9F%B0%20%EC%8B%9D%EC%9C%BC%EB%A1%9C%20%EC%9E%91%EB%8F%99%ED%95%A9%EB%8B%88%EA%B9%8C%3F%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