RPGIV @ Work

A unique site for RPG and System i Lovers

Welcome!

Hi, this site will provide all what you need in System i and RPG developments.

My Name is Chamara Withanachchi, System i Expert and RPG Developer. And in the field for last 11 years.

I hope you will find lot of valuable information from this site

Mean Absolute Deviation Print E-mail
User Rating: / 1
PoorBest 
Written by Chamara Withanachchi   

Assuming you mean MAD as defined by www.xycoon.com/mad.htm, here's an RPG procedure to compute it. Note that although it compiles, I haven't actually tried it with real data. I'll leave the debugging (and conversion to a release prior to V5R3) up to you.



	P mad             b                   export
	D mad             pi             8f
	D   data                         8f   dim(1000) options(*varsize)
	D   num                         10i 0 value
	D sum             s              8f
	D avg             s              8f
	D i               s             10i 0
 	/free
    	// compute average
    	avg = %xfoot(%subarr(data:1:num)) / num; 
	
    	// Compute sum of absolute deviations
    	sum = 0;
    	for i = 1 to num;
       		sum += %abs(data(i)-avg);
    	endfor;
 
    	// return mean average absolute devation
    	return sum / num;
 	/end-free
	P mad             e


User Comments

Please login or register to add comments

<Previous   Next>