Consider two variables of a population, each with discrete characteristics. The first variable has 5 distinct values,

- Red
- Green
- Blue
- Purple
- Yellow

- Square
- Triangle
- Parallelagram
- Hexagon
- Octogon
- Circle

To test our hypothesis that the color and shape are independent we will perform a

source("../gnrnd5.R") gnrnd5( key1=40123008708, key2=6449454834765 ) matrix_A

The display in Figure 1 matches the values shown in

`crosstab()`

`crosstab()`

`crosstab()`

Rather than painfully reproducing all of the steps here, we will merely load and then run the

`crosstab()`

source("../crosstab.R") crosstab(matrix_A )

That console output actually provides the answer to our question. The

Although the console output is quite concise, it does not show all of the steps that we would have gone through to look at the data and to compute the

`crosstab()`

In our investigation of the various tabs, we do not want to start with that display. In fact, the one we want is the

Within that selection, we point to our desired tab, in this case

Once we click on the selection the dispaly shifts to show our desired tab,

The difference between the console display of the table shown in Figure 1 and the display in Figure 6 is that we now have the

Next we want to examine the

When we click on the

Figure 8 shows all of the row percents, expressed as decimal values, for the entire table, including the total row and the total column. In row 3 column 4 we find the value

We already know from the console display of Figure 2 that there is not sufficient evidence to reject the hypothesis of independence. In the case of

Next we can look at the column percents. Unfortunately, those are not at shown in the tabs displayed in Figure 8 so we return to the tab selections via the chevron, as shown in Figure 9.

Clicking on the

Figure 10 shows the column percents for all of the cells in the table. Recall that there were 341

As we saw for the row percents above, in a

Next, somewhat for completeness, we want to look at the

We really have little use for the

When we get to the task of computing our χ²: value we want to remember the steps that we would need to take.

- For each cell in the matrix, note the value in the cell as the
**observed**value. - For each cell in the matrix, find the
**expected**value. This will be the value (**row total**) * (**column total)**/**grand total**. - For each cell in the matrix, find the
**difference**between the**observed**and**expected**values, i.e., compute**observed - expected**. - For each cell in the matrix, find the
**square of that difference**, i.e., compute (**observed**-**expected)²**. - For each cell of the matrix find the ratio of the
**squared difference**and the**expected**value, i.e., compute (**observed**-**expected)²**/**expected**. - Get the sum of all of those
**ratios**; that sum is the χ² value

Figure 12 holds all of the expected values. In particular, the cell we have been following, the

Then we move to the calculation of the

Recall that we had

Then we want to look at the

Sure enough, the cell we have been following, row 3 column 4, now has the square of the corresponding cell back in Figure 13. Thus

Once we have all of those squared values we want to find the

Again, focusing on our row 3 column 4 value, we expect that to be

The only remaining step is to add all 30 values in Figure 15. The function

That concludes our walk-through of the

[Note: It is interesting to compare

Again, we want to test the null huypothesis that the two varibables, color and shape, in the underlying population are independent. We will test this hypothesis at the

Looking at the console output in Figure 16 we confirm that we have the correct matrix values. In addition, in Figure 16, we have run the

There was a good deal of work that went into actually computing the χ² value. That work is shown, along with some descriptive work, in the various tabs displayed in the editor pane. For example, the tab

Comparing this to its corresponding display above, Figure 6, we see the result of having different values in

Figure 18 shows the

Again, the row percent values, with the exceptions of

Figure 19 shows the

As we might expect, the columns are pretty much the same, except for the changes in the row 4 values. Again, note the change in row 4 column 5.

Figure 20 shows the

Now we look at the tabs that represent the actual computation of the χ² value. Figure 21 shows the

Figure 22 shows the

Figure 23 shows the

Figure 24 shows the

If we were to add up all of the values in

©Roger M. Palay Saline, MI 48176 September, 2016