Lab Assignment 4 (Lab projects?)

  1. Go though LabAssignment4.pdf LabAssignment4.pdf

  2. Download LabAssignment4.Rmd (LabAssignment4.Rmd, MendelFigure1.png, MendelFigure2.png) in RStudio and run codes inside. Things should be exactly same as LabAssignment4.pdf.

  3. Download, open LabAssignment4_rev.Rmd LabAssignment4_rev.Rmd and save as a new Rmd file for your own Lab Assignment submission. Knit this Rmd file to see if you can make a html, pdf or words. If you couldn’t, just use RStudio Cloud or the Binder RStudio Binder set by Po.

  4. Run/add/edit/delete the codes in your own copy of LabAssignment4_rev.Rmd and add/edit/delete some writings. Knit to see how the .pdf looks like. Tidy up the codes and writings. Knit and submit!

Pearson’s chi-squared test

https://en.wikipedia.org/wiki/Pearson%27s_chi-squared_test

Hardcoding in LabAssignment4.pdf

NullRatio <- c(1,1,1,1,2,2,2,2,4)
NullProportion <- NullRatio/sum(NullRatio) # converting ratios to proportions
Observed <- c(38,35,28,30,65,68,60,67,138) # from Mendel's table
Expected <-sum(Observed)*NullProportion # converting proportions to Expected counts
Discrepancy <- (Expected-Observed)^2/Expected
TestStat <- sum(Discrepancy) # chi-squared test statistic
p_value <- 1-pchisq(TestStat,9-1) # don't forget the degrees of freedom!
pander(c(TestStat=TestStat, p_value=p_value))
TestStat p_value
2.811 0.9457

Using R built-in function chisq.test

NullRatio <- c(1,1,1,1,2,2,2,2,4)
Observed <- c(38,35,28,30,65,68,60,67,138)
pander(chisq.test(Observed, p = NullRatio, rescale.p = TRUE))
Chi-squared test for given probabilities: Observed
Test statistic df P value
2.811 8 0.9457

Help/Documentation

There is no secret ingredient. – Mr. Ping 🍜

Read the R Documentation of every functions you have seen.

?c
?rbind
?sum
?pchisq
?pander
?chisq.test

How Po knows all those built-in functions in R?

R tutorials that help you survive in Village 🍄