lab2.2

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.2     ✔ tibble    3.2.1
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.0.4     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
class_survey <- read_csv("https://tinyurl.com/stat20-fall25-class-survey")
Rows: 751 Columns: 31
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (16): time_at_cal, major, coding_exp_words, calc, cal_fav, piercings, di...
dbl  (8): coding_exp_scale, pets_and_sibs, tech_relationships, climate, cryp...
lgl  (7): is_artist, is_comp_sci, is_entrepreneur, is_humanist, is_nat_sci, ...

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
glimpse(class_survey)
Rows: 751
Columns: 31
$ time_at_cal        <chr> "This is my first semester!", "This is my first sem…
$ major              <chr> "econ", "Economics", "Economics", "Psychology", "Co…
$ coding_exp_words   <chr> "Very little. I've just dipped my toe in.", "None."…
$ coding_exp_scale   <dbl> 5, 1, 1, 1, 1, 1, 1, 1, 6, 5, 6, 1, 2, 1, 1, 3, 6, …
$ calc               <chr> "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "N…
$ cal_fav            <chr> "I really like the learning atmosphere here", "The …
$ piercings          <chr> "0", "0", "0", "5+", "5+", "0", "2", "2", "0", "0",…
$ pets_and_sibs      <dbl> 1, 2, 1, 3, 2, 1, 1, 2, 0, 4, 3, 1, 1, 0, 2, 0, 1, …
$ diet               <chr> "I eat both plants and animals.", "I eat both plant…
$ prof_label         <chr> "Artist", "Entrepreneur", "Other", "Social Scientis…
$ study_place        <chr> "DOE Library", "Dorm room", "Anywhere quiet", "I ha…
$ olympics           <chr> "Alpine skiing", "I am not excited to watch the Win…
$ season             <chr> "Spring", "Spring", "Summer", "Spring", "Winter", "…
$ mts_beach          <chr> "In the mountains", "In the mountains", "At the bea…
$ coffee_tea         <chr> "Coffee", "Tea", "I don't drink either", "Tea", "Co…
$ boba               <chr> "I don't know", "I haven't tried any yet!", "No ide…
$ tech_relationships <dbl> 2, 1, 3, 6, 8, 6, 4, 8, 5, 6, 7, 8, 4, 9, 4, 5, 5, …
$ climate            <dbl> 7, 10, 8, 7, 6, 7, 6, 3, 6, 3, 7, 5, 5, 8, 2, 5, 10…
$ crypto             <dbl> 7, 10, 2, 4, 5, 9, 7, 8, 5, 7, 8, 4, 3, 4, 5, 5, 10…
$ ai                 <dbl> 3, 1, 5, 8, 8, 8, 6, 8, 6, 4, 5, 8, 6, 8, 8, 6, 1, …
$ covid              <dbl> 0.330, 0.050, 0.150, 0.005, 0.028, 0.100, 0.500, 0.…
$ eagles             <dbl> 0.20, 0.00, 0.67, 0.50, 0.50, 0.20, 0.30, 0.30, 0.1…
$ hotdogs            <chr> "No", "No", "No", "No", "Yes", "No", "No", "No", "N…
$ horse_duck         <chr> "Duck-sized horse", "Duck-sized horse", "Duck-sized…
$ is_artist          <lgl> TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FAL…
$ is_comp_sci        <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FA…
$ is_entrepreneur    <lgl> FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FAL…
$ is_humanist        <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FAL…
$ is_nat_sci         <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FA…
$ is_other           <lgl> FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, TRUE…
$ is_soc_sci         <lgl> FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALS…
  1. Do students prefer to spend time at the beach or in the mountains?
library(ggplot2)
ggplot(class_survey, aes(x = mts_beach)) +
  geom_bar() +
  labs(
    title = "Preference for Beach or Mountain",
    x = "Preference (Beach/Mountain)",
    y = "Count of Students"
  )

  1. Is there an association between students’ favorite season and terrain preference (beach or mountains)?

    library(ggplot2)
    ggplot(class_survey, mapping = aes(x=mts_beach, fill = season))+
      geom_bar(position="fill")

  2. How much coding experience do students have? (numerical scale)

    library(ggplot2)
    ggplot(class_survey, mapping = aes(x=coding_exp_scale))+
      geom_bar()

    mean(class_survey $coding_exp_scale)
    [1] 3.243675
  3. What is the relationship between students’ optimism for cryptocurrency and their skepticism of the effect of technology on interpersonal relationships?

ggplot(class_survey, aes(x = factor(is_humanist), y = crypto, fill = factor(is_humanist))) +
  geom_boxplot() +
  labs(
    title = "Crypto Optimism by Humanist Identity",
    x = "Humanist Identity (TRUE/FALSE)",
    y = "Optimism for Cryptocurrency (Crypto)"
  ) +
  theme_minimal()

ggplot(class_survey, aes(x = factor(is_entrepreneur), y = crypto, fill = factor(is_entrepreneur))) +
  geom_boxplot() +
  labs(
    title = "Crypto Optimism by Entrepreneur Identity",
    x = "Entrepreneur Identity (TRUE/FALSE)",
    y = "Optimism for Cryptocurrency (Crypto)"
  ) +
  theme_minimal()

  1. Yes, there is a relationship. The optimism is higher for the entrepreneur. group, indicating greater optimism for cryptocurrency.

  2. Yes, there is a relationship. Students who do not identify as humanists tend to be more optimistic about cryptocurrency.

  3. Students who identify as entrepreneurs have a higher average optimism for cryptocurrency (6.35) compared to those who do not identify as entrepreneurs (5.41).

    library(ggplot2)
    
    # Calculate the means for each group (Entrepreneur vs Non-Entrepreneur)
    mean_crypto_entrepreneur <- mean(class_survey$crypto[class_survey$is_entrepreneur == TRUE], na.rm = TRUE)
    mean_crypto_non_entrepreneur <- mean(class_survey$crypto[class_survey$is_entrepreneur == FALSE], na.rm = TRUE)
    
    # Create the boxplot
    ggplot(class_survey, aes(x = factor(is_entrepreneur), y = crypto, fill = factor(is_entrepreneur))) +
      geom_boxplot() +
      labs(
        title = "Crypto Optimism by Entrepreneur Identity",
        x = "Entrepreneur Identity (TRUE/FALSE)",
        y = "Optimism for Cryptocurrency (Crypto)"
      ) +
      theme_minimal() +
      # Add the mean value labels to the plot
      geom_text(aes(x = 1, y = mean_crypto_entrepreneur + 0.2, label = paste("Mean:", round(mean_crypto_entrepreneur, 2))), color = "blue", size = 5) +
      geom_text(aes(x = 2, y = mean_crypto_non_entrepreneur + 0.2, label = paste("Mean:", round(mean_crypto_non_entrepreneur, 2))), color = "red", size = 5)

  4. Comp Sci students VS Crypto Optimism

library(ggplot2)
mean_crypto_cs <- mean(class_survey$crypto[class_survey$is_comp_sci == TRUE], na.rm = TRUE)
mean_crypto_non_cs <- mean(class_survey$crypto[class_survey$is_comp_sci == FALSE], na.rm = TRUE)
mean_data <- data.frame(
  Group = c("CS Students", "Non-CS Students"),
  MeanCrypto = c(mean_crypto_cs, mean_crypto_non_cs)
)

ggplot(mean_data, aes(x = Group, y = MeanCrypto, fill = Group)) +
  geom_bar(stat = "identity") +
  labs(
    title = "Crypto Optimism by Major (CS vs Non-CS)",
    x = "Group",
    y = "Average Optimism for Cryptocurrency"
  ) +
  theme_minimal() +
  scale_fill_manual(values = c("blue", "red")) 

Non-CS students have higher optimism for cryptocurrency than CS students