We want to use these data to test the hypothesis that relationship status and

obesity are associated at the 5% significance level.

To do so, we need a chi-square statistic.

And remember that for each cell,

we take the observed minus the expected squared divided by the expected.

Similarly, for cohabiting people,

103- 110 squared divided 110 for married people and

obese, that's a 147- 108 squared divided by 108.

We can go through this same calculations for each one of the cells in our table.

You can see the value of computation here as the table gets larger,

the calculations by hand become more and more tedious, and more and

more tedious always means more error-prone.

The chi-square statistic here comes out to be 31.68.

We also needed degrees of freedom to calculate the p-value associated

with this hypothesis test.

And remember that in a chi-square test of independence, the degrees

of freedom is number of rows minus one times number of columns minus one.

So that's (2 -1) x (3- 1), that's a degrees of freedom of two.

We can calculate the p value using r and the function we're going to use is p chi

square, and remember that takes the inputs of the observed chi square statistic,

the degrees of freedom, and we also usually specify whether we want

the tail area below the observed or above the observed.

And for chi-square test we always want the tail area above the observed

chi-square statistic.

So that comes out to be p chi-square of 31.68,

two further degrees of freedom and we don't want the lower tail.

And that's a pretty small p value we have there.

With a small p value, we reject the null hypothesis in favor of the alternative.

Which means that these data provide convincing evidence

that relationship status and obesity are associated.

So based on the significance p value,

can we conclude from these data that living with someone is making some

people obese, and marrying someone is making people even more obese.

The answer is no, we definitely cannot.

Remember that this is an observational study, so

what we're, we could be seeing the effect of here could also be age.

People tend to date when they're younger, then they start to live together,

and then at some point they get married.

It is possible that there is a causal relationship between obesity status and

relationship status but the type of analysis that we conducted here is

simply not sufficient to deduce a causal relationship.

And we always want to consider in these cases the effect of possible confounders

like age or other life factors that one might think about that change along with

the different life periods where people tend to be dating co-habitating and

married with each other.

To recap, we saw two types of chi-square tests.

Chi-square test of independence and chi-square test of goodness of fit.

In a chi-square test of goodness of fit, we compared the distribution of one

categorical variable with more than two levels to a hypothesized distribution.

In a chi-square test of independence we evaluate the relationship between

two categorical variables one of which at least has more than two levels,