library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.0.2
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.2 v purrr 0.3.4
## v tibble 3.0.4 v dplyr 1.0.2
## v tidyr 1.1.2 v stringr 1.4.0
## v readr 1.4.0 v forcats 0.5.0
## Warning: package 'tibble' was built under R version 4.0.3
## Warning: package 'tidyr' was built under R version 4.0.2
## Warning: package 'dplyr' was built under R version 4.0.2
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(infer)
## Warning: package 'infer' was built under R version 4.0.2
library(openintro)
## Warning: package 'openintro' was built under R version 4.0.2
## Loading required package: airports
## Warning: package 'airports' was built under R version 4.0.2
## Loading required package: cherryblossom
## Warning: package 'cherryblossom' was built under R version 4.0.2
## Loading required package: usdata
## Warning: package 'usdata' was built under R version 4.0.2
getwd()
## [1] "C:/Users/Jerome/Documents/From_Toshiba_HD_Work_Files/0000_Montgomery_College/Math_217/Week_10"
chickmatrix<-matrix(c(0.584, 0.5625, 0.195, 0.1875,0.179, 0.1875, 0.042, 0.0625),ncol=2,byrow=TRUE)
rownames(chickmatrix)<-c("wfsc","wflc","dfsc","dflc")
colnames(chickmatrix)<-c("observed","expected")
chickmatrix <- as.table(chickmatrix)
chickmatrix
## observed expected
## wfsc 0.5840 0.5625
## wflc 0.1950 0.1875
## dfsc 0.1790 0.1875
## dflc 0.0420 0.0625
# Now set the probability values for the expected proportions of chicks)
null.probs = c(9/16, 3/16, 3/16, 1/16)
chickdist = c(111, 37, 34, 8)
chisq.test(chickdist, p=null.probs) # p is not the second option, so must be labeled
##
## Chi-squared test for given probabilities
##
## data: chickdist
## X-squared = 1.5509, df = 3, p-value = 0.6706
died <-c(83, 106)
lived <- c(264, 262)
test <- data.frame(died, lived)
chisq.test(test)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: test
## X-squared = 1.9476, df = 1, p-value = 0.1628