library(readr)
library(dplyr)
library(infer)
survey <- read_csv("../datasets/class_survey.csv")
survey |> chisq_test(housing ~ year)# A tibble: 1 × 3
statistic chisq_df p_value
<dbl> <int> <dbl>
1 4.62 3 0.202
year and housing associated?sleep_hours differ across class year?study_hours predict sleep_hours?Both variables are categorical, so we cross-tabulate year × housing and test whether the two are independent.
year and housing.class_survey.csv.year; Columns: housing.(Jamovi screenshots to be added.)
library(readr)
library(dplyr)
library(infer)
survey <- read_csv("../datasets/class_survey.csv")
survey |> chisq_test(housing ~ year)# A tibble: 1 × 3
statistic chisq_df p_value
<dbl> <int> <dbl>
1 4.62 3 0.202
With only 50 students split across a 4×2 table, some expected counts fall below 5 — the chi-square approximation is shaky here. In practice you’d report that caveat (and could fall back to the randomization chi-square from the Simulate unit). For this tutorial the point is the mechanics.
ANOVA compares the mean of a numerical variable (sleep_hours) across 3+ groups (the four class years) with a single F-test.
sleep_hours, grouping year.sleep_hours; Grouping: year.(Jamovi screenshots to be added.)
aov(sleep_hours ~ year, data = survey) |> summary() Df Sum Sq Mean Sq F value Pr(>F)
year 3 2.78 0.9266 1.119 0.351
Residuals 46 38.08 0.8278
Both variables are numerical. We fit a line predicting sleep_hours from study_hours and test whether the slope differs from zero. (In the Explore unit the scatter of these two looked flat — regression now tests that formally.)
study_hours and y to sleep_hours.sleep_hours; Covariate: study_hours.study_hours coefficient), its p, and the R² (Model Fit).(Jamovi screenshots to be added.)
lm(sleep_hours ~ study_hours, data = survey) |> summary()
Call:
lm(formula = sleep_hours ~ study_hours, data = survey)
Residuals:
Min 1Q Median 3Q Max
-2.1533 -0.5092 -0.1111 0.5444 1.9448
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 7.14892 0.30485 23.450 <2e-16 ***
study_hours -0.00625 0.01982 -0.315 0.754
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.9217 on 48 degrees of freedom
Multiple R-squared: 0.002068, Adjusted R-squared: -0.01872
F-statistic: 0.09947 on 1 and 48 DF, p-value: 0.7538
OpenIntro IMS interactive tutorials for this unit: