‎2006 Nov 30 10:36 AM
Hi ,
Is there any function module to calculate mean and standard deviation.
Very urgent
Points will be rewarded
‎2006 Nov 30 11:09 AM
data : begin of it occurs 1,
num type p,
x_xbar type p,
end of it.
data : num1 type p value 10.
data : tot type p,l(2),
total type p. " E(x - mean)^2
data : mean type p.
data : var type p,
sd type p.
do 5 times .
it-num = num1.
append it.
num1 = num1 + 10.
enddo.
loop at it .
tot = tot + it-num.
endloop.
describe table it lines l.
mean = tot / l.
loop at it .
it-x_xbar = ( it-num - mean ) * ( it-num - mean ).
total = total + it-x_xbar.
endloop.
var = ( total ) / ( l - 1 ).
sd = SQRT( var ).
write : sd.
regards,
aswin.
‎2006 Nov 30 10:41 AM
There is no FM...Check below code...
1. say it_numbers is ur internal table with the numbers and num is ur field
2. loop ai it_numbers.
total = total + it_numbers-num.
v_var1 = it_numbers-num * it_numbers-num.
v_var2 = var2 + v_var1.
endloop.
describe table it_numbers lines v_lines.
mean = total / v_lines.
v_var3 = mean * mean.
standard deviation = (v_var2 - v_var3)/(N*N - N).
‎2006 Nov 30 10:44 AM
Hi,
Check this function module : RRT_MATH_STDDEV
Example of using the function module:
DATA val TYPE RRT3_T_VAL.
DATA wa TYPE LINE OF RRT3_T_VAL.
DATA stddev TYPE RRT3_FLOAT.
wa-index = 1.
wa-float = '4'.
APPEND wa TO val.
wa-index = 2.
wa-float = '9'.
APPEND wa TO val.
wa-index = 3.
wa-float = '11'.
APPEND wa TO val.
wa-index = 4.
wa-float = '12'.
APPEND wa TO val.
wa-index = 5.
wa-float = '17'.
APPEND wa TO val.
wa-index = 6.
wa-float = '5'.
APPEND wa TO val.
wa-index = 7.
wa-float = '8'.
APPEND wa TO val.
wa-index = 8.
wa-float = '12'.
APPEND wa TO val.
wa-index = 9.
wa-float = '14'.
APPEND wa TO val.
CALL FUNCTION 'RRT_MATH_STDDEV'
EXPORTING
i_t_val = val
IMPORTING
E_STDDEV = stddev
.
Regards
Wenceslaus
‎2006 Nov 30 11:09 AM
data : begin of it occurs 1,
num type p,
x_xbar type p,
end of it.
data : num1 type p value 10.
data : tot type p,l(2),
total type p. " E(x - mean)^2
data : mean type p.
data : var type p,
sd type p.
do 5 times .
it-num = num1.
append it.
num1 = num1 + 10.
enddo.
loop at it .
tot = tot + it-num.
endloop.
describe table it lines l.
mean = tot / l.
loop at it .
it-x_xbar = ( it-num - mean ) * ( it-num - mean ).
total = total + it-x_xbar.
endloop.
var = ( total ) / ( l - 1 ).
sd = SQRT( var ).
write : sd.
regards,
aswin.
‎2006 Dec 13 11:00 PM
Do you have an APO system?
SAP delivers function modules to support macros that perform the statistical calcuations. /SAPAPO/STDEV is an example. Not sure if the code here is any different than the proposed solutions, but there are modules available.
Michael