Browsing resource, all submissions are temporary.
The csv file for the Stat 100 Survey 2 data in Fall 2013 can be downloaded here. Download the file and load it to R using the command
survey <- read.csv("stat100_2013fall_survey02.csv")
Here is a description of the data in each column. Explore the data.
The histogram() function in the lattics graphics system can also be applied to categorical data (i.e. factor variables). The result is a barplot. Try the following commands:
histogram()
library(lattice) histogram(~religion, data=survey)
a. Use the histogram() function to make split plots of 'religion' for each ethnicity. You will need to increase the width of the graph in order to separate the labels. In R Studio, this can be done by clicking the "Zoom" button on the Plot panel. A separete window for the plot will pop up and you can maximize the window. From the plots, what is the most popular religion for the ethnic group "Black/African American"? Christianity Buddhism Hinduism Islam Other religions Judaism
b. Which ethnic groups have students believing in Hinduism? (Select all that apply) Hispanic/Latino White Mixed/Other Black/African American Asian
c. Which group of students has the highest percentage of having same sex experience? Buddhist Christian Muslim Jewish Atheist Hindu Other religion Agnostic
d. Consider the following two commands plotting number of sex partners versus number of relationship:
plot(jitter(sexPartners) ~ jitter(relationships), pch=16, col=gender, data=survey)
plot(jitter(sexPartners) ~ jitter(relationships), pch=16, col=1:2, data=survey)
What is the difference between these two commands? In the first command, females are plotted as black and males are plotted as red. In the second command, odd observations are plotted as black and even observations are plotted as red. In the first command, females are plotted as red and males are plotted as black. In the second command, females are black and males are red. In the first command, females are plotted as black and males are plotted as red. In the second command, females are red and males are black. There is no difference. They are the same. None of the above
e. Continuing with the question in (d). suppose I want to plot males in green and females in red. Which of the following commands produce the desired plot? (Select all that apply) plot(jitter(sexPartners) ~ jitter(relationships), pch=16, col=4-as.integer(gender), data=survey) plot(jitter(sexPartners) ~ jitter(relationships), pch=16, col=3:2, data=survey) plot(jitter(sexPartners) ~ jitter(relationships), pch=16, col=gender+1, data=survey) plot(jitter(sexPartners) ~ jitter(relationships), pch=16, col=4-gender, data=survey) plot(jitter(sexPartners) ~ jitter(relationships), pch=16, col=as.integer(gender)+1, data=survey) cols <- c("red","green"); plot(jitter(sexPartners) ~ jitter(relationships), pch=16, col=cols[gender], data=survey) plot(jitter(sexPartners) ~ jitter(relationships), pch=16, col=2:3, data=survey) cols <- c("red","green"); plot(jitter(sexPartners) ~ jitter(relationships), pch=16, col=cols[as.integer(gender)], data=survey) None of the above
plot(jitter(sexPartners) ~ jitter(relationships), pch=16, col=4-as.integer(gender), data=survey)
plot(jitter(sexPartners) ~ jitter(relationships), pch=16, col=3:2, data=survey)
plot(jitter(sexPartners) ~ jitter(relationships), pch=16, col=gender+1, data=survey)
plot(jitter(sexPartners) ~ jitter(relationships), pch=16, col=4-gender, data=survey)
plot(jitter(sexPartners) ~ jitter(relationships), pch=16, col=as.integer(gender)+1, data=survey)
cols <- c("red","green"); plot(jitter(sexPartners) ~ jitter(relationships), pch=16, col=cols[gender], data=survey)
plot(jitter(sexPartners) ~ jitter(relationships), pch=16, col=2:3, data=survey)
cols <- c("red","green"); plot(jitter(sexPartners) ~ jitter(relationships), pch=16, col=cols[as.integer(gender)], data=survey)