Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. **CHUNK 1 STARTS BELOW THIS LINE.
  2. ```{r}
  3. #YOU WILL ALWAYS NEED THIS FIRST CHUNK. WE WILL ADD TO IT DURING THE SEMESTER.
  4. #THIS CHUNK LOADS THE LIBRARIES AND DATA THAT YOU NEED FOR YOUR WORK.
  5. library(aws.s3)
  6. library('lehmansociology')
  7.  
  8. s3load('gss.Rda', bucket = 'lehmansociologydata')
  9. #View(GSS)
  10. #the line of code above View(GSS) would allow you to see the spreadsheet view of the data.
  11. #remember, since there is a # before View(GSS), R is treating it like a NOTE and not a command.
  12. #if you want to see the spreadsheet view of the data, you have to delete the # that starts that line.
  13. #R will not allow you to "Knit PDF" if you do not have a # before View(GSS)
  14. ```
  15.  
  16. **CHUNK 2 STARTS BELOW THIS LINE.
  17. ```{r}
  18. frequency(GSS$race)
  19. ```
  20. WRITE 1-2 SENTENCES BELOW THAT INTERPRET THE RESULTS OF THE FREQUENCY TABLE FOR RACE THAT YOU GET FROM RUNNING THE CHUNK ABOVE.
  21.  
  22.  
  23. **CHUNK 3 STARTS BELOW THIS LINE.
  24. ```{r}
  25. frequency(GSS$health)
  26. ```
  27. WRITE 1-2 SENTENCES BELOW THAT INTERPRET THE RESULTS OF THE FREQUENCY TABLE FOR HEALTH THAT YOU GET FROM RUNNING THE CHUNK ABOVE.
  28.  
  29.  
  30. **CHUNK 4 STARTS BELOW THIS LINE.
  31. ```{r}
  32. frequency(GSS$childs)
  33. ```
  34. WRITE 1-2 SENTENCES BELOW THAT INTERPRET THE RESULTS OF THE FREQUENCY TABLE FOR CHILDS THAT YOU GET FROM RUNNING THE CHUNK ABOVE.
  35.  
  36. **CHUNK 5 STARTS BELOW THIS LINE.
  37. ```{r}
  38. frequency(GSS$age)
  39. ```
  40. Notice how long the frequency table is for age when you have single categories of age as an
  41. interval-ratio variable. It is also possible to "recode" the variable into categories.
  42. Below is one example of recoding age into a dichotomous variable named "youngadult".
  43. **CHUNK 6 STARTS BELOW THIS LINE.
  44. ```{r}
  45. GSS$youngadult <- GSS$age <= 25
  46. #the line of code above creates a new variable named "youngadult" in the GSS dataset.
  47. #notice in the enrionment window that it now says GSS has 69 variables instead of the 68 we started with.
  48. #the line of code below asks R to give you a frequency table for the new variable.
  49. frequency(GSS$youngadult)
  50. ```
  51. WRITE 1-2 SENTENCES BELOW THAT INTERPRET THE RESULTS OF THE FREQUENCY TABLE FOR YOUNGADULT THAT YOU GET FROM RUNNING THE CHUNK ABOVE. YOU MIGHT WANT TO NOTE WHAT "TRUE" AND "FALSE" MEAN.
  52.  
  53.  
  54. BELOW WE WILL SEE SOME CROSSTABS OF 2 VARIABLES.
  55. **CHUNK 7 STARTS BELOW THIS LINE.
  56. ```{r}
  57. crosstab(GSS, row.vars ="health", col.vars = "youngadult")
  58. #compare the result that you get from running the line of code above and the line below.
  59. crosstab(GSS, row.vars ="health", col.vars = "youngadult", format="column_percent", row.margin.format = "percent")
  60.  
  61. #here is another crosstab with 2 different variables
  62. crosstab(GSS, row.vars = "childs", col.vars = "race", format="column_percent", row.margin.format = "percent")
  63. ```
  64. LOOKING AT A CROSSTABS ABOVE, ANSWER THE FOLLOWING QUESTIONS:
  65. (a) What does "Total N" show you?
  66. (b) What are you shown in the marginal column labeled "Total"?
  67. (c) Where is 100%?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement