cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Register for our Discovery Summit 2024 conference, Oct. 21-24, where you’ll learn, connect, and be inspired.
%3CLINGO-SUB%20id%3D%22lingo-sub-87647%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EMedia%20m%C3%B3vil%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-87647%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ETengo%20una%20tabla%20llamada%20medicamentos%20con%20columnas%20medicamento%20y%20resultado%2C%20%C2%BFc%C3%B3mo%20calculo%20el%20promedio%20m%C3%B3vil%20de%20la%20columna%20de%20resultados%20tomando%20las%20primeras%204%20filas%20seguidas%20de%20las%20siguientes%204%20filas%20y%20contin%C3%BAo%20de%20manera%20similar%3F%20Pfa%20la%20tabla%20de%20muestra%20para%20referencia.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-532174%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Promedio%20m%C3%B3vil%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-532174%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ELa%20documentaci%C3%B3n%20de%20soporte%20de%20JMP%20brinda%20antecedentes%20adicionales%20sobre%20c%C3%B3mo%20se%20puede%20definir%20la%20f%C3%B3rmula%20(define%20los%20argumentos%20y%20tambi%C3%A9n%20incluye%20algunos%20peque%C3%B1os%20ejemplos%20agradables)%3A%3CA%20href%3D%22https%3A%2F%2Fwww.jmp.com%2Fsupport%2Fhelp%2Fen%2F16.2%2F%23page%2Fjmp%2Fstatistical-functions-2.shtml%23%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20https%3A%2F%2Fwww.jmp.com%2Fsupport%2Fhelp%2Fen%2F16.2%2F%23page%2Fjmp%2Fstatistical-functions-2.shtml%23%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22PatrickGiuliano_0-1660093800183.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22PatrickGiuliano_0-1660093800183.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22PatrickGiuliano_0-1660093800183.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F44691i32DEE1055F339075%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22PatrickGiuliano_0-1660093800183.png%22%20alt%3D%22PatrickGiuliano_0-1660093800183.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPuedes%20encontrar%20en%20Wikipedia%20(%3CA%20href%3D%22https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FMoving_average%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FMoving_average)%3C%2FA%3E%20m%C3%A1s%20sobre%20los%20primeros%20principios%20y%20la%20comprensi%C3%B3n%20matem%C3%A1tica%2Fconceptual%20detr%C3%A1s%20del%20c%C3%A1lculo%20de%20la%20media%20m%C3%B3vil%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-105084%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Promedio%20m%C3%B3vil%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-105084%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3Egracias%20esto%20funciono%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-105083%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Promedio%20m%C3%B3vil%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-105083%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%C2%BFQu%C3%A9%20significa%20ponderaci%C3%B3n%20%3D%201%2C%20antes%20%3D%203%2C%20%3AMedicamento%3F%3CBR%20%2F%3E%20me%20podrias%20explicar%20la%20formula%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-105082%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Promedio%20m%C3%B3vil%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-105082%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3Eesto%20no%20funcion%C3%B3%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-88024%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Promedio%20m%C3%B3vil%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-88024%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Moving%20average%20dialog.png%22%20style%3D%22width%3A%20373px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Moving%20average%20dialog.png%22%20style%3D%22width%3A%20373px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Moving%20average%20dialog.png%22%20style%3D%22width%3A%20373px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F15002i2532FCBB9DB58BDE%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Moving%20average%20dialog.png%22%20alt%3D%22Moving%20average%20dialog.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3ECreo%20que%20esto%20le%20dar%C3%A1%20el%20promedio%20m%C3%B3vil%20que%20desea%20(4%20filas%20antes%20y%204%20filas%20despu%C3%A9s).%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-87746%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Promedio%20m%C3%B3vil%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-87746%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ELa%20f%C3%B3rmula%20a%20utilizar%20es%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3EIf(%20Mod(%20Row()%2C%204%20)%20%3D%3D%200%2C%0A%20Mean(%20%3AResult%5BIndex(%20Row()%20-%203%2C%20Row()%20)%5D%20)%0A)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EAdjunt%C3%A9%20su%20tabla%20de%20datos%20de%20ejemplo%2C%20con%20una%20nueva%20columna%20con%20la%20f%C3%B3rmula.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22drugs.PNG%22%20style%3D%22width%3A%20512px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22drugs.PNG%22%20style%3D%22width%3A%20512px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22drugs.PNG%22%20style%3D%22width%3A%20512px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F15001i63F40F710CA32DDB%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22drugs.PNG%22%20alt%3D%22drugs.PNG%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-87744%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Promedio%20m%C3%B3vil%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-87744%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EQuiero%20generar%20la%20columna%20de%20promedio%20m%C3%B3vil%20como%20se%20muestra%20en%20la%20tabla%20adjunta%2C%20por%20cada%204%20filas%20necesito%20calcular%20el%20promedio%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-87743%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Promedio%20m%C3%B3vil%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-87743%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%C2%BFTiene%204%20columnas%20de%20resultados%20o%204%20veces%20m%C3%A1s%20filas%20de%20las%20que%20muestra%20en%20su%20tabla%20de%20datos%20de%20muestra%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-87741%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Promedio%20m%C3%B3vil%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-87741%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%C2%BFPodr%C3%ADa%20explicar%20el%20siguiente%20paso%20despu%C3%A9s%20de%20esto%3F%20Quiero%20calcular%20el%20promedio%20de%204%20muestras%20consecutivas.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-87662%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Promedio%20m%C3%B3vil%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-87662%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ECree%20una%20nueva%20columna%20en%20su%20tabla%20de%20datos%20y%20aplique%20la%20siguiente%20f%C3%B3rmula%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ECol%20Moving%20Average(%20%3AResult%2C%20weighting%20%3D%201%2C%20before%20%3D%203%2C%20%3ADrug%20)%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-87661%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Promedio%20m%C3%B3vil%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-87661%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EHola%20%2C%3C%2FP%3E%3CP%3Epuede%20probar%20con%20la%20columna%20F%C3%B3rmula%20-%26gt%3B%20fila%20-%26gt%3B%20promedio%20m%C3%B3vil%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22moving.jpg%22%20style%3D%22width%3A%20908px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22moving.jpg%22%20style%3D%22width%3A%20908px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22moving.jpg%22%20style%3D%22width%3A%20908px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F14982i470944843464D147%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22moving.jpg%22%20alt%3D%22moving.jpg%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
jojmp
Level III

Moving Average

I have a table called drugs with columns drug and result, how do I calculate the moving average of the result column by taking the first 4 rows followed by the next 4 rows and similarly continue. Pfa the sample table for reference. 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Moving Average

The formula to use is

If( Mod( Row(), 4 ) == 0,
	Mean( :Result[Index( Row() - 3, Row() )] )
)

I have attached your example data table, with a new column with the formula in it

drugs.PNG

Jim

View solution in original post

11 REPLIES 11
gianpaolo
Level IV

Re: Moving Average

hello ,

you can try with Formula column --> row --> moving average

 

moving.jpg

Gianpaolo Polsinelli
jojmp
Level III

Re: Moving Average

Could you please explain the next step after this, I want to calculate the average of 4 consecutive samples
txnelson
Super User

Re: Moving Average

Do you have 4 columns of results, or 4 times as many rows as you show in your sample data table?
Jim
jojmp
Level III

Re: Moving Average

I want to generate the moving average column as shown in the attached table, for every 4 rows I need to calculate the average

txnelson
Super User

Re: Moving Average

The formula to use is

If( Mod( Row(), 4 ) == 0,
	Mean( :Result[Index( Row() - 3, Row() )] )
)

I have attached your example data table, with a new column with the formula in it

drugs.PNG

Jim
jojmp
Level III

Re: Moving Average

Thanks this worked
Phil_Kay
Staff

Re: Moving Average

Moving average dialog.png

I think this will give you the moving average that you want (4 rows before and 4 rows after).

jojmp
Level III

Re: Moving Average

this did not work
txnelson
Super User

Re: Moving Average

Create a new column in your data table, and apply the folloing formula

Col Moving Average( :Result, weighting = 1, before = 3, :Drug )
Jim