Q1(b).

For Males

# Add pdflatex to PATH: Sys.setenv(PATH=paste(Sys.getenv("PATH"),"C:/Users/Wei Hao/AppData/Local/Programs/MiKTeX 2.9/miktex/bin/x64",sep=";"))
t5q1m <- matrix(c(67,28,46,54), nr=2, byrow=T)
colnames(t5q1m) <- c("Candidate A", "Candidate B")
rownames(t5q1m) <- c("Candidate A", "Candidate B")
t5q1m
##             Candidate A Candidate B
## Candidate A          67          28
## Candidate B          46          54

For Females

t5q1f <- matrix(c(58,42,37,61), nr=2, byrow=T)
colnames(t5q1f) <- c("Candidate A", "Candidate B")
rownames(t5q1f) <- c("Candidate A", "Candidate B")
t5q1f
##             Candidate A Candidate B
## Candidate A          58          42
## Candidate B          37          61
mcnemar.test(t5q1f)
## 
##  McNemar's Chi-squared test with continuity correction
## 
## data:  t5q1f
## McNemar's chi-squared = 0.20253, df = 1, p-value = 0.6527