J Lab 3
Comparing groups: two proportions, two means, and the chi-square test
Portions of this lab are adapted from R labs from Introduction to Modern Statistics (2e) by Mine Çetinkaya-Rundel and Johanna Hardin.
Overview
In this lab you will compare groups in three ways:
- Part A, two proportions: a Yes/No variable compared across two groups.
- Part B, two means: a numerical variable compared across two groups.
- Part C, chi-square test: two categorical variables, at least one with more than two categories.
Each part works through an example and answers the same four questions you will answer in your lab report:
- What are the null and alternative hypotheses?
- What is the test statistic?
- What is the p-value, and what is the full conclusion?
- What is the confidence interval (Parts A and B), or what are the expected counts (Part C)?
A full conclusion has three parts:
- Decision and context: do you reject \(H_0\) or not, and what does that mean for the research question?
- Generalization: to what population, if any, can you apply the result?
- Causation: can you say that one variable causes a change in the other?
The data: MATH 115 class survey
Download survey data.csv from the J Lab 3 Data set link in the Jamovi Labs section of Moodle, and open it in jamovi (☰ → Open → Browse). Each row is one Hope College student who answered the MATH 115 class survey. There are 139 students in the data set.
You will use these variables:
| Variable | Description |
|---|---|
Sex |
Female / Male |
Coffee |
Do you drink coffee? (Yes / No) |
Dean'sList |
Have you been on the Dean’s List? (Yes / No) |
Nap |
Do you take naps regularly? (Yes / No) |
Greek |
Are you a member of a Greek organization? (Yes / No) |
Personality |
Extrovert / Introvert |
FavoriteClass-type |
Favorite class format: face-to-face / hybrid / online |
Residence |
Where you live: Cott-Apt (cottage or apartment) / Dorm / Off (off campus) |
GPA-Hope |
Current Hope College GPA (a number) |
You do not need to filter the data. If a student skipped a question, jamovi leaves that student out of the analysis automatically.
Put “Yes” first
The Randomize module counts the first column of a table as a “success” and treats the first row as Group 1. jamovi lists levels in alphabetical order, so “No” comes before “Yes” and “Female” comes before “Male”. When “Yes” is the success, move it to the top:
- Click the Data tab, click the column name
Coffee, and click Setup. - In the Levels box, click Yes, then click the up arrow on the right.
- Click the round arrow in the top right corner to close Setup.
Coffee.
Seed the simulations
Every simulation in this lab uses the Randomize module (the Randomize icon on the Analyses tab). Each time, check Seed random number generator and keep the seed 8675309. Then your results will match the ones in this lab.
Part A: Comparing two proportions
Is there a difference in the proportion of coffee drinkers between female and male Hope students?
The response variable is Coffee (success = Yes). The explanatory variable is Sex, with Group 1 = Female and Group 2 = Male.
Summaries
Click Analyses → Frequencies → Independent Samples. Drag Sex into Rows and Coffee into Columns. Open Cells and check Row under Percentages. Open Plots, check Bar Plot, and under Y-Axis choose Percentages and within rows. You can ignore the χ² Tests table for now.
Coffee by Sex.
In the sample, 48 of the 91 women drink coffee (\(\hat p_F = 48/91 = 0.527\)), and 15 of the 48 men do (\(\hat p_M = 15/48 = 0.313\)). The observed difference is
\[ \hat p_F - \hat p_M = 0.527 - 0.313 = 0.215 . \]
Question 1: Hypotheses
Let \(p_F\) and \(p_M\) be the proportions of all female and all male Hope students who drink coffee.
\[ H_0:\ p_F - p_M = 0 \qquad\qquad H_A:\ p_F - p_M \neq 0 \]
In words, \(H_0\) says the proportion of coffee drinkers is the same for female and male students, and \(H_A\) says it is different. The research question only asks about a difference, so the alternative is two-sided (\(\neq\)). We use \(\alpha = 0.05\).
Question 2: Test statistic and Z-score
The test statistic is the observed difference, 0.215.
Check the success–failure condition. Use the pooled proportion, the overall proportion of “Yes” in the Total row of the table:
\[ \hat p_{pool} = \frac{63}{139} = 0.453 . \]
Multiply each group size by \(\hat p_{pool}\) and by \(1-\hat p_{pool}\):
- Female: \(91(0.453) = 41.2\) successes and \(91(0.547) = 49.8\) failures
- Male: \(48(0.453) = 21.8\) successes and \(48(0.547) = 26.2\) failures
All four are at least 10, so the condition is met.
Standard error and Z-score:
\[ SE = \sqrt{\hat p_{pool}(1-\hat p_{pool})\left(\frac{1}{n_F}+\frac{1}{n_M}\right)} = \sqrt{0.453(0.547)\left(\frac{1}{91}+\frac{1}{48}\right)} = 0.0888 \]
\[ Z = \frac{0.215 - 0}{0.0888} = 2.42 \]
Question 3: p-value and conclusion
Theory-based p-value. Click Randomize → Model-Based Inference. Set Distribution to Standard normal (Z), check Calculate area (p-value), type 2.42 as the Observed value, and set Tail to Both (because \(H_A\) is two-sided). The p-value is 0.016.
Randomization p-value. Click Randomize → Two Proportions - Hypothesis Test. Drag Sex into Rows and Coffee into Columns, and keep Compare set to rows and Alternative hypothesis set to Group 1 ≠ Group 2. Open Cells and check Row. Open Simulations, set Number of simulated samples to 1000, set the plot to Histogram, and check Seed random number generator.
The histogram shows the differences we would expect if \(H_0\) were true. The red dashed line is the observed difference. The p-value in the Simulation Results table is 0.024.
Full conclusion.
- Decision and context: Both p-values (0.016 and 0.024) are below 0.05, so we reject \(H_0\). There is convincing evidence that the proportion of coffee drinkers is different for female and male Hope students. In the sample, women drink coffee more often (52.7% vs. 31.3%).
- Generalization: The data come from a voluntary survey of MATH 115 students, not a random sample, so the result applies only to students like the ones surveyed.
- Causation: Sex was not randomly assigned, so this is an observational study. We cannot say that sex causes the difference.
Question 4: Confidence interval
Theory-based interval. For a confidence interval, the standard error uses the two separate sample proportions:
\[ SE = \sqrt{\frac{0.527(0.473)}{91} + \frac{0.313(0.687)}{48}} = 0.0849 \]
To get the multiplier, open Model-Based Inference again, uncheck Calculate area (p-value), check Calculate CI multiplier, and enter 95 as the Confidence level. The multiplier is \(z^* = 1.960\).
\[ 0.215 \pm 1.960(0.0849) = 0.215 \pm 0.166 = (0.049,\ 0.382) \]
Bootstrap interval. Click Randomize → Two Proportions - Confidence Interval. Drag Sex into Rows and Coffee into Columns. Keep Confidence level at 95 and the type at bootstrap percentile. Open Cells and check Row. Open Simulations, set the number of samples to 1000, choose Histogram, and check Seed random number generator. The Lower and Upper bounds are (0.045, 0.374).
Meaning. We are 95% confident that the proportion of coffee drinkers among female Hope students is between about 0.05 and 0.38 higher than among male Hope students. Zero is not in the interval, which agrees with rejecting \(H_0\).
Part B: Comparing two means
Do coffee drinkers and non-coffee drinkers at Hope have different mean GPAs?
The response variable is GPA-Hope. The explanatory variable is Coffee, with Group 1 = Yes and Group 2 = No (you moved Yes to the top in the setup step).
Summaries
Click Analyses → Exploration → Descriptives. Drag GPA-Hope into Variables and Coffee into Split by. The table already shows N, Missing, Mean, Median, Std. deviation, Minimum, and Maximum. Open Plots and check Histogram and Box plot.
GPA-Hope split by Coffee.
GPA-Hope for each coffee group.
Coffee drinkers: \(n = 61\), \(\bar x = 3.57\), \(s = 0.347\). Non-coffee drinkers: \(n = 72\), \(\bar x = 3.42\), \(s = 0.392\). The observed difference is \(\bar x_{Yes} - \bar x_{No} = 0.153\) (jamovi uses more decimal places than the table shows; the Two Means - Hypothesis Test output below reports 0.153).
Question 1: Hypotheses
Let \(\mu_{Yes}\) and \(\mu_{No}\) be the mean GPAs of all Hope students who do and do not drink coffee.
\[ H_0:\ \mu_{Yes} - \mu_{No} = 0 \qquad\qquad H_A:\ \mu_{Yes} - \mu_{No} \neq 0 \]
In words, \(H_0\) says the mean GPA is the same for the two groups, and \(H_A\) says it is different. We use \(\alpha = 0.05\).
Question 2: Test statistic and T-statistic
The test statistic is the observed difference, 0.153.
Check the conditions.
- Independence: the students are different people.
- Normality: both groups have more than 30 students, and the histograms show no extreme outliers.
- Equal variance: the standard deviations (0.347 and 0.392) are similar, so we use the pooled standard deviation.
\[ s_p = \sqrt{\frac{(n_1-1)s_1^2+(n_2-1)s_2^2}{n_1+n_2-2}} = \sqrt{\frac{60(0.347)^2+71(0.392)^2}{131}} = 0.372 \]
\[ SE = s_p\sqrt{\frac{1}{n_1}+\frac{1}{n_2}} = 0.372\sqrt{\frac{1}{61}+\frac{1}{72}} = 0.0648 \qquad T = \frac{0.153 - 0}{0.0648} = 2.36 \]
The degrees of freedom are \(df = n_1 + n_2 - 2 = 61 + 72 - 2 = 131\).
Question 3: p-value and conclusion
Theory-based p-value. In Model-Based Inference, set Distribution to t and Degrees of freedom to 131. Check Calculate area (p-value), type 2.36 as the Observed value, and set Tail to Both. The p-value is 0.020.
Randomization p-value. Click Randomize → Two Means - Hypothesis Test. Drag GPA-Hope into Dependent Variable and Coffee into Grouping Variable. Keep the hypothesis at Group 1 ≠ Group 2, and check Descriptives and Descriptives plots. Set Number of simulated samples to 1000, choose Histogram, and check Seed random number generator. The p-value is 0.020.
Full conclusion.
- Decision and context: Both p-values (0.020) are below 0.05, so we reject \(H_0\). There is convincing evidence that mean GPA is different for coffee drinkers and non-coffee drinkers at Hope. In the sample, coffee drinkers had the higher mean GPA (3.57 vs. 3.42).
- Generalization: Only to students like the MATH 115 students who answered the voluntary survey.
- Causation: Students were not randomly assigned to drink coffee, so we cannot say coffee causes a higher GPA. Something else, such as class year or study habits, could explain the difference.
Question 4: Confidence interval
Theory-based interval. In Model-Based Inference, keep Distribution at t with 131 degrees of freedom, uncheck Calculate area (p-value), check Calculate CI multiplier, and enter 95. The multiplier is \(t^* = 1.978\).
\[ 0.153 \pm 1.978(0.0648) = 0.153 \pm 0.128 = (0.025,\ 0.281) \]
Bootstrap interval. Click Randomize → Two Means - Confidence Interval. Drag GPA-Hope into Dependent Variable and Coffee into Grouping Variable. Keep Confidence level at 95 and CI type at bootstrap percentile. Set the number of samples to 1000, choose Histogram, and check Seed random number generator. The bounds are (0.032, 0.292).
Meaning. We are 95% confident that the mean GPA of coffee drinkers at Hope is between about 0.03 and 0.28 grade points higher than that of non-coffee drinkers. Zero is not in the interval, which agrees with rejecting \(H_0\).
Part C: The chi-square test
When a categorical variable has more than two categories, one difference in proportions is not enough. The chi-square test checks whether two categorical variables are associated.
Is a student’s favorite type of class (face-to-face, hybrid, online) associated with personality (extrovert, introvert)?
The explanatory variable is Personality and the response variable is FavoriteClass-type.
Summaries and the test
Everything for Part C comes from one analysis. Click Analyses → Frequencies → Independent Samples. Drag Personality into Rows and FavoriteClass-type into Columns. The χ² test is already checked under Statistics. Open Cells and check Expected counts and Row. Open Plots, check Bar Plot, and choose Percentages within rows.
In the sample, 34% of introverts but only 13% of extroverts prefer hybrid classes.
Question 1: Hypotheses
- \(H_0\): Favorite class type and personality are not associated. Extroverts and introverts have the same distribution of favorite class type.
- \(H_A\): Favorite class type and personality are associated. The distributions are different.
In symbols, let \(p_{\text{hyb},E}\) be the proportion of all extroverted Hope students who prefer hybrid classes, and define the other proportions the same way. \(H_0\) says \(p_{\text{f2f},E}=p_{\text{f2f},I}\), \(p_{\text{hyb},E}=p_{\text{hyb},I}\), and \(p_{\text{onl},E}=p_{\text{onl},I}\); \(H_A\) says at least one of these is not equal. The chi-square test is always one test of “associated or not”, with no one-sided version.
Question 2: Chi-square statistic
The chi-square statistic adds up how far each observed count (\(O\)) is from its expected count (\(E\)):
\[ X^2 = \sum \frac{(O-E)^2}{E}. \]
For example, the extrovert/hybrid cell contributes \((10-17.27)^2/17.27 = 3.06\). Adding all six cells gives \(X^2 = 8.93\), the Value in the χ² Tests table. The two hybrid cells contribute the most: introverts chose hybrid more often than expected, and extroverts less often.
The degrees of freedom are \(df = (\text{rows} - 1)(\text{columns} - 1) = (2-1)(3-1) = 2\).
Question 3: p-value and conclusion
Read the p-value from the χ² Tests table: p = 0.011. A large \(X^2\) is evidence against \(H_0\), so the p-value is the area in the right tail of the chi-square distribution. No randomization test is needed in this part.
Full conclusion.
- Decision and context: 0.011 is below 0.05, so we reject \(H_0\). There is convincing evidence that favorite class type is associated with personality. The biggest difference is that introverts prefer hybrid classes more often (34% vs. 13%).
- Generalization: Only to students like the MATH 115 students who answered the voluntary survey.
- Causation: Personality was not randomly assigned, so we cannot say personality causes a class preference.
Question 4: Expected counts
An expected count is how many students we would expect in a cell if \(H_0\) were true:
\[ E = \frac{(\text{row total})\times(\text{column total})}{\text{grand total}} . \]
For introverts who prefer hybrid classes, \(E = \dfrac{64 \times 32}{139} = 14.73\). Overall, 23% of students prefer hybrid, so if personality didn’t matter we would expect about 23% of the 64 introverts, or 14.73 students, to prefer hybrid. We actually observed 22.
The Expected rows of the contingency table (Figure 13) show all the expected counts (jamovi rounds them). The smallest is 8.29. Every expected count is at least 5, so the chi-square test is appropriate.
Saving your work
Save your work with ☰ → Save as an .omv file so you can come back to it. You will not turn in this file. You will turn in a PDF lab report.
What you need to turn in
Answer the questions below. Follow the matching example (Part A, B, or C), include the jamovi output listed under each question, use \(\alpha = 0.05\), and use seed 8675309 for every simulation.
Part A: Two proportions
Is there a difference between female and male Hope students in the proportion who have been on the Dean’s List?
Response:
Dean'sList(success = Yes). Explanatory:Sex(Group 1 = Female, Group 2 = Male). First move Yes to the top of the levels ofDean'sList.
A1. Include the two-way table with row percentages and the side-by-side bar graph, and give the two sample proportions. Define the parameters in words, and state \(H_0\) and \(H_A\) in symbols and in words.
A2. Give the observed difference. Show \(\hat p_{pool}\), the four expected counts for the success–failure condition, the standard error, and the Z-score.
A3. Give the theory-based p-value (include the Model-Based Inference screenshot) and the randomization p-value from 1,000 simulations (include the histogram and Simulation Results table). Write a full conclusion: decision and context, generalization, and causation.
A4. Give the theory-based 95% interval (show the SE, the multiplier, and the calculation) and the bootstrap interval from 1,000 samples (include the histogram and results table). Interpret the interval and say whether it agrees with A3.
Part B: Two means
Do Hope students who nap regularly have a different mean GPA from students who do not nap regularly?
Response:
GPA-Hope. Explanatory:Nap(Group 1 = No, Group 2 = Yes). Leave the levels ofNapin their original order.
B1. Include the Descriptives table (N, mean, median, SD, minimum, maximum for each group), the histograms, and the box plots, and briefly compare the groups. Define the parameters in words, and state \(H_0\) and \(H_A\) in symbols and in words.
B2. Give the observed difference. Check the conditions, and show the pooled standard deviation, the standard error, the T-statistic, and the degrees of freedom.
B3. Give the theory-based p-value (include the Model-Based Inference screenshot) and the randomization p-value from 1,000 simulations (include the histogram and results table). Write a full conclusion.
B4. Give the theory-based 95% interval (SE, \(t^*\), calculation) and the bootstrap interval from 1,000 samples (include the histogram and results table). Interpret the interval and say whether it agrees with B3.
Part C: Chi-square test
Is membership in a Greek organization associated with where Hope students live (cottage/apartment, dorm, off campus)?
Explanatory:
Greek(Rows). Response:Residence(Columns).
C1. Include the two-way table with row percentages and the side-by-side bar graph, and describe what they show. State \(H_0\) and \(H_A\) in words and in symbols.
C2. Give \(X^2\) from the χ² Tests table. Show the calculation of \((O-E)^2/E\) for at least one cell, say which cells contribute the most, and give the degrees of freedom.
C3. Give the p-value (include the χ² Tests table) and write a full conclusion.
C4. Show how to calculate the expected count for Greek members who live in a dorm, compare it with the observed count, and explain what it means. Include the table with expected counts, and say whether every expected count is at least 5.
You may write your lab report in a Word document or a Google Doc. Number your answers A1–A4, B1–B4, and C1–C4, and put each table or plot under the question it belongs to. Save the report as a PDF, check that it is readable and complete, and submit it with the J Lab 3 Submission link on Moodle.