Homework Week 10 code

9.4.4

midbirth<-matrix(c(216, 716, 932),ncol=3,byrow=TRUE)
rownames(midbirth)<-c("births")
colnames(midbirth)<-c("weekend","weekday", "total")
midbirth <- as.table(midbirth)
midbirth
##        weekend weekday total
## births     216     716   932
null.probs = c(2/7, 5/7)
birthdist = c(216, 716)
chisq.test(birthdist, p=null.probs)  
## 
##  Chi-squared test for given probabilities
## 
## data:  birthdist
## X-squared = 13.294, df = 1, p-value = 0.0002662

9.4.5

null.probs2 = c(9/16, 3/16, 3/16, 1/16)
combdist = c(111, 37, 34, 8)
chisq.test(combdist, p=null.probs2)
## 
##  Chi-squared test for given probabilities
## 
## data:  combdist
## X-squared = 1.5509, df = 3, p-value = 0.6706

10.2.5

mites <-c(11, 15)
nomites <- c(17, 4)
test <- data.frame(mites, nomites)
test
##   mites nomites
## 1    11      17
## 2    15       4
chisq.test(test)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  test
## X-squared = 5.6885, df = 1, p-value = 0.01708

10.2.7

phen <- c(6, 11)
valp <- c(6, 14)
test2 <- data.frame(phen, valp)
test2
##   phen valp
## 1    6    6
## 2   11   14
chisq.test(test2)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  test2
## X-squared = 2.6469e-31, df = 1, p-value = 1

Used the Applet for this question since I do not think I did the code correctly.