 Welcome back to our video series on chi-square tests. In this video, we're gonna talk about how we can visualize our chi-square randomization distribution as well as an idealized chi-square distribution. And so we're essentially going to make a histogram, but we're going to use a different way, different variable on the y-axis than we have in the past. So let's go ahead and get started. So with our ggplot, our data is chi-square df. And this is part of the reason why up here we converted into a data frame. And then we can say geom histogram. And then we have our aes statement. Our x is just chi-square, which is what we called our data. And then normally we would leave this as it is and do a bit of accounting. But we can say y equals after stat density in quotes. So this essentially tells the Python to apply the density command to the data rather than the count that is traditionally shown in a histogram. And then we can also define an outline color as black. And we can specify our bin width as 0.75. And then as we've done in the past, we can add a vertical line for our sample statistic, which is chi-square stamp, color is blue. And we can say line type dashed. And so here we have our chi-square sampling distribution as the histogram and what the sample is. And so as the way the p-value works, all of the data that is above our sample statistic goes into our p-value, which is why we have such a high one. You can see that a lot of that data is above the sample statistic. But often it can be very helpful to show the idealized chi-square distribution. And so a chi-square distribution, similar to the normal distribution that we learned in a previous lecture is an idealized distribution that depends on only the degrees of freedom. And it'll generally follow this right skew shape. So before we can actually get into the plotting, we do need to do a bit of prep work. First we need to define our degrees of freedoms. And we're gonna define this as three. And officially this is the number of categories, minus one. So we've got four suits, four categories, three minus one, or four minus one is three. And then we also need to create new columns in our chi-square DF. So we need one for XPDF. And this is just a series of numbers that match the X-axis we see here. So we do np.bin space 0 to 25 to 1,000, or with 1,000 in between. Effectively, this creates a series of numbers from 0 to 25 evenly spaced numbers from 0 to 25. And there's 1,000 values. And so in effect, this will count from 0 to 25, with putting 1,000 values in between. And then we need the Y PDF. And this is where we actually figure out what the chi-square distribution is that fits this data. And so we say stats.chi-square.pdf. We give it our idealized X data, and we give it the degrees of freedom. And so now if we look at just the first five rows, we can see we've got our original chi-square sampling distribution, then we've got idealized X and Y data. And so if we wanna plot this, we can just continue on with our plot that we did last. Come up here. And essentially we can just add another line plot on top of it, where our X value is now X PDF. Our Y value is now Y PDF, the color is blue. And I'm gonna give it a size to make it a little bit more obvious. And so here we can see the final plot where we've got our chi-square distribution. We've got our idealized curve here. And we can see that it does a pretty good job of following the data. And that is in effect a way that we can see what the idealized chi-square curve is going to look like.