hi,
I made a program to get ANOVA for the Regression Analysis.
The program take data from C1 (XList) and C2 (List) (Statistics 2var), so one can do the normal Regression analysis and tests via Statistics and Inference App, and then get other parameters for ANOVA Table from the program itself: test F0 (Fisher) and t (Student) for slope and intercept, SSR, SSE, SST, MSR, MSE, b0 (intercept), b1 (slope), sxx, sxy, p value, r and R^2 (correlation, determination)...
(ANOVA for Regression isn't ANOVA 1 way or ANOVA 2 way)
Code:
export anova_F0_f:={0,0};
export anova_T0_T1_t:={0,0,0};
export anova_ssr_sse_sst:={0,0};
export anova_msr_mse:={0,0};
export anova_b0_b1_sxx_sxy:={0,0,0,0};
export anova_s2:=0;
export anova_r_R2:=0;
export anova_pvalue:=0;
export anova_DF:={0,0};
ANOVA_help();
EXPORT ANOVA_reg()
// ANOVA for REgression Analysis
//use Statistic 2var to input C1 (XList) and C2 (YList)
// by Salvo Micciché 2015
BEGIN
local a, ym, xm, res, sxx, sxy;
local SST, SSR, SSE, MSR, MSE;
local CL:={eval('C1'),eval( 'C2')};
local n, s2, DF, f, F0, p, mesg;
local b0, b1, T0, T1, t, r;
INPUT(a, "ANOVA Significance Level", "Sig. Level α=", "Input α for the test (default value: 0.05)", 0.01, 0.05);
IF (a <=0 OR a>= 1) THEN RETURN("Significance level must be > 0 AND <1"); END;
n:=size(C1); // numerosity
xm:=mean(C1);
ym:= mean(C2); // MeanY
res:= Resid(); // Residues
SSE:=ΣLIST(res^2); // Square Sum of Errors
SST:=ΣLIST((C2-ym)^2); //Square Sum Total
SSR:=SST-SSE; // Square Sum Regression
sxx:= ΣLIST((C1-xm)^2); // Sum of square deviation of x
sxy:=ΣLIST( (C1-xm)*(C2-ym) ); // Sum of crossed product of deviations
b1:=sxy/sxx; // β₁ (Slope)
b0:= ym-b1*xm; // β₀ (Intercept)
s2:=SSE/(n-2); // σ^² variance of the observations of response
MSR:= SSR;
MSE:=SSE/(n-2);
R2:= 1- (SSE/SST); // Determination
r:= b1*sqrt(sxx/SST); // correlation
DF:={1, n-2};
F0:= MSR/MSE; // Test F₀
f:= fisher_icdf(1, n-2, 1-a); // quantile F Fisher Snedecor
p:= 1- fisher_cdf(1, n-2, F0); // pvalue
T0:= b1/(sqrt(s2/sxx)); // Test T₀ (Slope)
T1:= b0/sqrt(s2*((1/n)+xm^2/sxx) ); // Test T₁ (Intercept)
t:= student_icdf(n-2, 1-a/2); // Quantile Student t
sto({"F₀=", F0, "F=", f}, anova_F0_f);
sto({"T₀=", T0, "T₁=", T1, "t=", t}, anova_T0_T1_t);
sto({SSR, SSE, SST}, anova_ssr_sse_sst);
sto({MSR, MSE}, anova_msr_mse);
sto({b0, b1, sxx, sxy}, anova_b0_b1_sxx_sxy);
sto({r, R2}, anova_r_R2);
sto(DF, anova_DF);
sto(s2, anova_s2);
sto(p, anova_pvalue);
MSGBOX( "Test Hypothesis: H₀: β₁=0 vs H₁: β₁ ≠ 0");
IF F0 < f THEN MSGBOX("Test F₀ < F Fisher: Fail to reject H₀ at α=" + eval('a')); END;
IF F0 >= f THEN MSGBOX("Test F₀ > F Fisher: Reject H₀ at α=" + eval('a')); END;
mesg:= "Degrees of freedom: "+ eval( '(1)')+ " and " + eval( 'n-2');
MSGBOX(mesg);
RETURN ("F₀ ="+ F0 + " F = "+ f + " p = " + p);
END;
EXPORT ANOVA_reg_help()
BEGIN
local mesg;
mesg:="ANOVA for Regression Analysis (© Salvo Micciché 2015)
ANOVA(): First use Statistic 2var to input C1 (XList) and C2 (YList),
then input significance level (α)
";
PRINT;
PRINT(mesg);
RETURN("Thanks for using");
END;