Dataset: cabbage.csv
This dataset has 60 observations and 4 variables:
Perform a hypothesis test to test if the vitamin C content in the C52 cultivar is greater than the C39 cultivar. Consider all planting dates. Use the 7(9) step procedure and set a significance level to 0.05.
Step 1: Hypotheses – The null and alternative hypotheses to test whether the vitamin C content for C52 cultivar is greater than C39 cultivar are
\[ H_0:\mu_{c52}-\mu_{c39}=0 \ \ \text{versus} \ \ H_a:\mu_{c52}-\mu_{c39}>0 \]
Step 2: Level of significance – \(\alpha=0.05\)
Step 3: Test statistic –
library(PASWR2)
## Warning: package 'PASWR2' was built under R version 4.3.3
## Loading required package: lattice
## Loading required package: ggplot2
cabbage <- read.csv("cabbage.csv")
cabbage.c52 <- subset(cabbage, subset=Cult=="c52")
cabbage.c39 <- subset(cabbage, subset=Cult=="c39")
var.test(cabbage.c52$VitC, cabbage.c39$VitC)
##
## F test to compare two variances
##
## data: cabbage.c52$VitC and cabbage.c39$VitC
## F = 1.4089, num df = 29, denom df = 29, p-value = 0.3613
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 0.670588 2.960098
## sample estimates:
## ratio of variances
## 1.408902
t <- t.test(cabbage.c52$VitC, cabbage.c39$VitC, var.equal = FALSE, alternative="greater")
t
##
## Welch Two Sample t-test
##
## data: cabbage.c52$VitC and cabbage.c39$VitC
## t = 6.3909, df = 56.376, p-value = 1.703e-08
## alternative hypothesis: true difference in means is greater than 0
## 95 percent confidence interval:
## 9.524381 Inf
## sample estimates:
## mean of x mean of y
## 64.4 51.5
Step 4: Rejection region calculations – rejection region is 1.67
RR <- qt(0.95,t$parameter)
RR
## [1] 1.672335
Step 5: Statistical conclusion – p-value is less than 0.05 so \(H_0\) rejected; t-value (6.39) is greater than 1.67 (outside rejection region) so \(H_0\) rejected.
1-pt(t$statistic,29)
## t
## 2.741454e-07
Step 6: Confidence interval – 95% confidence interval is \([9.52,\infty]\); does not contain 0, so \(H_0\) rejected.
Step 7: English conclusion – There is sufficient evidence to suggest the average vitamin C content of c52 cultivar is greater than the average vitamin C content of c39 cultivar.
Beta endorphin are morphine like substances produced by the body.
They create a sense of well-being. It has been proposed that Beta
endorphin increase with exercise. Sport scientists conducted an
experiment to investigate this problem. They used R to perform a
hypothesis test and adopted a significance level of 0.05. The
differences (dif) were computed as follows: dif = Beta-endorphin
post-test minus Beta-endorphin pre-test
The following R output was generated. Look at the R output generated.
Answer each question below assuming the assumptions associated with this
procedure are valid.
##
## One Sample t-test
##
## data: z$dif
## t = 6.8419, df = 8, p-value = 6.604e-05
## alternative hypothesis: true mean is greater than 0
## 95 percent confidence interval:
## 11.51382 Inf
## sample estimates:
## mean of x
## 15.81111
How many athletes took part in both the pre- and post-measurements?
9 athletes.
Explain how the number 15.81111 was computed.
The mean of the differences post and pre test. I.e.
mean(dif)
Formulate a null and alternate hypothesis in symbols and words.
\[ H_0:\mu=0 \ \ \text{no difference between pre- and post- measurements} \\ H_a:\mu>0 \text{post- measurements are greater than pre- measurements} \]
What is the value of the test statistic?
6.8419
Draw a picture that shows the test-statistic and critical t-value(s).
t.crit <- qt(0.95,8)
x <- seq(-7,7,0.1)
y <- dt(x,8)
plot(x,y,type="l",)
abline(v=6.8419,col=2)
abline(v=t.crit)
State the conclusions of the test for an expert and non-expert audience.
There is sufficient evidence to reject the null hypothesis (accept alternative hypothesis), i.e. there are a greater amount of Beta-endorphines post- measurement compared to pre- measurement.
A computer company that recently introduced a new software product claims that the mean time it takes to learn how to use this software is not more than 2 hours for people who are somewhat familiar with computers. A random sample of 12 such persons was selected. The following data give the times take by these persons to learn the software.
1.75 2.25 2.40 1.9 1.5 2.75 2.15 2.25 1.8 2.20 3.25 2.60
Test at the 1% significance level whether company’s claim is true. Assume that the times by all persons who are somewhat familiar with computers to learn how to use this software are approximately normally distributed.
Step 1: Hypotheses – The null and alternative hypotheses to test whether the mean time is less than 2 hours are
\[ H_0:\mu=0 \ \ \text{versus} \ \ H_a:\mu<0 \]
Step 2: Level of significance – \(\alpha=0.01\)
Step 3: Test statistic –
\[ \bar y= 2.2\bar3;\ \mu_0=2;\ \sigma=0.480...\\ z=\frac{\bar y - \mu_0}{\sigma/\sqrt{12}}= 1.681... \]
Step 4: Rejection region calculations – using t-table rejection region is 2.718…
Step 5: Statistical conclusion – p-value is 0.0465 p-value is greater than 0.01 so \(H_0\) accepted; t-value (1.681…) is less than 2.718… so \(H_0\) rejected. (contradictory?)
\[ p(z<1.681...) \\ \text{using z-table:} \\ \text{p-value}= 0.0465 \]
Step 6: Confidence interval –
Step 7: English conclusion – lack of sufficient evidence to support the companies claim.
The manufacturer of a gasoline additive claims that the use of this additive increases gasoline mileage. A random sample of size cars was selected and these cars were driven for one week without the additive and then for one week with the additive. The following table gives the miles per gallon for these cars without and with the additive:
| before | 24.6 | 28.3 | 18.9 | 23.7 | 15.4 | 29.5 |
| after | 26.3 | 31.7 | 18.2 | 25.3 | 18.3 | 30.9 |
Based on the significance level of 2.5%, can you conclude that the use of the gasoline additive increases the gasoline mileage?
before <- c(24.6,28.3,18.9,23.7,15.4,29.5)
after <- c(26.3,31.7,18.2,25.3,18.3,30.9)
D <- after - before
mean.D <- mean(D)
sd.D <- sd(D)
n.D <- length(D)
t <- mean.D / (sd.D / sqrt(n.D))
t
## [1] 2.945744
1-0.025
## [1] 0.975
qt(0.975,5)
## [1] 2.570582
t.test(D, alternative="greater", conf.level = 0.975)
##
## One Sample t-test
##
## data: D
## t = 2.9457, df = 5, p-value = 0.01602
## alternative hypothesis: true mean is greater than 0
## 97.5 percent confidence interval:
## 0.2186302 Inf
## sample estimates:
## mean of x
## 1.716667
mean.D - (2.571 * sd.D / sqrt(n.D))
## [1] 0.2183865
#0.2183865
Step 1: Hypotheses – The null and alternative hypotheses to test whether the mean time is less than 2 hours are
\[ H_0:\mu=0 \ \ \text{versus} \ \ H_a:\mu>0 \]
Step 2: Level of significance – \(\alpha=0.025\)
Step 3: Test statistic –
\[ t=\frac{\bar d-0}{s_D/\sqrt{n_D}}=\frac{1.71\bar 6}{1.4274.../\sqrt{6}} = 2.945... \]
Step 4: Rejection region calculations – using t-table rejection region is to the right of 2.571
Step 5: Statistical conclusion – p-value is less than 0.025 so \(H_0\) rejected; t-value (2.945…) is greater than 2.571 so \(H_0\) rejected.
\[ p(t>2.945...) \\ \text{using z-table:} \\ \text{p-value}= 0.0016 \]
Step 6: Confidence interval – 97.5 CI does not contain 0, so \(H_0\) rejected.
\[ \text{97.5CI:}\ \ [\bar d-t_{0.975;5}s_D/\sqrt{n_D},\infty] \\ [1.71\bar 6-2.571(1.427.../\sqrt{6},\infty] \\ [0.218,\infty] \]
Step 7: English conclusion – There is sufficient evidence to suggest the use of the gasoline additive increases the mean mileage.
Although you’ve had entrepreneurial interests for a while, you’ve just launched your dream company as a manufacturer of ice cream sandwiches. You bought and installed a machine that assembles the sandwiches: https://www.youtube.com/watch?v=Vlb4mfQv6-s You’re not yet an expert on using the machine, and not all of the sandwiches are meeting your quality standards. Sometimes the chocolate exterior is chipped or broken, sometimes the pieces aren’t exactly aligned, and sometimes (although more rarely), there’s an issue with cutting or inserting the ice cream and you end up with an ice cream sandwich that just looks bad.
Right now, you are aiming to have no more than 10% defective product. You systematically sampled one out of every twenty ice cream sandwiches that came off the production line today for a total of 150, and found that only 13 of them were unacceptable to offer to customers.
Are you meeting your target of having no more than 10% defective? Investigate this further. Follow the seven step procedure.
Step 0: Assumptions – \(n\pi\) and \(n(1-\pi)\) are equal to 30 and 120 respectively, which are both greater than 10, so normal approximating for n is appropriate.
Step 1: Hypotheses – The null and alternative hypotheses to test whether more than 10% of products are defective
\[ H_0:\pi\leq0.1 \ \ \text{versus} \ \ H_a:\pi>0.1 \]
Step 2: Level of significance – \(\alpha=0.05\)
pvalue <- sum(dbinom(13:150,150,0.10))
TR <- binom.test(x = 13, n = 150, p = 0.10, alternative="greater")
TR
##
## Exact binomial test
##
## data: 13 and 150
## number of successes = 13, number of trials = 150, p-value = 0.7455
## alternative hypothesis: true probability of success is greater than 0.1
## 95 percent confidence interval:
## 0.05202562 1.00000000
## sample estimates:
## probability of success
## 0.08666667
#without continuity:
without <- prop.test(x=13, n = 150, p = 0.1, correct=FALSE, alternative = "greater")
without$p.value
## [1] 0.7068932
##[1] 0.7068932
without$p.value < 0.05
## [1] FALSE
##[1] FALSE
with <- prop.test(x=13,n=150,p=0.1,alternative = "greater")
with$p.value
## [1] 0.6584543
##[1] 0.6584543
with$p.value < 0.05
## [1] FALSE
##[1] FALSE
Step 5: Statistical conclusion – p-value is greater than 0.05, so \(H_0\) accepted.
\[ \begin{align} p&=\frac{13}{150}=0.08\bar6 \\ z_{obs}&=\frac{0.08\bar6-0.1}{\sqrt{\frac{0.1(0.9)}{150}}}=-0.544... \\ \text{p-value}=P(z_{obs}>-0.544...)&=1-0.2946=0.7054 \end{align} \]
Step 6: Confidence interval – 0.1 is within the confidence interval, so \(H_0\) accepted.
\[ \text{95% CI}=[p\pm1.96\sqrt{\frac{0.1(0.9)}{150}}] \\ =[0.0387,0.1347] \]
Step 7: English conclusion – sufficient evidence to suggest the proportion of defective products being produced is less than or equal to 10%.
SNAP_R is a program written to automate the process of “spear phishing” - that is, contacting an individual online while masquerading as a “trusted source” and convincing him or her to divulge sensitive personal (or business) information.
The author of your textbook found out about this tool while watching a video from DEFCON 24, an annual hacker’s conference held in Las Vegas. They provided some observations about how many times their victims clicked malicious links based on whether humans or SNAP_R were doing the phishing. We were told that the hackers running SNAP_R convinced 275 people out of 819 to click through, compared to 49 out of 129 when a human was doing the phishing.
Does the SNAP_R software program snag a different percentage of victims than human phishers? Investigate this further. Follow the appropriate steps for hypothesis tests.
Step 0: Assumptions – \(XP\) (and \(X(1-P)\) as well as \(YP\) and \(Y(1-P)\) are greater than 10, so large normal approximation can be used.
Step 1: Hypotheses – The null and alternative hypotheses to test whether there is a difference in the proportion of victims from human compared to SNAP_R phishers
\[ H_0:\pi_X=\pi_Y \ \ \text{versus} \ \ H_a:\pi_X\neq\pi_Y \]
Step 2: Level of significance – \(\alpha=0.05\)
Step 5: Statistical conclusion – p-value (0.327) is greater than 0.05, so \(H_0\) accepted.
\[ \begin{align} P&=\frac{275+49}{819+129}=0.341... \\ p_X=\frac{275}{819}=0.335...&;\ p_Y=\frac{49}{129}=0.379... \\ z&=\frac{0.335...-0.379...}{\sqrt{0.341...9(1-0.341...)(\frac{1}{819}+\frac{1}{129})}}=-0.980... \\ \\ P(z\leq-0.980...)&+P(z\geq0.980...) = 2(0.1635)=0.327 \end{align} \]
Step 6: Confidence interval – 95% CI contains 0, so \(H_0\) accepted.
\[ \text{95% CI}=[(0.335...-0.379...)\pm1.96\sqrt{0.341...9(1-0.341...)(\frac{1}{819}+\frac{1}{129})}] \\ =[-0.044...\pm0.088...]=[-0.132,0.044] \]
Step 7: English conclusion – sufficient evidence to suggest the proportion of victims from human and SNAP_R phishers is not different.
A government grants is funding a study to calculate how long it takes for the average consumer to establish an Internet connection. A random sample of 20 Internet users’ connection time is collected. The connections time in seconds are:
0.03, 0.48, 0.49, 0.52, 0.66, 0.67, 0.70, 0.76, 0.82, 1.2, 1.22, 1.39, 1.62, 1.85, 1.97, 2.25, 2.84, 3.11, 3.48, 4.02
Use chi-square test to see if it is reasonable to assume that internet connection time follows an exponential distribution with a mean of 1.5 seconds.
Hint:
#H0 the connection times do not follow an exponential distribution with a mean of 1.5 seconds, Ha states that they do
#alpha = 0.05
connection_times <- c(0.03, 0.48, 0.49, 0.52, 0.66, 0.67, 0.70, 0.76, 0.82, 1.2, 1.22, 1.39, 1.62, 1.85, 1.97, 2.25, 2.84, 3.11, 3.48, 4.02)
bins <- cut(connection_times, breaks = c(0,1,2,Inf))
ctab <- xtabs(~ bins)
ctab
## bins
## (0,1] (1,2] (2,Inf]
## 9 6 5
#from lec notes rate=1/mean
lambda <- 1 / 1.5
p01 <- pexp(1, lambda)
p12 <- pexp(2, lambda) - pexp(1, lambda)
p23 <- pexp(2, lambda, lower.tail = FALSE)
chisq.test(ctab, c(p01, p12, p23))
## Warning in chisq.test(ctab, c(p01, p12, p23)): Chi-squared approximation may be
## incorrect
##
## Pearson's Chi-squared test
##
## data: ctab and c(p01, p12, p23)
## X-squared = 6, df = 4, p-value = 0.1991
p-value (0.1991) is greater than 0.05, so \(H_0\) is not rejected.
There is not sufficient evidence suggesting internet connection time follows an exponential distribution with a mean of 1.5 seconds.
The R data frame HairEyeColor contains classification of 592 students by gender, hair color and eye color. Carry out the appropriate hypothesis tests to test:
eye.cols <- rep(c(“Brown”,“Blue”,“Hazel”,“Green”),4)
hair.cols <- rep(c(“Black”,“Brown”,“Red”,“Blond”),each=4)
If hair color is independent of eye color?
#H0 hair and eye colour are not indepedent, Ha hair and eye colour are independent
#alpha = 0.05
val.both <- c(68,20,15,5,119,84,54,29,26,17,14,14,7,94,10,16)
eye.cols <- rep(c("Brown","Blue","Hazel","Green"),4)
hair.cols <- rep(c("Black","Brown","Red","Blond"),each=4)
dat.both <- data.frame(hair.cols,eye.cols,val.both)
ctab.both <- xtabs(val.both~hair.cols+eye.cols,data=dat.both)
z1 <- chisq.test(ctab.both)
z1
##
## Pearson's Chi-squared test
##
## data: ctab.both
## X-squared = 138.29, df = 9, p-value < 2.2e-16
# z1$expected
## eye.cols
##hair.cols Blue Brown Green Hazel
## Black 39.22297 40.13514 11.675676 16.96622
## Blond 46.12331 47.19595 13.729730 19.95101
## Brown 103.86824 106.28378 30.918919 44.92905
## Red 25.78547 26.38514 7.675676 11.15372
p-value is extremely low, can reject \(H_0\). There is sufficient evidence suggesting an association between eye colour and hair colour.
If hair color is independent of eye color for women?
# fem <- HairEyeColor[, , 2]
# fem
# chisq.test(fem)
#H0 hair and eye colour are not indepedent for females, Ha hair and eye colour are independent for females
#alpha = 0.05
val.fem <- c(36,9,5,2,66,34,29,14,16,7,7,7,4,64,5,8)
dat.fem <- data.frame(hair.cols,eye.cols,val.fem)
ctab.fem <- xtabs(val.fem~hair.cols+eye.cols,data=dat.fem)
z2 <- chisq.test(ctab.fem)
## Warning in chisq.test(ctab.fem): Chi-squared approximation may be incorrect
#z2$expected
## eye.cols
##hair.cols Blue Brown Green Hazel
## Black 39.22297 40.13514 11.675676 16.96622
## Blond 46.12331 47.19595 13.729730 19.95101
## Brown 103.86824 106.28378 30.918919 44.92905
## Red 25.78547 26.38514 7.675676 11.15372
z2
##
## Pearson's Chi-squared test
##
## data: ctab.fem
## X-squared = 106.66, df = 9, p-value < 2.2e-16p-value is extremely low, can reject \(H_0\). There is sufficient evidence suggesting an association between eye colour and hair colour in women.
Acrophobia is a fear of heights, it can be treated in a number of different ways. After an intensive literature review, a research found three unconventional methods had promising results in the literature. The researcher wants to know if there is a difference in the effectiveness of these treatments. Due to the nature of the treatments, he worries that some methods may be less acceptable by patients than others. So he recruited 15 volunteers and divided them into five acceptance groups, and randomly assigned the members of each acceptance group into each of the three treatments. Given the following ANOVA table from a randomised complete block design:
| Source | DF | SS | MS | F |
|---|---|---|---|---|
| Factor | 2 | 260.93 | 130.465 | 15.259 |
| Block | 4 | 438.00 | 109.50 | 12.807 |
| Error | 8 | 68.4 | 8.55 | |
| Total | 14 | 767.33 |
Fill in the missing values [9 marks]
How many levels does the factor have? [1 mark] 3
How many blocks are there in the design? [1 mark] 5
The data frame barley from the lattice package lists barley yield in bushels per acre for the years 1931 and 1932 for ten varieties of barley grown at six sites. Is there enough evidence to suggest the average barley yield in 1931 is different between the ten varieties? If the difference is found, use Tukey’s HSD test to identify which varieties are different in the 1931 yield.
Which hypothesis test is appropriate for this study? Why? [3 marks]
One way ANOVA is appropriate. Used to determine whether or not the means are equal under different (independent) treatment groups.
Write down the model associated with the test [2 marks]
\[ Y_{tr}=\mu+\tau_t+\epsilon_{tr} \]
Follow the appropriate steps for the hypothesis test [6 marks]
Step 1: Hypotheses – \(H_0\) average barley yield is the same for all ten varieties. \(H_a\) at least one variety differs in average yield.
Interpret the result [2 marks]
A consumer agency wants to check if the mean lives of four brands of car batteries, which sell for nearly the same price, are the same. The agency randomly selected a few batteries of each band and tested the, The following table gives the lives of these batteries in thousands of hours.
| Brand A | Brand B | Brand C | Brand D |
|---|---|---|---|
| 74 | 53 | 57 | 56 |
| 78 | 51 | 71 | 51 |
| 51 | 47 | 81 | 49 |
| 56 | 59 | 77 | 43 |
| 65 | 68 |
At the 5% significance level, is there a difference in the mean lifetime of these four brands of batteries? (assume the lives of batteries has normal distribution, you need to include the steps of hypothesis tests) [6 marks]
Step 1: Hypotheses – \(H_0\) there is no difference in the mean lifetime between all four brands. \(H_a\) at least one brand differs in mean lifetime.
Of the brands tested in this study, is there a specific brand you will/will not recommend to consumers? Explain your reason? [4 marks]
Interpret the result [2 marks]