Advertisement
Davejee

Unit 541/551

Dec 6th, 2023
1,750
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.05 KB | None | 0 0
  1. library(tidyverse)
  2. library(janitor)
  3. library(broom)
  4.  
  5. data541 <- read.csv("unit_541_practice_data.csv")
  6. data541 %>% View()
  7.  
  8. groups <- data541 %>%
  9.   group_by(group) %>%
  10.   summarise_at(vars(happy),
  11.                list(means = mean))
  12.  
  13. model <- data541 %>% lm(happy ~ group, .)
  14.  
  15. # create dummy variables
  16. data541$group_dummy_1 <- ifelse(data541$group == "Group 1", 1, 0)
  17. data541$group_dummy_2 <- ifelse(data541$group == "Group 2", 1, 0)
  18. data541$group_dummy_3 <- ifelse(data541$group == "Group 3", 1, 0)
  19.  
  20. # create a linear model where 3 is the reference category
  21. data541 %>% lm(happy ~ group_dummy_1 + group_dummy_2, .) %>% summary
  22.  
  23. # ANOVA
  24. model %>%
  25.   anova() %>%
  26.   tidy()
  27.  
  28. summary(model)
  29.  
  30. # Unit 551
  31. data551 <- read.csv("unit_551_practice_data.csv")
  32. data551 %>% View()
  33.  
  34. # boxplot
  35. data551 %>%
  36.   ggplot(aes(x = method, y = bacteria)) +
  37.   geom_boxplot()
  38.  
  39. # linear model
  40. data551$method <- as.factor(data551$method)
  41.  
  42. model2 <- data551 %>%
  43.   lm(bacteria ~ method, data = .)
  44. summary(model2)  
  45.  
  46. # ANOVA
  47. model2 %>%
  48.   anova() %>%
  49.   tidy()
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement