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%3EM%C3%ADnimo%20m%C3%B3vil%20(ventana%20m%C3%B3vil)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-275257%22%20slang%3D%22en-US%22%20mode%3D%22UPDATE%22%3E%3CP%3E%C2%BFAlguien%20sabe%20c%C3%B3mo%20calcular%20un%20m%C3%ADnimo%20m%C3%B3vil%20(o%2C%20de%20hecho%2C%20c%C3%B3mo%20seleccionar%20%3CSPAN%3Ede%20forma%20iterativa%3C%2FSPAN%3E%20X%20n%C3%BAmero%20de%20filas%20de%20retraso%20y%20hacerles%20cualquier%20cosa%2C%20como%20calcular%20un%20m%C3%ADnimo%2C%20un%20m%C3%A1ximo%2C%20un%20rango%2C%20etc.%20En%20este%20ejemplo%20espec%C3%ADfico%20quiero%20volver%20a%20revisarlo%3F%20diga%20las%20%C3%BAltimas%20100%20filas%20y%20obtenga%20el%20valor%20m%C3%ADnimo%2C%20luego%20pase%20a%20la%20siguiente%20fila%20hacia%20abajo%20y%20haga%20lo%20mismo%20nuevamente%20(una%20y%20otra%20vez).%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%3EDise%C3%B1o%20de%20experimentos%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%3A%20m%C3%ADnimo%20m%C3%B3vil%20(ventana%20m%C3%B3vil)%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%20a%20continuaci%C3%B3n%20no%20es%20particularmente%20elegante%2C%20pero%20har%C3%A1%20el%20trabajo.%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%3ESubconfigurar%20los%20datos%20seleccionados%2C%20como%20lo%20hice%2C%20es%20lento.%20Quiz%C3%A1s%20otro%20usuario%20tenga%20una%20mejor%20idea%20de%20c%C3%B3mo%20acceder%20a%20los%20datos%20seleccionados%20y%20extraer%20el%20producto%20deseado.%3C%2FP%3E%3CP%3ETambi%C3%A9n%20me%20pregunto%20c%C3%B3mo%20podr%C3%ADa%20ser%20una%20f%C3%B3rmula%20de%20columna%20para%20lograr%20los%20resultados%20sin%20una%20macro.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESalud%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%3ERe%3A%20m%C3%ADnimo%20m%C3%B3vil%20(ventana%20m%C3%B3vil)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-275287%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EAlgo%20como%20esto%20funcionar%C3%ADa%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