Chapter 1

  1. d
  2. b
  3. b
  4. b

  5. The Maximum likelyhood estimate MLE of \(\pi = 0.75\)

225/300
## [1] 0.75
  1. As shown below with the 95% Wald CI for \(\pi\), the lower and upper bounds are -0.70 and 0.79, respectivel
library(binom)
binom.confint(225, 300, conf.level = 0.95, method ="asymptotic")
##       method   x   n mean     lower     upper
## 1 asymptotic 225 300 0.75 0.7010009 0.7989991
  1. With 95% confidence, the lower and uppoer bound of the score CI for \(\pi\) are 0.698 and 0.796, respectively
binom.confint(225, 300, conf.level = 0.95, method ="wilson")
##   method   x   n mean     lower     upper
## 1 wilson 225 300 0.75 0.6980484 0.7956301

8.a. The null hypothesis \(H_{0}: \pi = 0.5\)

8.b. The alternative hypothesis \(H_{a} \neq 0.5\)

8.c. The Wald test statistic is 100

z <- (0.75 - 0.5)/sqrt(0.75 *(1 - 0.75)/300) # Wald stat
z^2 # Wald 
## [1] 100
pchisq(z^2, df = 1, lower.tail = FALSE) # p. value
## [1] 1.523971e-23

8.d. The degree of freedom for the Wald test is 1

8.e. Yes. The p.value is less than 0.05

8.f. The value of the score test statistic is 8.66

(0.75 - 0.5)/sqrt(0.5 *(1 - 0.5)/300)
## [1] 8.660254

8.g. False. We do reject the null hypothesis, using the score test statistic

  1. The null hypothesis \(H_{0}: \pi > 0.5\)

  2. False. Based on the the result in 8 we infer that the majority wold say either Yes or No.

11.a. The value of the score test chi-square variate is 4.5

11.b. The p.value is 0.017

prop.test(7, 8, p=0.5, alternative = "greater", correct=FALSE)
## Warning in prop.test(7, 8, p = 0.5, alternative = "greater", correct = FALSE):
## Chi-squared approximation may be incorrect
## 
##  1-sample proportions test without continuity correction
## 
## data:  7 out of 8, null probability 0.5
## X-squared = 4.5, df = 1, p-value = 0.01695
## alternative hypothesis: true p is greater than 0.5
## 95 percent confidence interval:
##  0.5888566 1.0000000
## sample estimates:
##     p 
## 0.875

12.a. The p.value is 0.035

binom.test(7, 8, 0.5, alternative = "greater")
## 
##  Exact binomial test
## 
## data:  7 and 8
## number of successes = 7, number of trials = 8, p-value = 0.03516
## alternative hypothesis: true probability of success is greater than 0.5
## 95 percent confidence interval:
##  0.5293206 1.0000000
## sample estimates:
## probability of success 
##                  0.875

12.b. Yes. The nul hypothesis is rejected.

13.a. The p-value is 0.019

library(exactci)
## Loading required package: ssanv
## 
## Attaching package: 'exactci'
## The following object is masked from 'package:binom':
## 
##     binom.exact
binom.exact(7, 8, alternative = "greater", midp = TRUE)
## 
##  Exact one-sided binomial test, mid-p version
## 
## data:  7 and 8
## number of successes = 7, number of trials = 8, p-value = 0.01953
## alternative hypothesis: true probability of success is greater than 0.5
## 95 percent confidence interval:
##  0.5801644 1.0000000
## sample estimates:
## probability of success 
##                  0.875

13.b. Yes. The result is significant at the alpha level of 0.05

  1. 13

  2. (0.52, 0.99)

library(PropCIs)
midPci(7, 8, 0.95)
## 
## 
## 
## data:  
## 
## 95 percent confidence interval:
##  0.5201 0.9936

16.a. For Jeffrey’s prior, \(\alpha = 0.5, \beta = 0.5\)

16.b. conjugate

16.c. \(\alpha^* = y + \alpha, \beta^* = n - y + \beta\)

16.d. The EAP parameters, \(\pi = 0.83\)

7 + 0.5 # alpha*
## [1] 7.5
8 - 7 + 0.5 # beta*
## [1] 1.5
7.5/(7.5 + 1.5)
## [1] 0.8333333

16.e. The 95% posterior credibility interval is (0.55, 0.99)

qbeta(0.025, 7.5, 1.5)
## [1] 0.5462807
qbeta(0.975, 7.5, 1.5)
## [1] 0.9861618

16.f. True

16.g. False

16.h. True

Chapter 2

  1. P(X = 2, Y = 1) =0.299
90/301
## [1] 0.2990033
  1. P(Y = 1) = 0.744
224/301
## [1] 0.744186
  1. P(X = 2) = 0.468
141/301
## [1] 0.4684385
  1. P(Y = 1 | X = 1) = 0.837
134/160
## [1] 0.8375
  1. P(X = Male, Y = Yes) = 0.222
(141/301) * (224/301)
## [1] 0.3486054
  1. Expected frequency (male, yes) = 104.93
(141 * 224) / 301
## [1] 104.9302
  1. The 95% CI for \(\pi_1 - \pi_2\) = (0.101, 0.296)
prop.test(c(134, 90), c(160, 141), conf.level = 0.95, correct = FALSE)
## 
##  2-sample test for equality of proportions without continuity
##  correction
## 
## data:  c(134, 90) out of c(160, 141)
## X-squared = 15.623, df = 1, p-value = 7.732e-05
## alternative hypothesis: two.sided
## 95 percent confidence interval:
##  0.1014396 0.2969646
## sample estimates:
##    prop 1    prop 2 
## 0.8375000 0.6382979
  1. Zero

  2. The 95% score CI is (0.100, 0.296)

diffscoreci(134, 160, 90, 141, conf.level = 0.95)
## 
## 
## 
## data:  
## 
## 95 percent confidence interval:
##  0.1009379 0.2966407
  1. The relative risk RR = 1.312. The probability of Yes for females are 1.312 times that for males
(134/160) / (90/141)
## [1] 1.312083
  1. The 95% CI for the population RR is (1.145, 1.525)
riskscoreci(134, 160, 90, 141, conf.level = 0.95)
## 
## 
## 
## data:  
## 
## 95 percent confidence interval:
##  1.145359 1.525178
  1. Yes

  2. The odd of Yes response for females is 5.153

  3. The odd of Yes response for males is 1.8

odd_f <- (134/160) / (1 - (134/160))
odd_f
## [1] 5.153846
odd_m <- (90/140) / (1 - (90/140))
odd_m
## [1] 1.8
  1. The value of the odd ratio is 2.863
odd_f / odd_m
## [1] 2.863248
  1. The odd of Yes in the female group are 2.863 times the odds of Yes in the male group, indicating Yes is more likely in the female group than in the male group.

  2. The 95% CI for the population odds ratio is (1.697, 5.024)

library(epitools)
## 
## Attaching package: 'epitools'
## The following object is masked from 'package:exactci':
## 
##     binom.exact
## The following objects are masked from 'package:binom':
## 
##     binom.exact, binom.wilson
oddsratio(c(134, 90, 26, 51), method ="wald", conf = 0.95, correct = FALSE)
## $data
##           Outcome
## Predictor  Disease1 Disease2 Total
##   Exposed1      134       90   224
##   Exposed2       26       51    77
##   Total         160      141   301
## 
## $measure
##           odds ratio with 95% C.I.
## Predictor  estimate    lower    upper
##   Exposed1 1.000000       NA       NA
##   Exposed2 2.920513 1.697494 5.024699
## 
## $p.value
##           two-sided
## Predictor    midp.exact fisher.exact  chi.square
##   Exposed1           NA           NA          NA
##   Exposed2 8.317185e-05 0.0001083532 7.73227e-05
## 
## $correction
## [1] FALSE
## 
## attr(,"method")
## [1] "Unconditional MLE & normal approximation (Wald) CI"
  1. … with the value of 50/50 chance .. The value is 1

  2. cross-sectional

20.a. \(X^2 = 14.594\)

belief <- data.frame(Yes =c(134,90), No = c(26,51)) 
row.names(belief) = c("females", "males")
belief
##         Yes No
## females 134 26
## males    90 51
belief.test <- chisq.test(belief)
belief.test
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  belief
## X-squared = 14.594, df = 1, p-value = 0.0001334

20.b. Yes

20.c. The standardized residuals for females and yes is 3.952

belief.test$stdres
##              Yes       No
## females  3.95255 -3.95255
## males   -3.95255  3.95255

20.d. Yes responses dominant for females and less dominant for males

  1. True

22.a. \(X^2 = 147.98\)

school <- data.frame(fail = c(36, 8, 1, 0), pass = c(14, 67, 127, 32))
row.names(school) <- c("below.basic", "basic", "proficient", "advanced")
school
##             fail pass
## below.basic   36   14
## basic          8   67
## proficient     1  127
## advanced       0   32
chisq.test(school)
## 
##  Pearson's Chi-squared test
## 
## data:  school
## X-squared = 147.98, df = 3, p-value < 2.2e-16

22.b. The degree of freedom is 3

22.c. Yes. Reject the null hypothesis

23.a. The value of the \(M^2\) is 105.4

library(vcdExtra)
## Loading required package: vcd
## Loading required package: grid
## 
## Attaching package: 'vcd'
## The following object is masked from 'package:epitools':
## 
##     oddsratio
## Loading required package: gnm
## 
## Attaching package: 'vcdExtra'
## The following object is masked from 'package:epitools':
## 
##     expand.table
school2 <- matrix(c(36, 8, 1, 0, 14, 67, 127, 32), ncol = 2)
school2
##      [,1] [,2]
## [1,]   36   14
## [2,]    8   67
## [3,]    1  127
## [4,]    0   32
CMHtest(school2, rscore = c(1, 2, 3, 4))
## Cochran-Mantel-Haenszel Statistics 
## 
##                  AltHypothesis  Chisq Df       Prob
## cor        Nonzero correlation 105.04  1 1.1971e-24
## rmeans  Row mean scores differ 147.46  3 9.3047e-32
## cmeans  Col mean scores differ 105.04  1 1.1971e-24
## general    General association 147.46  3 9.3047e-32

23.b. Yes. Reject.