library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6      ✔ purrr   0.3.4 
## ✔ tibble  3.1.8      ✔ dplyr   1.0.10
## ✔ tidyr   1.2.1      ✔ stringr 1.4.1 
## ✔ readr   2.1.2      ✔ forcats 0.5.2 
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(BSDA)
## Warning: package 'BSDA' was built under R version 4.2.2
## Loading required package: lattice
## 
## Attaching package: 'BSDA'
## 
## The following object is masked from 'package:datasets':
## 
##     Orange

9.2.5

69/339 infants with reactions over total number of infants. P tilde is 0.20, 20%

Add the Wilsopn adjusted method to P, 69+2/339+4

p.adjust = (69+2)/(339+4)

SE is square root of Ptilde(1-Ptilde)/n+4

SE = sqrt(p.adjust*(1 - p.adjust)/343)
p.adjust - 1.96*SE
## [1] 0.1641197
p.adjust + 1.96*SE
## [1] 0.2498745

B. We are 95% confident that the true population proportion of infants who received their routine vaccination for whooping cough is between 16.4% to 25.0%

C. I would say it is around 0.25 for the upper bound

9.4.4

932 births total, 216 births occured on weekends, 716 on weekdays

null.probs <-c(716/932)
Weekends <-c(216/932)
df <- data.frame(Weekends,null.probs)
chisq.test(df)
## Warning in chisq.test(df): Chi-squared approximation may be incorrect
## 
##  Chi-squared test for given probabilities
## 
## data:  df
## X-squared = 0.28781, df = 1, p-value = 0.5916

B.

3 Null Hypothese: The data does not reveal random timing of the births

Alternative hypothesis: The data between weekend and weekday births does reveal random timing of the births

C.

It revea;s that is it very strong evidence to support that the births are by chance

9.4.5

Null Hypothesis: The data is consistent with Mendelian expected ratios

Alternative Hypothesis: The data is not consistent with Mendelian ratios

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

10.2.5

Null: Infestions with mites does not induce wilt disease

HsubO: U1 = U2

15/26 is no WIlt disease with mites treatment over total, 4/21 wilt diease over no mites treatment

10.2.7

6/20 patients getting Val treatment did not get seizures so 14/20 did

6/17 patients getting Phoen treatment were seizure free, so 11/17 had seizures

null.probs = c(14/20,11/17)
SeizureFree = c(6/20,6/17)
df = data.frame(SeizureFree,null.probs)
chisq.test(df)
## Warning in chisq.test(df): Chi-squared approximation may be incorrect
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  df
## X-squared = 9.3811e-32, df = 1, p-value = 1

HsubO: Both treatments demonstrated similar resposnes in epilepsy patients, independant of each other

HsubA: One treatment showed more promising results for patients with epilepsy over 12 months, are not independant

the value of the test statistic is 0.0000000000000000000000000000000093811

There is weak evidence since the p value is greater than the alpha. Fail to reject the null

10.3.3

Died = c(89/347)
Survived = c(189/347)
df = data.frame(Died,Survived)
chisq.test(df)
## Warning in chisq.test(df): Chi-squared approximation may be incorrect
## 
##  Chi-squared test for given probabilities
## 
## data:  df
## X-squared = 0.10366, df = 1, p-value = 0.7475
Died = c(106/348)
WW = c(242/348)
df = data.frame(Died,WW)
chisq.test(df)
## Warning in chisq.test(df): Chi-squared approximation may be incorrect
## 
##  Chi-squared test for given probabilities
## 
## data:  df
## X-squared = 0.15273, df = 1, p-value = 0.6959

10.9.1

Relative risk for A. Find Phat1 and Phat2. Then Divide Phat1/Phat2

25/492
## [1] 0.05081301
23/614
## [1] 0.03745928
(25/492)/(23/614)
## [1] 1.356486

Find Odds Ratio of the table

(25*614)/(23*492)
## [1] 1.356486

Relative Risk and Odds Ratio for B

12/93
## [1] 0.1290323
8/84
## [1] 0.0952381
(12/93)/(8/84)
## [1] 1.354839
(12*84)/(8*93)
## [1] 1.354839

10.9.3

3995/46941
## [1] 0.08510684
221/5228
## [1] 0.04227238
(3995/46941)/(221/5228)
## [1] 2.013297

10.9.4a

(3995*5007)/(221*42946)
## [1] 2.107557