Post Reply 
Chi square test for variance
03-19-2015, 11:53 AM (This post was last modified: 03-19-2015 10:05 PM by salvomic.)
Post: #1
Chi square test for variance
Hi all,
in Prime Inference App we have to tests for Chi2 (chi square): Goodness of Fit and 2-way-test...
However I need to calc chi2 test having only s^2 and σ^2 (H_0: σ^2 = value, H_1: σ^2 ≠ value)

(i.e. s^2 = 0.0153, σ^2 = 0.01, n=20)
the test to confront with chi-square should be
\[ X_{0}^{2}= \frac{(n-1)s^{2}}{σ_{0}^{2}} \]

(for my data I should have X^2= 29.07 against chi-square(19,1-0.05)=30.14 and then reject H_0)...

Can I do something already with Inference app?
If not I hope to see also this test Chi2 for variance added in Inference App (chi2 test section) in a next upgrade of the firmware... :-)

Thank you

Salvo

∫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
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
03-19-2015, 09:42 PM
Post: #3
RE: Chi square test for variance
I agree, this would be very useful to have Hypothesis Testing and Confidence Intervals for standard deviation/variance for 1 and 2 sample cases.

Interestingly, the TI84+ and Nspire calculators have the 2 sample F-Test for standard deviation, but none of the other standard deviation Intervals or Tests. That always struck me as being odd to leave certain ones out.

-wes
Find all posts by this user
Quote this message in a reply
03-19-2015, 10:03 PM
Post: #4
RE: Chi square test for variance
(03-19-2015 09:42 PM)Wes Loewer Wrote:  I agree, this would be very useful to have Hypothesis Testing and Confidence Intervals for standard deviation/variance for 1 and 2 sample cases.

Interestingly, the TI84+ and Nspire calculators have the 2 sample F-Test for standard deviation, but none of the other standard deviation Intervals or Tests. That always struck me as being odd to leave certain ones out.

-wes

Indeed, Wes, you're right.

∫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
03-19-2015, 10:45 PM (This post was last modified: 03-19-2015 10:47 PM by salvomic.)
Post: #5
RE: Chi square test for variance
Another improvement for Inference could be Prediction Interval (not Confidence Interval) having mean x̅ (x_bar) and standard deviation of the sample, s...

For now in Inference there is only Regression -> Prediction Interval, but this estimation need to have two lists: Xlist and Ylist...

∫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
03-20-2015, 06:55 AM
Post: #6
RE: Chi square test for variance
Xcas has the following commands for tests:
- chisquaret (chi2 test)
- normalt (normal)
- studentt (Student)
- kolmogorovt (K.-Smirnov)
- wilcoxont (Wilcoxon)

chisquaret takes 2 args: 2 samples or 1 sample and a distribution law (i.e. you can test adequation with more distributions than just the normal distribution).

I don't think these commands are inside the Prime right now, might be an interesting addition...
Find all posts by this user
Quote this message in a reply
03-20-2015, 10:20 AM
Post: #7
RE: Chi square test for variance
(03-20-2015 06:55 AM)parisse Wrote:  Xcas has the following commands for tests:
- chisquaret (chi2 test)
- normalt (normal)
- studentt (Student)
- kolmogorovt (K.-Smirnov)
- wilcoxont (Wilcoxon)

chisquaret takes 2 args: 2 samples or 1 sample and a distribution law (i.e. you can test adequation with more distributions than just the normal distribution).

I don't think these commands are inside the Prime right now, might be an interesting addition...

thank you Parisse,
I agree: why not include those (of some of them) tests in Prime?
Especially in Inference app...

Salvo

∫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
03-20-2015, 04:50 PM
Post: #8
RE: Chi square test for variance
Kolmogorov-Smirnov test and Student test are also important and are used a lot so as parisse suggested it would be a great addition to include the whole patrisse's list of test:
- chisquaret (chi2 test)
- normalt (normal)
- studentt (Student)
- kolmogorovt (K.-Smirnov)
- wilcoxont (Wilcoxon)
Find all posts by this user
Quote this message in a reply
03-20-2015, 10:26 PM
Post: #9
RE: Chi square test for variance
(03-20-2015 04:50 PM)Anders Wrote:  Kolmogorov-Smirnov test and Student test are also important and are used a lot so as parisse suggested it would be a great addition to include the whole patrisse's list of test:
- chisquaret (chi2 test)
- normalt (normal)
- studentt (Student)
- kolmogorovt (K.-Smirnov)
- wilcoxont (Wilcoxon)

yes, Anders, I agree!

Another thing I think it should be included in Inference: Test F for variances of two population: here there is my proposal...

∫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 




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