Archive for September, 2010

It’s A Math, Math World (Chi-Square Goodness-of-Fit Test)

In this week’s post, we will be analyzing categorical data. When dealing with categorical data, we are concerned with frequencies of each occurrence of the values of a random variable. We will be testing hypotheses of multiple proportions (more than 2 at a time). This technique we will use, called the Chi-Square Goodness of Fit Test, works for any set of proportions that add up to 1.

This test involves taking the observed frequencies (O) given in the problem and comparing these to the expected frequencies (E) which we calculate.

We are given, for example:

H0: p1 = 0.3, p2 = 0.2, p3 = 0.5; where 0.3 + 0.2 + 0.5 = 1

There are a total of n onbservartions so the expected frequencies are:

0.3 x n, 0.2 x n and 0.5 x n

If the observed frequencies differ too much from the expected frequencies, we would reject the null hypothesis.

We calculate the test statistic which is Χ2 = ∑ ((O-E)2/E) which has the Chi-Square distribution.  The properties of the Chi-Square are as follows:

  • There is an infinite number of Chi-Square distributions, each one associated with a number called its degrees of freedom.  We calculate df = k-1 where k is the number of categories. We use this number to specify which Chi-Square distribution we are using.
  • The test statistic has a Chi-square distribution if the sample size is sufficiently large such that the expected value of each category is at least 5.

Ex.  (From the textbook, General Statistics (2000), by Chase and Brown). We look at the production of electronic instruments. Four assembly lines are used to produce the same item. Each assembly line is equivalent in theory, so each should have the same rate of items produced that need servicing under warranty. 

A decision was made to look at the next 100 instruments returned as defective and see how many came from each plant.

The observed values of returned instruments for plants 1 through 4 are respectively: 53,18,14,15.

Plant 1 operates two shifts per day, while the other 3 plants operate 1 shift per day each.

Carry out the test of equivalence of the assembly lines at 10% level of significance.

Hypothesis:

H0: p1 = 2/5 = 0.4, p2=p3=p4=1/5 = 0.2 (Because plant 1 operates 2 of the 5 shifts while the remaining plants each operate a single shift of the five)

Ha: H0 not true

We have to compare the observed frequencies (O) against the expected frequencies (E) using the Chi-Square Goodness of Fit Test:

Expected Frequencies

Assembly Line P NP = E
1 0.4 (100)(0.4) = 40
2 0.2 (100)(0.2) = 20
3 0.2 (100)(0.2) = 20
4 0.2 (100)(0.2) = 20

 

Calculation of Test Statistic

Assembly Line O E (O-E) (O-E)2 (O-E)2/E
1 53 40 13 169 4.225
2 18 20 -2 4 0.200
3 14 20 -6 36 1.800
4 15 20 -5 25 1.250

 

χ2 = ∑ ((O-E)2/E) = 7.457, df = k-1 = 4-1= 3 where k= number of groups. This value,  χ2, is the test statistic.

When df=3, χ2(0.10) = 6.251 which we get from a Chi-Squared table or any software package. This is the critical value.

Since test statistic = 7.457 > 6.251 = critical value, we reject the null hypothesis, in a right tailed test, and conclude that the assembly lines are not equivalent.

NOTE: I will be taking the next few weeks off for vacation. I will be returning with my next blog post on Monday, October 18th.

Like what you read? Get blogs delivered right to your inbox as I post them so you can start standing out in your job and career. There is not a better way to learn or review college level stats topics than by reading, It’s A Math, Math World

It’s A Math, Math World (ANOVA Part 2)

Today’s example is taken from the book, General Statistics, (2000) by Chase and Brown.

In previous weeks, we learned how to test a single hypothesis of the difference between two population means: i.e., test whether two means u1 and u2 are equal. What if we have more than two populations are we want to see if the means are equal? We want to compare more than 2 population means at the same time. This process is called Analysis of Variance (ANOVA).

Note we could conduct multiple pair-wise tests of the equality of means, but this would multiply the error rate considerably. In the ANOVA case, we test the following hypothesis:

H0: u1 = u2 = u3 = … = uk

HA: not all the means are equal

This week, we are NOT assuming equal sample sizes.

Swimmers Left Ventricular End Diastolic Volume (n1 =15)

  x1 (x1 – x1_bar) (x1 – x1_bar)2
  140 -41.733 1741.643
  140 -41.733 1741.643
  140 -41.733 1741.643
  148 -33.733 1137.915
  148 -33.733 1137.915
  175 -6.733 45.333
  185 3.267 10.673
  194 12.267 150.479
  194 12.267 150.479
  203 21.267 452.285
  203 21.267 452.285
  214 32.267 1041.159
  214 32.267 1041.159
  214 32.267 1041.159
  214 32.267 1041.159
SUM 2726   12926.929
x1­_bar 181.733    

 

Wrestlers Left Ventricular End Diastolic Volume (n2 =12)

  x2 (x2 – x2_Bar) (x2 – x2_Bar)2
  83 -27.167 738.046
  91 -19.167 367.374
  97 -13.167 173.370
  97 -13.167 173.370
  108 -2.167 4.696
  111 0.833 0.694
  111 0.833 0.694
  117 6.833 46.690
  117 6.833 46.690
  125 14.833 220.018
  125 14.833 220.018
  140 29.833 890.008
SUM 1322   2881.668
x2_Bar 110.167    

 

Example:

The 3 tables listed here contain measurements of heart size for 3 populations: swimmers, wrestlers and a control group of non-athletes. Left Ventricular End Diastolic Volume is the volume of the lower left heart chamber when it if filled with blood. Test that the mean size is the same for the 3 populations at 1% level of significance.

H0: u1 = u2 = u3

HA: not all of the population means are equal.

F-stat = (Estimate 1)/(Estimate 2)

Estimate #1 = Mean Squares Within (MSW) = Sum of Squares Within (SSW)/(n-k)

Estimate #2 = Mean Squares Between (MSB) = Sum of Squares Between (SSB)/(k-1)

Compare to F (0.01) with df = (k-1, n-k)

SSW = SUM(x1 – x1_bar)2 + SUM(x2 – x2_bar)2 + SUM (x3 – x3_bar)2

                = 12926.929 + 2881.668 + 437.756 = 20146.353

df = (n-k) = 43-3 = 40

MSW = 20146.353/40 = 503.659

Grand mean = ( 2726 + 1322 + 1614) /43 = 5662/43 = 131.674

 Left Ventricular End Diastolic Volume of Controls (n3 =16)

  x3 (x3 – x3_bar) (x3 – x3_bar)2
  64 -36.875 1359.766
  83 -17.875 319.516
  83 -17.875 319.516
  85 -15.875 252.016
  91 -9.875 97.516
  97 -3.875 15.016
  97 -3.875 15.016
  97 -3.875 15.016
  103 2.125 4.516
  108 7.125 50.766
  111 10.125 102.516
  111 10.125 102.516
  117 16.125 260.016
  117 16.125 260.016
  125 24.125 582.016
  125 24.125 582.016
SUM 1614   4337.756
X3_bar 100.875    

 

SSB = n1(x1_bar – grand_mean)2 + n2(x2_bar – grand_mean)2 + n3(x3_bar –grand_Mean)2

= 15(181.733 – 131.974)2 + 12(110.167 – 131.674)2 + 16(100.875 – 131.674)2

= 37588.552 + 5550.613 + 15177.254 = 58316.419

Df = (k-1) = 3-1 = 2

MSB = 58316.419/2 = 29158.210

Therefore, F-stat = 29158.210/503.659 = 57.89

Compare to F(0.01) with df = (2, 40)

From the table of the F-distribution, we have an F value of 5.18. Since 57.89 > 5.18, we reject the null hypothesis and conclude that not all of the 3 population means are equal.

Note: we have to have certain assumptions for this ANOVA calculation to be valid.

1) The sampled populations must be approximately normal.

2) There must be equal population standard deviations ; a property called homoscedasticity.

* Email
First Name
  * = Required Field
 


Email Marketing You Can Trust

It’s A Math, Math World (ANOVA Part1)

 

In previous weeks, we learned how to test a single hypothesis of the difference between two population means: i.e., test whether two means u1 and u2 are equal. What if we have more than two populations are we want to see if the means are equal? We want to compare more than 2 population means at the same time. This process is called Analysis of Variance (ANOVA).

Note we could conduct multiple pair-wise tests of the equality of means, but this would multiply the error rate considerably. In the ANOVA case, we test the following hypothesis:

H0: u1 = u2 = u3 = … = uk

HA: not all the means are equal

The methodology is as follows (we are assuming EQUAL sample sizes in this example).This example is from the textbook General Statistics (2000) by Chase and Bown:

A large chemical company uses 4 manufacturing plants to produce the same fertilizer. The plants were built to be equivalent, so the mean output of fertilizer from each plant should be the same and have the same variability. We want to test that the weekly mean output (tons of fertilizer produced) is the same for each plant. This will of course vary week to week, but we are interested in the true mean weekly production for a plant.

H0: u1 = u2 = u3 = u4

Ha: Not all means are equal (at least one is different)

Weekly Production Figures for 5 weeks for 4 Fertilizer Plants (weekly production is in tons)

  PLANT 1 PLANT 2 PLANT 3 PLANT 4
  574 546 580 585
  578 556 570 582
  573 549 577 581
  568 551 575 589
  572 553 573 588
Sample mean 573 551 575 585
Sample variance 13 14.5 14.5 12.5

 

If the sample means are clustered close together, this would tend to support H0.

A great degree of variability among the sample- means would suggest that not all of the population means are equal, thus supporting HA.

The key to testing for equality of several population means is to look at the variability between the sample means. A large amount of variability would suggest that not all of the population means are equal. Therefore, we would reject H0 in favor of HA, otherwise we would not reject H0.

“Large” is a relative term and this variability must be measured in terms of something.  We will define large as being the condition that the variability between the sample- means is large in relation to the variability within the samples. When this is the case, we reject H0 and conclude that the population means are not all the same.

First we assume that the population variance, σ2, is the same for all the plants, whether the means are equal or not. From our sample data, we will calculate 2 estimates:

  • The within-sample estimate of σ2
  • The between sample estimate of σ2

Estimate #1: Within-Sample Estimate

We pool the estimates the estimates of the sample variances by averaging them:

Estimate 1 = (13+14.5+14.5+12.5)/4 = 13.625

Estimate #2: Between-Sample Estimate

Let us assume for the moment that H0 is true, and then we can view the samples of production figures as 4 samples of size 5 from the same population.  The 4 sample means are values of the random variable x_bar.  By the Central Limit Theorem, we know that the standard deviation of x_bar is:

                                σx_bar = sqrt (σ2/m)   or     σ2 = m x (σx_bar)2

We use the sample variance of the 4 values of x_bar which I will call s2x_bar as an            estimate of this variance we have to find.

We first need to find the grand mean of the 4 sample means which is = (573 + 571 + 575                                + 585)/4

= 571

We calculate the sample variance s2x_bar as follows:

Sample Mean Sample mean – grand mean (Sample mean – grand mean)2
573 0 0
551 -2 4
575 2 4
585 0 0
Grand mean = 571   8 = SUM

 

S2x_bar = SUM/(4-1) = 8/3

Estimate 2 = m x (s2x_bar) = 5 x (8/3) = 13.333

We combine the estimates as follows:

F-stat = (Estimate #1)/ (Estimate #2) = 13.625/13.333 = 1.021

The statistic, F-stat, follows an F distribution with df1= k-1 and df2 = n-k degrees of freedom               where:

n= # of data values in all the samples.

k = # of populations

We express the degrees of freedom as an ordered pair df = (k-1, n-k)

In our example F-stat = 1.021 and compare it to the F distribution at α=0.05 and df = (3, 16)

Our critical value is 3.24 (from the F distribution tables), since F-stat < critical value, we fail to reject the H0 and we conclude that there is no difference between the mean output of the 4 plants.

Like what you read? Get blogs delivered right to your inbox as I post them so you can start standing out in your job and career. There is not a better way to learn or review college level stats topics than by reading, It’s A Math, Math World