ChiSquare Test 2 X Test of Goodness of

  • Slides: 16
Download presentation
Chi-Square Test -- 2 X Test of Goodness of Fit 1

Chi-Square Test -- 2 X Test of Goodness of Fit 1

(Pseudo) Random Numbers o o o Uniform: values conform to a uniform distribution Independent:

(Pseudo) Random Numbers o o o Uniform: values conform to a uniform distribution Independent: probability of observing a particular value is independent of the previous values Should always test uniformity 2

Test for Independence o Autocorrelation Test n n Tests the correlation between successive numbers

Test for Independence o Autocorrelation Test n n Tests the correlation between successive numbers and compares to the expected correlation of zero e. g. 2 3 2 4 2 3 o n There is a correlation between 2 & 3 We won’t do this test o software available 3

Hypotheses & Significance Level o Null Hypotheses – Ho n n o Numbers are

Hypotheses & Significance Level o Null Hypotheses – Ho n n o Numbers are distributed uniformly Failure to reject Ho shows that evidence of non-uniformity has not been detected Level of Significance – α (alpha) n α = P(reject Ho|Ho is true) 4

Frequency Tests (Uniformity) o Kolmogorov-Smirnov n n o More powerful Can be applied to

Frequency Tests (Uniformity) o Kolmogorov-Smirnov n n o More powerful Can be applied to small samples Chi Square n n Large Sample size >50 or 100 Simpler test 5

Overview o o Not 100% accurate Formalizes the idea of comparing histograms to candidate

Overview o o Not 100% accurate Formalizes the idea of comparing histograms to candidate probability functions Valid for large samples Valid for Discrete & Continuous 6

Chi-Square Steps - #1 o o Arrange the n observations into k classes Test

Chi-Square Steps - #1 o o Arrange the n observations into k classes Test Statistic: n n n o X 2 = Σ (i=0. . k) ( Oi – Ei)2 / Ei Oi = observed # in ith class Ei = expected # in ith class Approximates a X 2 distribution with (k-s-1) degrees of freedom 7

Degrees of Freedom o o o Approximates a X 2 distribution with (k-s-1) degrees

Degrees of Freedom o o o Approximates a X 2 distribution with (k-s-1) degrees of freedom s = # of parameters for the dist. Ho: RV X conforms to ? ? distribution with parameters ? ? H 1: RV X does not conform Critical value: X 2(alpha, dof) from table Ho reject if X 2 > X 2 (alpha, dof) 8

X 2 Rules o o Each Ei > 5 If discrete, each value should

X 2 Rules o o Each Ei > 5 If discrete, each value should be separate group If group too small, can combine adjacent, then reduce dof by 1 Suggested values n n = 50, k = 5 – 10 n = 100, k = 10 – 20 n > 100, k = sqrt(n) – n/5 9

Degrees of Freedom o o k–s– 1 Normal: s=2 Exponential: s = 1 Uniform:

Degrees of Freedom o o k–s– 1 Normal: s=2 Exponential: s = 1 Uniform: s = 0 10

X 2 Example o o Ho: Ages of MSU students conform to a normal

X 2 Example o o Ho: Ages of MSU students conform to a normal distribution with mean 25 and standard deviation 4. Calculate the expected % for 8 ranges of width 5 from the mean. 11

X 2 Example o Expected percentages & values n n n <10 -15 =

X 2 Example o Expected percentages & values n n n <10 -15 = 2. 5% 15 -20 = 13. 5% 20 -25 = 34% 25 -30 = 34% 30 -35 = 13. 5% 35 -40> = 2. 5% 5 27 68 68 27 5 12

X 2 Example o Consider 200 observations with the following results: n n n

X 2 Example o Consider 200 observations with the following results: n n n 10 -15 = 1 15 -19 = 70 20 -24 = 68 25 -29 = 41 30 -34 = 10 35 -40+ = 10 13

Graph of Data 70 60 50 40 30 20 10 15 20 25 30

Graph of Data 70 60 50 40 30 20 10 15 20 25 30 35 14

X 2 Example o X 2 Values – (O-E)2/E n 10 -15 = 15

X 2 Example o X 2 Values – (O-E)2/E n 10 -15 = 15 -20 = 20 -25 = 25 -30 = 30 -35 = 35 -40+ = n Total n n n (5 -1)2/5 (27 -70) 2/27 (68 -68) 2/68 (68 -41) 2/68 (27 -10) 2/27 (5 -10) 2/4 3. 2 68. 4 0 10. 7 5 98 15

X 2 Example o o o DOF = 6 -3 = 3 Alpha =

X 2 Example o o o DOF = 6 -3 = 3 Alpha = 0. 05 X 2 table value = 7. 81 X 2 calculated = 98 Reject Hypothesis 16