/* ANOVA - One Way */ options results if ~show('P','TCALC') then do address command 'run sys:turbocalc/turbocalc' address command 'waitforport TCALC' loadflag=1 end address 'TCALC' /* Add-in Rexx Libraries needed for some routines */ signal on syntax if ~show('l','rexxmathlib.library') then call addlib('rexxmathlib.library',0,-30) /* add to library list */ if ~show('l','rexxreqtools.library') then call addlib('rexxreqtools.library',0,-30) signal off syntax /* Start Main Routine */ if loadflag=1 then 'Load()' 'ActivateWindow()' ;'LiesCursorPos' range=rtgetstring(,"Enter Cell Range for Input","Input Request",,'rt_pubscrname="TurboCalc"') colon=pos(":",range) if colon=0 then do 'Message "Please select a range~before executing this script"' exit end /* Find cell references and cell, column numbers */ start_cell=substr(range,1,colon-1) end_cell=substr(range,colon+1) start_row=cellrow(start_cell) end_row=cellrow(end_cell) start_col=cellcol(start_cell) end_col=cellcol(end_cell) NRows=end_row-start_row+1 NCols=end_col-start_col+1 /* Get cell reference for output range */ out_cell=rtgetstring(,"Enter Cell Reference for Output","Input Request",,'rt_pubscrname="TurboCalc"') if out_cell="" then exit if length(out_cell)<2 | datatype(left(out_cell,1),'n') then do 'Message "Invalid cell reference"' exit end /* Suppress Screen Redraw to Speed Things Up */ 'Refresh 0' /* Get cell references for top cell in each column */ 'SelectCell' start_cell do col=start_col to end_col 'GetCursorPos' top_cell.col=result 'Column' 1 end /* Get labels for later use on output */ 'SelectCell' start_cell 'GetValue' testlabel=result testlabel=strip(testlabel) if datatype(testlabel,'a')=1 then do labelflag=0 do x=1 to NCols title.x="Column "||x end end else do labelflag=1 do x=1 to NCols 'GetValue' title.x=result 'Column 1' end end /* Get data from cell range */ col=start_col lav=0 tot=0 count.=0 total.=0 do x=1 to NCols 'SelectCell' top_cell.col if labelflag=1 then 'Down 1' if labelflag=0 then NRows=NRows+1 do y=1 to NRows-1 'GetValue' valtest=result if datatype(valtest)='NUM' then do 'GetValue' val=result data.x.y=val tot=tot+val total.x=tot count.x=1+count.x end 'Down 1' end col=col+1 tot=0 lav=0 val=0 end /* Calculate Means */ mean.=0 do x=1 to NCols mean.x=total.x/count.x end /* Calculate Standard deviation and Variance */ dat=0 meenx=0 sum.=0 sum3.=0 sum4.=0 sd.=0 var.=0 m2.=0 m3.=0 m4.=0 do x=1 to NCols sum.x=0 sum3.x=0 sum4.x=0 meenx=mean.x do y =1 to count.x dat=data.x.y sum.x=(dat-meenx)**2+(sum.x) sum3.x=(dat-meenx)**3+(sum3.x) sum4.x=(dat-meenx)**4+(sum4.x) end N=(count.x)-1 var.x=(sum.x)/N sd.x=sqrt(var.x) m2.x=(sum.x)/(count.x) m3.x=(sum3.x)/(count.x) m4.x=(sum4.x)/(count.x) end /* Calculate Totals */ TN.=0 sumTN=0 GrandTotal=0 NumObs=0 TNG=0 Do x=1 to NCols NumObs=NumObs+count.x GrandTotal=GrandTotal+total.x TN.x=((total.x)**2)/count.x SumTN=SumTN+TN.x end TNG=(GrandTotal**2)/NumObs /* Calculate Sum of Squares */ SS.=0 SSTotal=0 SSBN=0 SSWN=0 SST=0 do x=1 to NCols do y=1 to count.x SS.x=((data.x.y)**2)+SS.x end SSTotal=SSTotal+SS.x end SSBN=SumTN-TNG /* Sum of Squares Between */ SSWN=SSTotal-SumTN /* Sum of Squares Within */ SST=SSTotal-TNG /* Total Sum of Squares */ /* Calculate Variances */ DFW=NumObs-NCols /* Degrees of Freedom Within */ DFB=NCols-1 /* Degrees of Freedom Between */ DFT=NumObs-1 /* Degress of Freedom for Total */ VarB=SSBN/DFB /* Variance Estimate for Between */ VarW=SSWN/DFW /* Variance Estimate for Within */ VarT=VarB/VarW /* F Ratio for Total */ /* Output */ 'SelectCell' out_cell 'ColumnWidth 15' 'Put "ANOVA - One Way"' 'Down 2' 'Put' "Group" 'Column 1' 'ColumnWidth 10' 'Put' "Count" 'Column 1' 'ColumnWidth 5' 'Put' "Total" 'Column 1' 'ColumnWidth 12' 'Put' "Mean" 'Column 1' 'ColumnWidth 10' 'Put' "Variance" 'SelectCell' out_cell 'Down 3' do x=1 to NCols 'GetCursorPos' first_cell.x=result title=""""||title.x||"""" 'Put' title 'Down 1' end Do x=1 to NCols 'SelectCell' first_cell.x 'Column 1' 'Put' count.x 'Column 1' 'Put' total.x 'Column 1' 'Put' mean.x 'Column 1' 'Put' var.x end 'SelectCell' first_cell.NCols 'Down 1' 'Down 1' 'Put' "ANOVA" 'Down 1' 'Put "Source of Variation"' 'GetCursorPos' Go_cell=result 'Column 1' 'Put' "SS" 'Column 1' 'Put' "df" 'Column 1' 'Put "Variance Est."' 'Column 1' 'Put' "F-Ratio" 'SelectCell' Go_cell 'Down 2' 'Put "Between Groups"' 'Down 1' 'Put "Within Groups"' 'Down 1' 'Put' "Total" 'SelectCell' Go_cell 'Down 2' 'Column 1' 'Put' SSBN 'Down 1' 'Put' SSWN 'Down 1' 'Put' SST 'Up 2' 'Column 1' 'Put' DFB 'Down 1' 'Put' DFW 'Down 1' 'Put' DFT 'Up 2' 'Column 1' 'Put' VarB 'Down 1' 'Put' VarW 'Up 1' 'Column 1' 'Put' VarT 'Refresh 1' 'Refresh 2' 'Message' "Finished" exit /* Procedures */ cellrow: procedure do parse arg cell do charpos=2 to length(cell) if datatype(substr(cell,charpos,1),n) then return substr(cell,charpos) end return 0 end Return cellcol: procedure do parse arg cell labels="ABCDEFGHIJKLMNOPQRSTUVWXYZ" cell=upper(cell) len=length(cell) val=0 do charpos=1 to len if datatype(substr(cell,charpos,1),n) then do cell=reverse(substr(cell,1,charpos-1)) do x=1 to length(cell) val=(26**(x-1))*pos(substr(cell,x,1),labels)+val end return val end end return 0 end Return syntax: if arg(1)='FAIL' then do 'Message "Library is unavailable."' exit end 'Message "Unknown Syntax Error"' exit