Advertisement
SixPathsOfMen

I Can Take Joe Biden in a Fist Fight

Jun 25th, 2022
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.54 KB | None | 0 0
  1. ```{r, results='hide', message=FALSE, warning=FALSE}
  2. library(mdsr)
  3. library(mosaic)
  4. library(tidyverse)
  5. library(gapminder)
  6. library("rmarkdown")
  7. library(dplyr)
  8. library(class)
  9. library(e1071)
  10. library(ROCR)
  11. library(NHANES)
  12. library(rpart)
  13. library(rpart.plot)
  14. library(tidyr)
  15. ```
  16.  
  17. 1. If you look at the class notes, you will see that the dataset NHANES has 76 variables. In this homework, you will select a subset of the data targeting a specific group of people doing analysis using the filter command. For example, If we looking at the group of married people, you will use;
  18.  
  19. ```{r, results='hide', message=FALSE, warning=FALSE}
  20. Married1 <- filter(NHANES, MaritalStatus =="Married")
  21.  
  22. Married1
  23. ```
  24.  
  25. 2. Count the percentage of married persons have Diabetes
  26.  
  27. ```{r, results='hide', message=FALSE, warning=FALSE}
  28. tally(~ Diabetes, data= people, format = "percent")
  29. ```
  30.  
  31. 3. Using the Married people's data, select columns of Age, Diabetes, BMI, TotChol, PhysActive from the data
  32.  
  33. ```{r, results='hide', message=FALSE, warning=FALSE}
  34. NHANES %>%
  35.    select(c("TotChol","Age","Diabetes","BMI", "PhysActive"))
  36. ```
  37.  
  38. 4. Use rpart to generate a decision tree classification model using:
  39.  
  40. ```{r, results='hide', message=FALSE, warning=FALSE}
  41. whoIsDiabetic <-rpart( Diabetes ~ Age +BMI +TotChol +PhysActive, data =people, control =rpart.control(cp =0.005, minbucket = 30))
  42. rpart.plot(whoIsDiabetic, extra=4)
  43.  
  44. whoIsDiabetic
  45. ```
  46.  
  47. 6. Discuss any difference between this decision tree and the first one decision tree shown in the lecture notes.
  48.  
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement