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%3EMinimo%20mobile%20(finestra%20mobile)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-275257%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3E%3CP%3EQualcuno%20sa%20come%20calcolare%20un%20minimo%20mobile%20(o%20del%20resto%20come%20selezionare%20%3CSPAN%3Ein%20modo%20iterativo%3C%2FSPAN%3E%20il%20numero%20X%20di%20righe%20di%20ritardo%20e%20fare%20qualcosa%20su%20di%20loro%20come%20calcolare%20un%20minimo%2C%20un%20massimo%2C%20un%20intervallo%2C%20ecc.%20In%20questo%20esempio%20specifico%20voglio%20guardare%20indietro%20pronuncia%20le%20ultime%20100%20righe%20e%20ottieni%20il%20valore%20minimo%2C%20quindi%20passa%20alla%20riga%20successiva%20e%20fai%20di%20nuovo%20la%20stessa%20cosa%20(ancora%20e%20ancora).%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%3EProgettazione%20di%20esperimenti%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%3ERi%3A%20minimo%20mobile%20(finestra%20mobile)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-275272%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ELa%20macro%20di%20seguito%20non%20%C3%A8%20particolarmente%20elegante%2C%20ma%20far%C3%A0%20il%20lavoro.%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%3ELa%20subimpostazione%20dei%20dati%20selezionati%2C%20come%20ho%20fatto%2C%20%C3%A8%20lenta.%20Forse%20un%20altro%20utente%20ha%20un'idea%20migliore%20su%20come%20accedere%20ai%20dati%20selezionati%20ed%20estrarre%20il%20prodotto%20desiderato.%3C%2FP%3E%3CP%3EMi%20chiedo%20anche%20come%20potrebbe%20essere%20una%20formula%20di%20colonna%20per%20ottenere%20i%20risultati%20senza%20una%20macro.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESaluti%2C%3C%2FP%3E%3CP%3EKofi%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-275287%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERi%3A%20minimo%20mobile%20(finestra%20mobile)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-275287%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EQualcosa%20del%20genere%20funzionerebbe%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