Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- **CHUNK 1 STARTS BELOW THIS LINE.
- ```{r}
- #YOU WILL ALWAYS NEED THIS FIRST CHUNK. WE WILL ADD TO IT DURING THE SEMESTER.
- #THIS CHUNK LOADS THE LIBRARIES AND DATA THAT YOU NEED FOR YOUR WORK.
- library(aws.s3)
- library('lehmansociology')
- s3load('gss.Rda', bucket = 'lehmansociologydata')
- #View(GSS)
- #the line of code above View(GSS) would allow you to see the spreadsheet view of the data.
- #remember, since there is a # before View(GSS), R is treating it like a NOTE and not a command.
- #if you want to see the spreadsheet view of the data, you have to delete the # that starts that line.
- #R will not allow you to "Knit PDF" if you do not have a # before View(GSS)
- ```
- **CHUNK 2 STARTS BELOW THIS LINE.
- ```{r}
- frequency(GSS$race)
- ```
- WRITE 1-2 SENTENCES BELOW THAT INTERPRET THE RESULTS OF THE FREQUENCY TABLE FOR RACE THAT YOU GET FROM RUNNING THE CHUNK ABOVE.
- **CHUNK 3 STARTS BELOW THIS LINE.
- ```{r}
- frequency(GSS$health)
- ```
- WRITE 1-2 SENTENCES BELOW THAT INTERPRET THE RESULTS OF THE FREQUENCY TABLE FOR HEALTH THAT YOU GET FROM RUNNING THE CHUNK ABOVE.
- **CHUNK 4 STARTS BELOW THIS LINE.
- ```{r}
- frequency(GSS$childs)
- ```
- WRITE 1-2 SENTENCES BELOW THAT INTERPRET THE RESULTS OF THE FREQUENCY TABLE FOR CHILDS THAT YOU GET FROM RUNNING THE CHUNK ABOVE.
- **CHUNK 5 STARTS BELOW THIS LINE.
- ```{r}
- frequency(GSS$age)
- ```
- Notice how long the frequency table is for age when you have single categories of age as an
- interval-ratio variable. It is also possible to "recode" the variable into categories.
- Below is one example of recoding age into a dichotomous variable named "youngadult".
- **CHUNK 6 STARTS BELOW THIS LINE.
- ```{r}
- GSS$youngadult <- GSS$age <= 25
- #the line of code above creates a new variable named "youngadult" in the GSS dataset.
- #notice in the enrionment window that it now says GSS has 69 variables instead of the 68 we started with.
- #the line of code below asks R to give you a frequency table for the new variable.
- frequency(GSS$youngadult)
- ```
- 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.
- BELOW WE WILL SEE SOME CROSSTABS OF 2 VARIABLES.
- **CHUNK 7 STARTS BELOW THIS LINE.
- ```{r}
- crosstab(GSS, row.vars ="health", col.vars = "youngadult")
- #compare the result that you get from running the line of code above and the line below.
- crosstab(GSS, row.vars ="health", col.vars = "youngadult", format="column_percent", row.margin.format = "percent")
- #here is another crosstab with 2 different variables
- crosstab(GSS, row.vars = "childs", col.vars = "race", format="column_percent", row.margin.format = "percent")
- ```
- LOOKING AT A CROSSTABS ABOVE, ANSWER THE FOLLOWING QUESTIONS:
- (a) What does "Total N" show you?
- (b) What are you shown in the marginal column labeled "Total"?
- (c) Where is 100%?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement