Advertisement
Davejee

Unit 531

Dec 6th, 2023
1,000
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.74 KB | None | 0 0
  1. library(tidyverse)
  2. library(janitor)
  3. library(haven)
  4. library(broom)
  5. library(foreign)
  6. install.packages("haven")
  7.  
  8.  
  9. healthdata <- read_spss("Health_LISS_Core_Study_Wave_12_2020_data_plus_background_small.sav")
  10. healthdata %>% View()
  11. healthdata %>%
  12.   ggplot() +
  13.   geom_histogram(aes(x = nettoink))
  14.  
  15. # filter income
  16. healthdata <- healthdata %>%
  17.   filter(nettoink <= 15000)
  18.  
  19. # scatterplot
  20. healthdata %>%
  21.   ggplot(aes(x = nettoink, y = BMI)) +
  22.   geom_point() +
  23.   geom_smooth(method = "lm", se = F)
  24.  
  25. # linear regression
  26. model <- healthdata %>%
  27.   lm(BMI ~ nettoink, data = .)
  28.  
  29. model %>% tidy()
  30. summary(model)
  31.  
  32. # 95% confidence interval
  33. confint(model, 'nettoink', level=0.95) %>%
  34.   as.data.frame() %>%
  35.   mutate_if(is.numeric, round, 6)
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement