MAST20005: Computer Lab Test Solutions Appendix
# Load the data.
HExer <- read.table(“HExer.txt”, header = TRUE)$HExer # Q1summary(HExer)##Min. 1st Qu.MedianMean 3rd Qu.Max.## 6.080 7.37510.310 9.52611.57012.560# Q2t.test(HExer, conf.level = 0.90)####One Sample t-test#### data:HExer## t = 18.408, df = 19, p-value = 1.43e-13## alternative hypothesis: true mean is not equal to 0## 90 percent confidence interval:## 8.631188 10.420812## sample estimates:## mean of x## 9.526# Q3# Any of the following are acceptable. wilcox.test(HExer, mu = 10)####Wilcoxon signed rank exact test#### data:HExer## V = 80, p-value = 0.3683## alternative hypothesis: true location is not equal to 10wilcox.test(HExer, mu = 10, exact = FALSE)####Wilcoxon signed rank test with continuity correction#### data:HExer## V = 80, p-value = 0.3604## alternative hypothesis: true location is not equal to 10wilcox.test(HExer, mu = 10, exact = FALSE, correct = FALSE)####Wilcoxon signed rank test#### data:HExer## V = 80, p-value = 0.3507## alternative hypothesis: true location is not equal to 101 # Q4# Any of the following are acceptable.prop.test(sum(HExer > 10), length(HExer), alternative = greater)
##
##1-sample proportions test without continuity correction
##
## data:sum(HExer > 10) out of length(HExer), null probability 0.5
## X-squared = 0, df = 1, p-value = 0.5
## alternative hypothesis: true p is greater than 0.5
## 95 percent confidence interval:
##0.3274038 1.0000000
## sample estimates:
## p
## 0.5
binom.test(sum(HExer > 10), length(HExer), alternative = greater)
##
##Exact binomial test
##
## data:sum(HExer > 10) and length(HExer)
## number of successes = 10, number of trials = 20, p-value = 0.5881
## alternative hypothesis: true probability of success is greater than 0.5
## 95 percent confidence interval:
##0.3019539 1.0000000
## sample estimates:
## probability of success
##0.5
# Q5
x <- table(cut(HExer, c(-Inf, 7, 10, Inf)))x####(-Inf,7](7,10] (10, Inf]## 5 510chisq.test(x)####Chi-squared test for given probabilities#### data:x## X-squared = 2.5, df = 2, p-value = 0.28652 # Load the data.salesdata <- read.csv(“sales.csv”, header = TRUE)daysofweek <- c(“Mon”, “Tue”, “Wed”, “Thu”, “Fri”, “Sat”, “Sun”)salesdata$days <- factor(salesdata$days, daysofweek)salesdata## ##1 ##2 ##3 ##4 ##5 ##6 ##7 ##8 ##9 ## 10 ## 11 ## 12 ## 13 ## 14 ## 15 ## 16 ## 17 ## 18 ## 19 ## 20 ## 21# Q6mfit <- lm(sales ~ customers, salesdata)summary(mfit)#### Call:## lm(formula = sales ~ customers, data = salesdata)#### Residuals:## Min1QMedian3Q Max## -351.90 -159.38-78.29170.79529.03#### Coefficients:## Estimate Std. Error t value Pr(>|t|)
## (Intercept)67.0893 212.9286 0.3150.75614
## customers 2.9169 0.9425 3.0950.00597 **
##
## Signif. codes:0 *** 0.001 ** 0.01 * 0.05 . 0.1 1
##
## Residual standard error: 244.3 on 19 degrees of freedom
## Multiple R-squared:0.3351,Adjusted R-squared:0.3001
## F-statistic: 9.577 on 1 and 19 DF,p-value: 0.005965
# Q7
confint(mfit, level = 0.95)
customers sales days
230 934Mon
179 760Tue
134 728Wed
237 599Thu
149 395Fri
315 634Sat
3351063Sun
2301267Mon
169 234Tue
220 523Wed
140 596Thu
187 763Fri
229 635Sat
2871111Sun
190 543Mon
265 750Tue
155 566Wed
209 444Thu
213 601Fri
209 332Sat
3111328Sun
3
##2.5 % 97.5 %
## (Intercept) -378.5753071 512.753990
## customers0.9441196 4.889594
# Q8
newdata <- data.frame(customers = 200)predict(mfit, newdata, interval = “prediction”, level = 0.9)##fitlwrupr## 1 650.4607 216.9488 1083.973# Q9anova(lm(customers ~ factor(days), salesdata))## Analysis of Variance Table#### Response: customers##Df Sum Sq Mean Sq F valuePr(>F)
## factor(days)6419946998.93.8867 0.01705 *
## Residuals14252111800.8
##
## Signif. codes:0 *** 0.001 ** 0.01 * 0.05 . 0.1 1
# Q10
on.weekend <- factor(salesdata$days %in% c(“Sat”, “Sun”))t.test(customers ~ on.weekend, salesdata)####Welch Two Sample t-test#### data:customers by on.weekend## t = -3.776, df = 7.5397, p-value = 0.006041## alternative hypothesis: true difference in means is not equal to 0## 95 percent confidence interval:##-141.02435-33.37565## sample estimates:## mean in group FALSEmean in group TRUE## 193.8 281.0t.test(customers ~ on.weekend, salesdata, var.equal = TRUE)####Two Sample t-test#### data:customers by on.weekend## t = -4.2293, df = 19, p-value = 0.000454## alternative hypothesis: true difference in means is not equal to 0## 95 percent confidence interval:##-130.35457-44.04543## sample estimates:## mean in group FALSEmean in group TRUE## 193.8 281.0anova(lm(customers ~ on.weekend, salesdata))4 ## Analysis of Variance Table#### Response: customers##Df Sum Sq Mean Sq F value Pr(>F)
## on.weekend132588 3258817.887 0.000454 ***
## Residuals19346161822
##
## Signif. codes:0 *** 0.001 ** 0.01 * 0.05 . 0.1 1
5
Reviews
There are no reviews yet.