Post Reply 
Chi square test for variance
03-19-2015, 03:09 PM (This post was last modified: 03-20-2015 12:20 PM by salvomic.)
Post: #2
RE: Chi square test for variance
my first propose is this one.

chi2_variance()
It calc X² test and compare with χ² (saying if H₀ is to be reject or not), then calc also p value and confidence interval...
If you have other idea for improvement, please, suggest...

Code:

export chi_var_test:={"",0,"",0};
export chi_var_pvalue:=0;
export chi_var_dfreedom:=0;
export chi_var_intconf:={"",  0, "", 0};

EXPORT chi2_variance()
BEGIN
// Chi-square test for variances (H₀: σ²=σ₀² / H₁: σ² ≠ σ₀²)
local a:=0.05 ,n:=2,  s:=1, si:=1, XT, chi, p;
local mesg, icl, icu, control:=1;

REPEAT
INPUT({a, n, s, si}, "Chi-square Variance test", {"Signif. level α=", "Sample size n=", "Sample var s²=", "Popul. var σ₀²="}, 
{"Significance level α (default 0.05)", "Sample size", "Observed Sample Variance  s²", "Population Variation σ₀²"},{0.01, 2, 1, 1}, {a, n,  s, si});
CASE
IF (a <=0 OR a>= 1) THEN MSGBOX("Significance level must be > 0 AND <1"); control:=1; a:=0.05; END;
IF (n<2) THEN MSGBOX("Sample numerosity must be >=2"); control:=1; n:=2; END;
IF (s<0) THEN MSGBOX("Sample Variance must be >= 0"); control:=1; s:=1; END;
IF (si<=0) THEN MSGBOX("Population Variance must be > 0"); control:=1; si:=1; END;
DEFAULT control:= 0;
END; // case
UNTIL control < 1;

XT:=((n-1)*(s))/(si);  // test=(n-1)s²/σ²
chi:=chisquare_icdf(n-1,1-a);
p:= 1- chisquare_cdf(n-1, XT);
icl:= s*(n-1)/chisquare_icdf(n-1,1-a);
icu:= s*(n-1)/chisquare_icdf(n-1,a);

MSGBOX( "Test Hypothesis: H₀: σ²=σ₀² vs H₁: σ² ≠ σ₀²");
IF XT<chi THEN MSGBOX("Test X² < χ²: Fail to reject H0 at α=" + eval('a')); END;
IF XT >= chi THEN MSGBOX("Test X² > χ²: Reject H0 at α=" + eval('a')); END;
mesg:= "Degrees of freedom: "+ eval( '(n-1)');
MSGBOX(mesg);

sto({"X²", XT," χ²",  chi}, chi_var_test);
sto(p, chi_var_pvalue);
sto(n-1, chi_var_dfreedom);
sto({"lower", icl, "upper", icu}, chi_var_intconf);

RETURN("Test XT=" + XT+" (χ²="+ chi + ")  p=" + p);
END;

Also, please, help: is it possible to display results graphically as in Inference in a normal program (not an App)?
or help me to make ...an App Smile
I would indeed "mimic" the output of Inference...

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Chi square test for variance - salvomic - 03-19-2015, 11:53 AM
RE: Chi square test for variance - salvomic - 03-19-2015 03:09 PM
RE: Chi square test for variance - parisse - 03-20-2015, 06:55 AM
RE: Chi square test for variance - Anders - 03-20-2015, 04:50 PM



User(s) browsing this thread: 2 Guest(s)