Method One:
mytable <- table(lhs$AGENDER,lhs$AV1GUM)
mytable
##
## 0 1
## F 1708 387
## M 2942 551
Method Two:
mytable2<-matrix(
c(387,2095-387,551,3493-551), #specifying the cell values
nrow=2, #specifying the number of rows
ncol=2, #specifying the number of columns
byrow=TRUE, #create the matrix by rows
dimnames=list(c("Female", "Male"),
c("Used nicotine gum", "Did not use nicotine gum")))
mytable2
## Used nicotine gum Did not use nicotine gum
## Female 387 1708
## Male 551 2942
Chi-squared test of independence
mychi.test<-chisq.test(mytable, correct=FALSE)
mychi.test
##
## Pearson's Chi-squared test
##
## data: mytable
## X-squared = 6.8252, df = 1, p-value = 0.008988
#expected as a saved object
mychi.test$expected
##
## 0 1
## F 1743.334 351.6661
## M 2906.666 586.3339
lhs$AV1GUM_1<-factor(lhs$AV1GUM, levels=c(0,1),
labels=c("No use","Used nicotine gum"))
mytable3 <- table(lhs$AGENDER,lhs$AV1GUM_1)
mytable3
##
## No use Used nicotine gum
## F 1708 387
## M 2942 551
mychi.test1<-chisq.test(mytable3, correct=FALSE)
mychi.test1
##
## Pearson's Chi-squared test
##
## data: mytable3
## X-squared = 6.8252, df = 1, p-value = 0.008988
mychi.test1$observed
##
## No use Used nicotine gum
## F 1708 387
## M 2942 551
mychi.test1$expected
##
## No use Used nicotine gum
## F 1743.334 351.6661
## M 2906.666 586.3339
ggplot(data = lhs, aes(AGENDER, AV1GUM_1)) +
geom_col() +
facet_grid(~AV1GUM_1 )
***
Significance level of 0.05 because making a type 1 error doesn’t look like it is high risk.
The test statistic is 6.8252 and the degree of freedom is 1.
The p-value is 0.008988.
The p-value is 0.008988.
We reject the null hypotheses because the p-value 0.008988 is less than our significance level of 0.05. We conclude that the data provided convincing evidence that the use of nicotine gum is associated with the gender of the participant.
DO NOT simply write “we reject the null hypothesis because p<.05”.
One example: The probability of observing our χ2 statistic or one more extreme if the (state null hypothesis here) is true, is (below/above) our significance level of ___ . Thus, we have sufficient evidence to conclude _____ (context).
Yes, its a random sample.
Yes, the variables are categorical.
Yes, each expected value of the sample observations are at least 5.
Yes, these are the same questions as in your group problem set. Let’s make sure you can do them on your own too!