Warning: package 'broom' was built under R version 4.2.2
Warning: package 'dials' was built under R version 4.2.2
Warning: package 'infer' was built under R version 4.2.2
Warning: package 'modeldata' was built under R version 4.2.2
Warning: package 'parsnip' was built under R version 4.2.2
Warning: package 'recipes' was built under R version 4.2.2
Warning: package 'rsample' was built under R version 4.2.2
Warning: package 'tune' was built under R version 4.2.2
Warning: package 'workflows' was built under R version 4.2.2
Warning: package 'workflowsets' was built under R version 4.2.2
Warning: package 'yardstick' was built under R version 4.2.2
── Conflicts ───────────────────────────────────────── tidymodels_conflicts() ──
✖ scales::discard() masks purrr::discard()
✖ dplyr::filter() masks stats::filter()
✖ recipes::fixed() masks stringr::fixed()
✖ dplyr::lag() masks stats::lag()
✖ yardstick::spec() masks readr::spec()
✖ recipes::step() masks stats::step()
• Dig deeper into tidy modeling with R at https://www.tmwr.org
library(dplyr)data <-readRDS(here('fluanalysis/data/SypAct_clean.rds')) #upload cleaned datatibble(data) #overview of data
# A tibble: 730 × 26
SwollenLymph…¹ Chest…² Chill…³ Nasal…⁴ Sneeze Fatigue Subje…⁵ Heada…⁶ Weakn…⁷
<fct> <fct> <fct> <fct> <fct> <fct> <fct> <fct> <fct>
1 Yes No No No No Yes Yes Yes Mild
2 Yes Yes No Yes No Yes Yes Yes Severe
3 Yes Yes Yes Yes Yes Yes Yes Yes Severe
4 Yes Yes Yes Yes Yes Yes Yes Yes Severe
5 Yes No Yes No No Yes Yes Yes Modera…
6 No No Yes No Yes Yes Yes Yes Modera…
7 No No Yes No No Yes Yes No Mild
8 No Yes Yes Yes Yes Yes Yes Yes Severe
9 Yes Yes Yes Yes No Yes Yes Yes Modera…
10 No Yes No Yes No Yes No Yes Modera…
# … with 720 more rows, 17 more variables: CoughIntensity <fct>, Myalgia <fct>,
# RunnyNose <fct>, AbPain <fct>, ChestPain <fct>, Diarrhea <fct>,
# EyePn <fct>, Insomnia <fct>, ItchyEye <fct>, Nausea <fct>, EarPn <fct>,
# Pharyngitis <fct>, Breathless <fct>, ToothPn <fct>, Vomit <fct>,
# Wheeze <fct>, BodyTemp <dbl>, and abbreviated variable names
# ¹SwollenLymphNodes, ²ChestCongestion, ³ChillsSweats, ⁴NasalCongestion,
# ⁵SubjectiveFever, ⁶Headache, ⁷Weakness
Split Data
set.seed(123)# Fix the random numbers by setting the seed # This enables the analysis to be reproducible when random numbers are used data_split <-initial_split(data, prop =3/4)# Create data frames for the two sets:train_data <-training(data_split)test_data <-testing(data_split)
Make a recipe and fit a model
# Create recipe using Nausea as categorical variabledata_recipe <-recipe(Nausea ~ ., data = train_data)# Logistic model reciperecipe_mod <-logistic_reg() %>%set_engine("glm")# Model workflow to pair model and recipe mod_flow <-workflow() %>%add_model(recipe_mod) %>%add_recipe(data_recipe)mod_flow