You are on page 1of 3

Homework 5

Marcel Castillo, Colby Foster

2024-03-08

Q1
Null Hypothesis: The population variance of organic scores is equal to the population variance of comfort
scores
Alternative: pop var(organic) > pop var(comfort)
since var(organic)>var(comfort) as seen below, the test will be to determine if the population variance truly
is greater
S2
test statistic: F = S12
2
null distribution : F ~ Fn1 −1,n2 −1 = F19,21

Organic = read_excel("/Users/colby/Downloads/Organic.xls")
organic = Organic[which(Organic$Food == "Organic"), "Score"]
comfort = Organic[which(Organic$Food == "Comfort"), "Score"]
var(organic$Score)

## [1] 0.3523187
var(comfort$Score)

## [1] 0.3282303
var.test(organic$Score,comfort$Score,ratio = 1, alternative = c("greater"))

##
## F test to compare two variances
##
## data: organic$Score and comfort$Score
## F = 1.0734, num df = 19, denom df = 21, p-value = 0.4349
## alternative hypothesis: true ratio of variances is greater than 1
## 95 percent confidence interval:
## 0.5089612 Inf
## sample estimates:
## ratio of variances
## 1.073389
#Since the P value is 0.43>.05 (and the CI contains 1), we fail to reject the null hypothesis.

Q2
Null Hypothesis: The population mean of organic scores is equal to the population mean of comfort scores
Alternative: pop mean(organic) != pop mean(comfort)
Because the population variances haven’t shown to be different, we use the pooled t-test, which has testing
statistic:
T = √ 2 X̄−Ȳ
Sp (1/n1 +1/n2 )

1
(n −1)S 2 +(n −1)S 2
where Sp2 = 1 n1 +n 1 2
2 −2
2

and null distribution : T ~ Tn1 +n2 −2

t.test(comfort,organic, alternative = "two.sided", paired = FALSE, var.equal = TRUE)

##
## Two Sample t-test
##
## data: comfort and organic
## t = -3.8665, df = 40, p-value = 0.0003966
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -1.0601514 -0.3323031
## sample estimates:
## mean of x mean of y
## 4.887273 5.583500
Since the P value is 0.00040<.05 (and the CI doesn’t contain 0), we reject the null hypothesis with 95%
confidence that the population mean of organic does not equal the population mean of comfort.

Problem 3
(i) The null hypothesis is that these population proportions are equal to eachother. The
alternative hypothesis are:
1. They are not equal.
2. Population proportion 1 > Population proportion 2.
3. Population proportion 1 < Population Proportion 2.
n = length(Organic$Food); n

## [1] 62
significance = 0.05

Control <- Organic[Organic$Food == "Control", "Score"] #Generate our list of Control Food Scores
Comfort <- Organic[Organic$Food == "Comfort", "Score"] #Generate our list of Comfort Food Scores

Generating the binary populations


#Generate our binary data
bctrl = ifelse(Control > 4.75, 1, 0); bctrl
bcmft = ifelse(Comfort > 4.75, 1, 0); bcmft
n1 = length(bctrl)
n2 = length(bcmft)
N1 = sum(bctrl)
N2 = sum(bcmft)
p1 = sum(bctrl)/n1
p2 = sum(bcmft)/n2

Common Proportion:
N1 − N2
p̂ =
n1 − n2
phat = (N1 + N2)/(n1 + n2)

2
ii) Testing Statistic:
p̂1 − p̂2
Z=r  
p̂(1 − p̂) n11 + 1
n2

z <- (p1 - p2)/(sqrt(phat*(1-phat)*((1/n1)+(1/n2))))


pval = 1 - pnorm(z)
print(pval)

## [1] 0.04783022
Because Z ~N(0,1), the null distribution would be the standard normal distribution, with mean 0 and variance
1
iii) R Function
prop.test(c(N1, N2), c(n1, n2), alternative = c("greater"), correct=FALSE)

##
## 2-sample test for equality of proportions without continuity correction
##
## data: c(N1, N2) out of c(n1, n2)
## X-squared = 2.7764, df = 1, p-value = 0.04783
## alternative hypothesis: greater
## 95 percent confidence interval:
## 0.01312602 1.00000000
## sample estimates:
## prop 1 prop 2
## 0.75 0.50
iv) Conclusion and interpretation With p1 being greater than p2, it stands to reason that a right
sided test should be performed.We manually calculated the testing statistic and from the null distribution
determined the pvalue. We then ran the R function that provided a near-exact number. Because our p-value
is less than alpha = 0.05, we reject the null hypothesis. Additionally, the 95% confidence interval does not
include zero, this also suggests that the proportions are not equal.

You might also like