



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




This assignment includes problems related to paired samples and analysis of two-way categorical data.
diet1 <- c(596, 422, 524, 454, 538, 552, 478, 564, 556) diet2 <- c(498, 460, 468, 458, 530, 482, 528, 598, 456) se <- sqrt(var(diet1 - diet2)/length(diet1 - diet2)) se
[1] 19.
ts <- 22.9/(59.3/sqrt(9)) ts
[1] 1.
t.test(diet1, diet2, paired = T, conf.level = 0.9)
Paired t-test
data: diet1 and diet t = 1.1585, df = 8, p-value = 0. alternative hypothesis: true difference in means is not equal to 0 90 percent confidence interval: -13.85051 59. sample estimates: mean of the differences
We are 90% confident that the mean 140-day weight gain (in pounds) of all beef steers from a given herd would be between 13.9 pounds less or 59.6 pounds more when on Diet 1 than when on Diet 2. There is data is consistent with a hypothesis of no mean difference in weight gain for the two diets (two-sided p-value = 0.28 from a paired t-test).
(a) Test significance of the 35 mg/dl drop in cholesterol for the no-coffee group. This is a paired t-test where each man’s cholesterol is compared to a measurement for the man at baseline.
ts <- -35/(27/sqrt(25)) ts [1] -6.
2 * pt(ts, 24) [1] 1.055815e- If this group had been randomly sampled from a population, there would be strong evidence that stopping coffee drinking and participating in the study would decrease cholesterol. (b) Test significance of the 26 mg/dl rise in cholesterol for the usual-coffee group. This is a paired t-test where each man’s cholesterol is compared to a measurement for the man at baseline. ts <- 26/(56/sqrt(8)) ts [1] 1. 2 * pt(-ts, 7) [1] 0. The increase in cholesterol level for this group is consistent with chance variation. There is insufficient evidence to conclude that participating in the study changed the cholesterol level for this group. (c) Use a t-test to compare the groups. This is an independent samples t-test. se <- sqrt(27^2/25 + 56^2/8) ts <- (-35 - 26)/se df2sample <- function(se1, n1, se2, n2) {
df <- df2sample(27/sqrt(25), 25, 56/sqrt(8), 8) df [1] 8. p <- 2 * pt(ts, df) p [1] 0. (d) State conclusions to part (c). There is strong evidence that not drinking coffee lowers cholesterol level in this population and that the difference is not due to participation in the study alone (two-sided p-value = 0.018, independent samples t-test).
central <- c(62.7, 63.6, 60.9, 63, 62.7, 63.7) top <- c(59.7, 61.6, 58.2, 60.5, 60.6, 60.8) t.test(central, top, paired = T, conf.level = 0.9)
Paired t-test
data: central and top t = 15.0208, df = 5, p-value = 2.368e- alternative hypothesis: true difference in means is not equal to 0 90 percent confidence interval: 2.193486 2. sample estimates: mean of the differences
n <- 1000 observed <- c(0.52, 0.48) * n expected <- c(0.5, 0.5) * n x2 <- sum((observed - expected)^2/expected) x
[1] 1.
1 - pchisq(x2, 1)
[1] 0.
n <- 3000 observed <- c(0.52, 0.48) * n expected <- c(0.5, 0.5) * n x2 <- sum((observed - expected)^2/expected) x
[1] 4.
1 - pchisq(x2, 1)
[1] 0.
n <- 6000 observed <- c(0.52, 0.48) * n expected <- c(0.5, 0.5) * n x2 <- sum((observed - expected)^2/expected) x
[1] 9.
1 - pchisq(x2, 1)
[1] 0.
We see that the p-value gets smaller as the sample size increases.
(a) State the null hypothesis in words. Both products are equally effective at producing pregnant cows. (b) State the null hypothesis in symbols. Let pA and pB be the probabilities that cows become pregnant using product A and B respectively. Then the null hypothesis is H 0 : pA = pB. (c) Find the test statistic and the p-value. I’ll use R.
observed <- matrix(c(8, 13, 15, 6), 2, 2) rsum <- apply(observed, 1, sum) csum <- apply(observed, 2, sum) gsum <- sum(rsum) expected <- (rsum %o% csum)/gsum expected [,1] [,2] [1,] 11.5 11. [2,] 9.5 9.
x2 <- sum((observed - expected)^2/expected) x [1] 4. 1 - pchisq(x2, (length(rsum) - 1) * (length(csum) - 1)) [1] 0.
(d) State a conclusion in the context of the setting. There is fairly strong evidence that the two products are not equally effective in leading to pregnant cows (p-value = 0.03 in a χ^2 test). Product B appears to be more effective.