Hello,
I am trying to get a function to return a standard deviation calculation stored inside an associative array, my code will only return the expression of the associative array and not the calculation. would you please tell me what is wrong with my code.
cvf= Max(replist);// my cvf in the file is 8
cv=Associative Array();
cv[6]=Associative Array({(Std Dev(5,6,7,8,9,10))});
cv[8]=Associative Array ({(Std Dev(5,6,7,8,9,10,11,12))});
cv[12]=Associative Array ({(Std Dev(5,6,7,8,9,10,11,12,13,14,15,16))});
CVC = Function({ref},Local ({cv = Associative Array({cvf, Eval(cvf)} )},cv << get values(cvf));cv[ref]););
a=CVC(cvf);
eval(eval expr(a));
Show(a);
this is the output that I get:
a = Associative Array({{Std Dev( 5, 6, 7, 8, 9, 10, 11, 12 ), 1}}, 0);
this is the output that I want: a= 2.5
Summarize(age grp) is list of two lists and is not compatible with Associative array(age grp). Also avg and sd are in a single list which is not compatible for cross referencing with Summary(age grp). The code below aligns the lists correctly (not pretty)
Names Default to Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
Summarize( sum = By( :age),sex grp= By (:sex), avg = Mean( :height ), sd = Std Dev( :height ) );
age grp = Associative Array( :age ) << Get Keys;
sex grp = Associative Array( :sex ) << Get Keys;
dt << New Column( "CV" ) << New Column( "AVG" ) << New Column( "SD" );
For( g = 1, g <= nitems(age grp), g++,
For(i =1, i<=nitems(sex grp), i++,
rows = dt << get rows where( :age == age grp[g] & :sex == sex grp[i] );
if( i==1,
:AVG[rows] = avg[ g*2-1 ];
:SD[rows] = sd[ g*2-1 ];
:CV[rows] = 100 * avg[ g*2-1 ] / sd[ g*2-1 ];
,
:AVG[rows] = avg[ g*i ];
:SD[rows] = sd[ g*i ];
:CV[rows] = 100 * avg[ g*i ] / sd[ g*i ];
)));
Thank you, it works