Apr 10, 2025
Exam 02 - April 17 (same format as Exam 01)
Next project milestone: Draft and peer review in April 21 lab
Statistics experience due April 15
Todayβs data comes from an experiment by the Educational Testing Service to test the effectiveness of the childrenβs program Sesame Street. Sesame Street is an educational program designed to teach young children basic educational skills such as counting and the alphabet
As part of the experiment, children were assigned to one of two groups: those who were encouraged to watch the program and those who were not.
The show is only effective if children watch it, so we want to understand what effect the encouragement had on the frequency children watched the program.
Response:
viewcat
Predictors:
age: childβs age in monthsviewenc: 1: encouraged to watch, 0: not encouragedResampling is only conducted on the training set. The test set is not involved. For each iteration of resampling, the data are partitioned into two subsamples:
Image source: Kuhn and Silge. Tidy modeling with R.
More specifically, v-fold cross validation β commonly used resampling technique:
Letβs give an example where v = 3β¦
Split data into training and test sets
Specify model
Note: Use linear_reg() or logistic_reg() for linear or logistic models, respectively.
Create workflow
ββ Workflow ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Preprocessor: Formula
Model: multinom_reg()
ββ Preprocessor ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
viewcat ~ ageCent + viewenc + site
ββ Model βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Multinomial Regression Model Specification (classification)
Computational engine: nnet
Randomly split your training data into 3 partitions:
sesame_fit_rs1 <- sesame_wflow1 |>
fit_resamples(resamples = folds,
metrics = metric_set(accuracy, roc_auc))
sesame_fit_rs1# Resampling results
# 3-fold cross-validation
# A tibble: 3 Γ 4
splits id .metrics .notes
<list> <chr> <list> <list>
1 <split [120/60]> Fold1 <tibble [2 Γ 4]> <tibble [0 Γ 3]>
2 <split [120/60]> Fold2 <tibble [2 Γ 4]> <tibble [0 Γ 3]>
3 <split [120/60]> Fold3 <tibble [2 Γ 4]> <tibble [0 Γ 3]>
# A tibble: 2 Γ 6
.metric .estimator mean n std_err .config
<chr> <chr> <dbl> <int> <dbl> <chr>
1 accuracy multiclass 0.344 3 0.0641 Preprocessor1_Model1
2 roc_auc hand_till 0.624 3 0.0341 Preprocessor1_Model1
Note: These are calculated using the assessment data
# A tibble: 6 Γ 5
id .metric .estimator .estimate .config
<chr> <chr> <chr> <dbl> <chr>
1 Fold1 accuracy multiclass 0.4 Preprocessor1_Model1
2 Fold1 roc_auc hand_till 0.644 Preprocessor1_Model1
3 Fold2 accuracy multiclass 0.217 Preprocessor1_Model1
4 Fold2 roc_auc hand_till 0.557 Preprocessor1_Model1
5 Fold3 accuracy multiclass 0.417 Preprocessor1_Model1
6 Fold3 roc_auc hand_till 0.670 Preprocessor1_Model1
To illustrate how CV works, we used v = 3:
This was useful for illustrative purposes, but v is often 5 or 10; we generally prefer 10-fold cross-validation as a default
Exploratory data analysis
Using training dataβ¦
Fit and evaluate candidate model using cross validation
Select the best fit model
Check model conditions and diagnostics
Repeat as needed until youβve landed on final model
Evaluate the final model performance using the test set
Source: R for Data Science with additions from The Art of Statistics: How to Learn from Data.