Load the data

library(tidyverse)
## -- Attaching packages --------------------------------------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.2     v purrr   0.3.4
## v tibble  3.0.2     v dplyr   1.0.0
## v tidyr   1.1.0     v stringr 1.4.0
## v readr   1.3.1     v forcats 0.5.0
## -- Conflicts ------------------------------------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
setwd("C:/Users/MCuser/Dropbox/Rachel/MontColl")
survey <- read_csv("springScheduleSurvey.csv")
## Parsed with column specification:
## cols(
##   ID = col_double(),
##   `Start time` = col_character(),
##   `Completion time` = col_character(),
##   full_15 = col_character(),
##   first_half = col_character(),
##   second_half = col_character(),
##   mix = col_character(),
##   dl = col_character(),
##   srt = col_character(),
##   f2f = col_character(),
##   `Distance learning (DL)2` = col_character(),
##   `Structured remote teaching (SRT)3` = col_character(),
##   `Face to Face` = col_character(),
##   class = col_character(),
##   status = col_character(),
##   employment = col_character()
## )

Clean the data

names(survey) <- tolower(names(survey))
names(survey) <- gsub(" ","_",names(survey))
head(survey)
## Warning: `...` is not empty.
## 
## We detected these problematic arguments:
## * `needs_dots`
## 
## These dots only exist to allow future extensions and should be empty.
## Did you misspecify an argument?
## # A tibble: 6 x 16
##      id start_time completion_time full_15 first_half second_half mix   dl   
##   <dbl> <chr>      <chr>           <chr>   <chr>      <chr>       <chr> <chr>
## 1     1 9/3/20 21~ 9/3/20 21:41:49 Very l~ Least lik~ Least like~ Leas~ Very~
## 2     2 9/3/20 21~ 9/3/20 21:42:54 Very l~ Neutral    Neutral     Neut~ Very~
## 3     3 9/3/20 21~ 9/3/20 21:43:55 Very l~ Somewhat ~ Somewhat l~ Leas~ More~
## 4     4 9/3/20 21~ 9/3/20 21:45:45 Very l~ Somewhat ~ Least like~ Some~ Some~
## 5     5 9/3/20 21~ 9/3/20 21:46:30 More l~ Neutral    Neutral     Neut~ Very~
## 6     6 9/3/20 21~ 9/3/20 21:49:15 Very l~ Least lik~ Least like~ Leas~ Some~
## # ... with 8 more variables: srt <chr>, f2f <chr>,
## #   `distance_learning_(dl)2` <chr>, `structured_remote_teaching_(srt)3` <chr>,
## #   face_to_face <chr>, class <chr>, status <chr>, employment <chr>
#survey %>% 
#  rename(
 #    "full_15" = "full_15_week_semester",
#   "first_half" = "first_1/2_semester_(first_7_weeks)",
 #    "second_half" = "second_1/2_semester_(last_7_weeks)",
#     "mix" = "mix_of_some_full_and_some_1/2_semester_classes",
#     "dl" = "distance_learning_(dl)",
#     "srt" = "structured_remote_teaching_(srt)",
#     "f2f" = "face_to_face",
#     "class" = "which_math/statistics/data_class_(or_classes)_are_you_thinking_about_taking_this_spring_(#you_can_select_more_than_one)",
#     "status" = "what_will_your_student_status_be_in_the_spring:",
#     "employment" = "what_do_you_think_your_employment_status_will_be_in_the_spring"
#    )

Separate multiple lists of classes

survey <- survey %>% 
    mutate(class = strsplit(as.character(class), ";")) %>% 
    unnest(class)
survey
## Warning: `...` is not empty.
## 
## We detected these problematic arguments:
## * `needs_dots`
## 
## These dots only exist to allow future extensions and should be empty.
## Did you misspecify an argument?
## # A tibble: 125 x 16
##       id start_time completion_time full_15 first_half second_half mix   dl   
##    <dbl> <chr>      <chr>           <chr>   <chr>      <chr>       <chr> <chr>
##  1     1 9/3/20 21~ 9/3/20 21:41:49 Very l~ Least lik~ Least like~ Leas~ Very~
##  2     2 9/3/20 21~ 9/3/20 21:42:54 Very l~ Neutral    Neutral     Neut~ Very~
##  3     3 9/3/20 21~ 9/3/20 21:43:55 Very l~ Somewhat ~ Somewhat l~ Leas~ More~
##  4     4 9/3/20 21~ 9/3/20 21:45:45 Very l~ Somewhat ~ Least like~ Some~ Some~
##  5     5 9/3/20 21~ 9/3/20 21:46:30 More l~ Neutral    Neutral     Neut~ Very~
##  6     6 9/3/20 21~ 9/3/20 21:49:15 Very l~ Least lik~ Least like~ Leas~ Some~
##  7     7 9/3/20 21~ 9/3/20 21:49:58 Somewh~ Very like~ Somewhat l~ Neut~ Leas~
##  8     8 9/3/20 21~ 9/3/20 21:51:55 Least ~ Least lik~ Least like~ Leas~ More~
##  9     8 9/3/20 21~ 9/3/20 21:51:55 Least ~ Least lik~ Least like~ Leas~ More~
## 10     9 9/3/20 21~ 9/3/20 21:52:11 Very l~ Very like~ Very likely Very~ Some~
## # ... with 115 more rows, and 8 more variables: srt <chr>, f2f <chr>,
## #   `distance_learning_(dl)2` <chr>, `structured_remote_teaching_(srt)3` <chr>,
## #   face_to_face <chr>, class <chr>, status <chr>, employment <chr>

Gather the data

Create a category, “likley”, that shows how likely students are to take a type of length of semester class.

surveylong <- survey %>% 
  tidyr::gather("type", "likely", 4:7) 
surveylong
## Warning: `...` is not empty.
## 
## We detected these problematic arguments:
## * `needs_dots`
## 
## These dots only exist to allow future extensions and should be empty.
## Did you misspecify an argument?
## # A tibble: 500 x 14
##       id start_time completion_time dl    srt   f2f   `distance_learn~
##    <dbl> <chr>      <chr>           <chr> <chr> <chr> <chr>           
##  1     1 9/3/20 21~ 9/3/20 21:41:49 Very~ Very~ Leas~ Very effective  
##  2     2 9/3/20 21~ 9/3/20 21:42:54 Very~ More~ Leas~ Very effective  
##  3     3 9/3/20 21~ 9/3/20 21:43:55 More~ More~ Neut~ Somewhat effect~
##  4     4 9/3/20 21~ 9/3/20 21:45:45 Some~ Leas~ Very~ Somewhat ineffe~
##  5     5 9/3/20 21~ 9/3/20 21:46:30 Very~ Very~ Leas~ Somewhat effect~
##  6     6 9/3/20 21~ 9/3/20 21:49:15 Some~ Very~ Neut~ Very ineffective
##  7     7 9/3/20 21~ 9/3/20 21:49:58 Leas~ Neut~ Very~ Somewhat ineffe~
##  8     8 9/3/20 21~ 9/3/20 21:51:55 More~ Very~ Leas~ Somewhat effect~
##  9     8 9/3/20 21~ 9/3/20 21:51:55 More~ Very~ Leas~ Somewhat effect~
## 10     9 9/3/20 21~ 9/3/20 21:52:11 Some~ Some~ More~ Somewhat effect~
## # ... with 490 more rows, and 7 more variables:
## #   `structured_remote_teaching_(srt)3` <chr>, face_to_face <chr>, class <chr>,
## #   status <chr>, employment <chr>, type <chr>, likely <chr>

The likelihood for students to take 15-week classes

library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
p1 <- surveylong %>%
  filter(type == "full_15") %>%
  ggplot(aes(x = class, fill = likely)) +
  geom_bar() +
  coord_flip() +
  theme_classic() +
  ggtitle("Preference for Full 15 Week Semester Classes")
ggplotly(p1)

The likelihood for students to take first half of the semester classes

p2 <- surveylong %>%
  filter(type == "first_half") %>%
  ggplot(aes(x = class, fill = likely)) +
  geom_bar() +
  coord_flip() +
  theme_classic() +
  ggtitle("Preference for First Half Semester Classes")
ggplotly(p2)

The likelihood for students to take second half semester classes

p3 <- surveylong %>%
  filter(type == "second_half") %>%
  ggplot(aes(x = class, fill = likely)) +
  geom_bar() +
  coord_flip() +
  theme_classic() +
  ggtitle("Preference for Second Half Semester Classes")
ggplotly(p3)

The likelihood for students to take a mix of full semester and half semester classes

p4 <- surveylong %>%
  filter(type == "mix") %>%
  ggplot(aes(x = class, fill = likely)) +
  geom_bar() +
  coord_flip() +
  theme_classic() +
  ggtitle("Preference for Mix of Full and Half Semester Classes")
ggplotly(p4)

Basic table of counts

surveylong$type <- factor(surveylong$type, levels = c("full_15", "first_half", "second_half", "mix"))
survey_table <- table(surveylong$type, surveylong$likely)
survey_table
##              
##               Least likely More likely Neutral Somewhat likely Very likely
##   full_15               10          28      12               9          66
##   first_half            27          14      31              34          19
##   second_half           31          15      30              30          19
##   mix                   34          26      31              15          19

Create a full table disaggregating classes with the type of semester duration

ftable(xtabs(~ class + type + likely, data = surveylong))
##                          likely Least likely More likely Neutral Somewhat likely Very likely
## class        type                                                                           
## DATA Classes full_15                       2           4       0               2          10
##              first_half                    2           2       3               9           2
##              second_half                   5           2       3               6           2
##              mix                           7           5       2               2           2
## MATH 050     full_15                       0           1       1               1           2
##              first_half                    0           0       3               1           1
##              second_half                   0           0       3               1           1
##              mix                           0           0       2               2           1
## MATH 092     full_15                       0           0       0               0           1
##              first_half                    0           0       0               0           1
##              second_half                   0           0       0               0           1
##              mix                           0           0       0               0           1
## MATH 098     full_15                       0           0       1               0           2
##              first_half                    0           1       1               0           1
##              second_half                   0           0       2               0           1
##              mix                           0           2       0               0           1
## MATH 117     full_15                       4           4       2               2           8
##              first_half                    4           2       3               6           5
##              second_half                   5           2       3               6           4
##              mix                           5           3       6               3           3
## MATH 120     full_15                       1           3       1               2           4
##              first_half                    4           2       1               4           0
##              second_half                   2           4       3               2           0
##              mix                           3           5       1               1           1
## MATH 150     full_15                       2           4       3               0           9
##              first_half                    5           1       3               5           4
##              second_half                   6           2       3               3           4
##              mix                           6           4       4               2           2
## MATH 165     full_15                       0           3       1               0           4
##              first_half                    3           1       2               1           1
##              second_half                   3           0       1               3           1
##              mix                           2           0       2               3           1
## MATH 181     full_15                       1           3       1               1           8
##              first_half                    2           2       7               2           1
##              second_half                   3           3       4               3           1
##              mix                           2           4       5               0           3
## MATH 182     full_15                       0           3       2               0           9
##              first_half                    4           3       5               0           2
##              second_half                   4           2       5               1           2
##              mix                           5           1       5               1           2
## MATH 280     full_15                       0           0       0               1           3
##              first_half                    0           0       1               2           1
##              second_half                   0           0       1               2           1
##              mix                           1           1       2               0           0
## MATH 282     full_15                       0           1       0               0           4
##              first_half                    3           0       1               1           0
##              second_half                   3           0       0               1           1
##              mix                           3           1       1               0           0
## MATH 284     full_15                       0           2       0               0           2
##              first_half                    0           0       1               3           0
##              second_half                   0           0       2               2           0
##              mix                           0           0       1               1           2
#library(gmodels)
#library(descr)
#CrossTable(surveylong$class, surveylong$type, digits = 2, prop.r = TRUE, prop.c = TRUE)
mytable <- xtabs(~ surveylong$class+ surveylong$type + surveylong$likely)
round(prop.table(mytable, 1),2)
## , , surveylong$likely = Least likely
## 
##                 surveylong$type
## surveylong$class full_15 first_half second_half  mix
##     DATA Classes    0.03       0.03        0.07 0.10
##     MATH 050        0.00       0.00        0.00 0.00
##     MATH 092        0.00       0.00        0.00 0.00
##     MATH 098        0.00       0.00        0.00 0.00
##     MATH 117        0.05       0.05        0.06 0.06
##     MATH 120        0.02       0.09        0.05 0.07
##     MATH 150        0.03       0.07        0.08 0.08
##     MATH 165        0.00       0.09        0.09 0.06
##     MATH 181        0.02       0.04        0.05 0.04
##     MATH 182        0.00       0.07        0.07 0.09
##     MATH 280        0.00       0.00        0.00 0.06
##     MATH 282        0.00       0.15        0.15 0.15
##     MATH 284        0.00       0.00        0.00 0.00
## 
## , , surveylong$likely = More likely
## 
##                 surveylong$type
## surveylong$class full_15 first_half second_half  mix
##     DATA Classes    0.06       0.03        0.03 0.07
##     MATH 050        0.05       0.00        0.00 0.00
##     MATH 092        0.00       0.00        0.00 0.00
##     MATH 098        0.00       0.08        0.00 0.17
##     MATH 117        0.05       0.03        0.03 0.04
##     MATH 120        0.07       0.05        0.09 0.11
##     MATH 150        0.06       0.01        0.03 0.06
##     MATH 165        0.09       0.03        0.00 0.00
##     MATH 181        0.05       0.04        0.05 0.07
##     MATH 182        0.05       0.05        0.04 0.02
##     MATH 280        0.00       0.00        0.00 0.06
##     MATH 282        0.05       0.00        0.00 0.05
##     MATH 284        0.12       0.00        0.00 0.00
## 
## , , surveylong$likely = Neutral
## 
##                 surveylong$type
## surveylong$class full_15 first_half second_half  mix
##     DATA Classes    0.00       0.04        0.04 0.03
##     MATH 050        0.05       0.15        0.15 0.10
##     MATH 092        0.00       0.00        0.00 0.00
##     MATH 098        0.08       0.08        0.17 0.00
##     MATH 117        0.03       0.04        0.04 0.07
##     MATH 120        0.02       0.02        0.07 0.02
##     MATH 150        0.04       0.04        0.04 0.06
##     MATH 165        0.03       0.06        0.03 0.06
##     MATH 181        0.02       0.12        0.07 0.09
##     MATH 182        0.04       0.09        0.09 0.09
##     MATH 280        0.00       0.06        0.06 0.12
##     MATH 282        0.00       0.05        0.00 0.05
##     MATH 284        0.00       0.06        0.12 0.06
## 
## , , surveylong$likely = Somewhat likely
## 
##                 surveylong$type
## surveylong$class full_15 first_half second_half  mix
##     DATA Classes    0.03       0.12        0.08 0.03
##     MATH 050        0.05       0.05        0.05 0.10
##     MATH 092        0.00       0.00        0.00 0.00
##     MATH 098        0.00       0.00        0.00 0.00
##     MATH 117        0.03       0.07        0.07 0.04
##     MATH 120        0.05       0.09        0.05 0.02
##     MATH 150        0.00       0.07        0.04 0.03
##     MATH 165        0.00       0.03        0.09 0.09
##     MATH 181        0.02       0.04        0.05 0.00
##     MATH 182        0.00       0.00        0.02 0.02
##     MATH 280        0.06       0.12        0.12 0.00
##     MATH 282        0.00       0.05        0.05 0.00
##     MATH 284        0.00       0.19        0.12 0.06
## 
## , , surveylong$likely = Very likely
## 
##                 surveylong$type
## surveylong$class full_15 first_half second_half  mix
##     DATA Classes    0.14       0.03        0.03 0.03
##     MATH 050        0.10       0.05        0.05 0.05
##     MATH 092        0.25       0.25        0.25 0.25
##     MATH 098        0.17       0.08        0.08 0.08
##     MATH 117        0.10       0.06        0.05 0.04
##     MATH 120        0.09       0.00        0.00 0.02
##     MATH 150        0.12       0.06        0.06 0.03
##     MATH 165        0.12       0.03        0.03 0.03
##     MATH 181        0.14       0.02        0.02 0.05
##     MATH 182        0.16       0.04        0.04 0.04
##     MATH 280        0.19       0.06        0.06 0.00
##     MATH 282        0.20       0.00        0.05 0.00
##     MATH 284        0.12       0.00        0.00 0.12