Assignment 10: T-tests
In this analysis of the T-test,the continuous variable used was Feelings to Police and the categorical variable was Gender. Gender only had two responses, Male and Female, therefore it did not need to filter further.
library(readr)
library(dplyr)
library(knitr)
library(ggplot2)
VoterData<-read_csv("/Users/safiesaf/Downloads/VOTER_Survey_July17_Release1-csv.csv")
New4Data<-VoterData%>%
rename("Gender"=gender_baseline,
"Feelings_To_Police"=ft_police_2017)%>%
mutate(Gender=ifelse(Gender==1,"Male","Female"),
Feelings_To_Police=ifelse(Feelings_To_Police==997,NA,Feelings_To_Police))%>%
select(Gender,Feelings_To_Police)
kable(head(New4Data))
| Gender | Feelings_To_Police |
|---|---|
| Female | 76 |
| Female | 95 |
| Male | 78 |
| Male | NA |
| Male | 94 |
| Female | 28 |
For the variable Gender,the male respondents had a mean of 75, as for the female respondents,there was a mean of approximately the same 75.
New4Data%>%
group_by(Gender)%>%
summarize(Feelings_To_Police=mean(Feelings_To_Police, na.rm = TRUE))%>%
kable()
| Gender | Feelings_To_Police |
|---|---|
| Female | 75.91523 |
| Male | 75.51218 |
For the histograms, the respondents’ feelings toward police were very similar, there was little to no difference between the two. As for the t-test, the p value was > 0.05 therefore it was NOT statistically significant and we FAILED to reject the null hypothesis.
library(ggplot2)
New4Data%>%
filter(Gender=="Female")%>%
ggplot()+
geom_histogram(aes(Feelings_To_Police), fill="red")+
ggtitle("Females' feelings toward police")
New4Data%>%
filter(Gender=="Male")%>%
ggplot()+
geom_histogram(aes(Feelings_To_Police), fill="black")+
ggtitle("Males' feelings toward police")
t.test(Feelings_To_Police~Gender, data=New4Data)
##
## Welch Two Sample t-test
##
## data: Feelings_To_Police by Gender
## t = 0.57219, df = 4816.3, p-value = 0.5672
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.9778848 1.7839842
## sample estimates:
## mean in group Female mean in group Male
## 75.91523 75.51218