library(resampledata)
DiffInPrice <- Groceries$Target-Groceries$Walmart
t.test(DiffInPrice, conf.level=.95)
One Sample t-test
data: DiffInPrice
t = 0.47046, df = 29, p-value = 0.6415
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
-0.1896825 0.3030159
sample estimates:
mean of x
0.05666667
t.test(Groceries$Target, Groceries$Walmart, conf.level=.95, paired=T)
Paired t-test
data: Groceries$Target and Groceries$Walmart
t = 0.47046, df = 29, p-value = 0.6415
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-0.1896825 0.3030159
sample estimates:
mean of the differences
0.05666667
boxplot(Groceries$Target-Groceries$Walmart)
I'll remove any data points where the difference in price between Target and Walmart is more than $2.
The which command returns the index of the data point(s). If we pass the whole which command to the new vector construction we don't need to know the particular index values.
#which(abs(DiffInPrice)>2)
ModifiedTarget <- Groceries$Target[-which(abs(DiffInPrice)>2)]
ModifiedWalmart <- Groceries$Walmart[-which(abs(DiffInPrice)>2)]
t.test(ModifiedTarget, ModifiedWalmart, conf.level = .95, paired=T)
Paired t-test
data: ModifiedTarget and ModifiedWalmart
t = 2.2038, df = 28, p-value = 0.03593
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
0.01098743 0.30073671
sample estimates:
mean of the differences
0.1558621
prop.test(34, 350)$conf
[1] 0.06913692 0.13429260
attr(,"conf.level")
[1] 0.95
prop.test(56, 350)$conf
[1] 0.1240384 0.2036158
attr(,"conf.level")
[1] 0.95
prop.test(34, 350)$conf
[1] 0.06913692 0.13429260
attr(,"conf.level")
[1] 0.95
prop.test(56, 350)$conf
[1] 0.1240384 0.2036158
attr(,"conf.level")
[1] 0.95
prop.test(c(34, 56), c(350, 350))$conf
[1] -0.11508783 -0.01062645
attr(,"conf.level")
[1] 0.95