 Welcome back to the final video on chi-square testing. So in this video, I'm going to show you how we can conduct a two-way chi-square test. And so our two-way chi-square test ends up looking a little different in terms of the null hypothesis. Essentially, we're looking at association instead of equal proportions. So what we're gonna do is we're going to do another card-based draw. And we're essentially gonna compare the suit to the chance of winning the game. And so our null hypothesis is that there's no association between the suit that you draw and the chance of winning the game of war, meaning the highest card wins. And our alternative is that there is an association. So I've already done some setup here to get our data in a way that we can use this two-way table. And so I'm using a new command called product. And then I'm using that to essentially build up this list of parentheses and then creating this data frame. And essentially what we're gonna do when I draw cards is that we're going to count, we're gonna draw two cards at once, and we're gonna count which one wins and record the suit. So we're gonna add a third column to this table and do some counting there. So here I've got it set up, table two count is going to be what we call it. And so we've got wins and losses here and I've separated out four things. So let's go ahead and draw. We'll probably do about 20 draws. So I'm just gonna draw the top two cards. And so I've got six of hearts and four of hearts here. So that means that hearts actually gets one loss and one win. And we're going to ignore any ties that we get. So then the next two cards, I have the nine of hearts and the queen of clubs. So that means hearts get a loss and clubs gets a win. Then I have a tie between two nines. So I'm just gonna ignore those. Then I have the nine of diamonds and the six of clubs. So that means clubs gets its first loss and diamonds gets its first win. Then I have king of clubs and five of spades. So clubs gets a second win and spades gets a loss. King of spades and six of spades. So that means spades gets a win and a loss. Four of diamonds and three of spades. So spades gets another loss and diamonds gets a win. Another time, queen of spades and 10 of spades. So again, win and a loss, a tie, two 10s. We've got an ace of clubs and an eight of hearts. So that means clubs gets a win and hearts gets a loss. An ace of hearts and a three of clubs. So hearts gets a win and clubs gets a loss. Ace of spades and eight of diamonds. So spades gets a win, diamonds gets a loss. And we will do one more draw. So a 10 of diamonds and a three of hearts. So diamonds gets a win and hearts gets a loss. And so what we're gonna do in the rest of this video is conduct a two-way chi square test to see if there's any association between the suit and the chance of winning. And so here we have our table just to show you what it looks like. We can run this. So now we have the suit, whether or not they won and the count of that situation happening. And so the first thing we need to do to conduct the two-way chi square test is we need to reorganize this using crosstab. So I'm gonna call this table three and I'm gonna say PD dot crosstab. We want to do table two of suit and table two of win with question mark. And then we want the values to be table two count. And then I'm going to specify that the add function is MP dot sum and that the margins are set to false. So we can print this and we can see that we've got essentially the wins, no and yes, and we've got the suit. And that's the format that we need our data to be in. Because then when we conduct the test, we can say results equals stats dot chi square this time underscore contingency. And then we just give it what we called our two-way table, table three, and we can print those results to show you what it looks like. So they give us the chi square statistic, they give us the p-value, the degrees of freedom and they give us what the expected frequency is. So a little bit more information that we see from the one-way chi square test. But if we just wanted to print the p-value, we can just say results one, which is this is the zero with point. So this is the first point. So we can print that and we can see that it's the same value, 0.57. And so we can draw a conclusion from that. We can say that the p-value is greater than our 0.05. So we either fail to reject or accept whichever one you prefer. The null hypothesis. So there is not sufficient evidence to say there is an association between suit and winning. In other words, our null hypothesis that we are accepting says there is no association. And so that is the conclusion that we make from this two-way chi-square test.