#################
# FLIGHT DATA
#################
# reading in data
library(readxl)
flight_data <- read_excel("flight_times.xlsx")R Lab Session – Week 8
Experiment 1
An air traffic officer is interested in discovering if the same plane travelling under capacity will always have a quicker flight than when travelling over capacity. The officer collected the data found in flight_times.xlsx. Conduct an appropriate test at the 5% significance level to discover if the officer is correct in thinking that an under-capacity flight will be quicker than an over-capacity one.
Question 1
Inspecting the distribution of the differences (Under − Over) reveals the following:
- The box plot looks relatively symmetric but there is a clear outlier.
- The histogram shows some right skewness due to the large positive outlier.
- The Q-Q plot shows distortion of normality due to the outlier, since most of the points roughly follow the XY line relatively well, except at the upper tail.
- All the above, together with the fact that the data has a small sample size, leads to the conclusion that we cannot confidently conclude normality.
- There are no clear deviations from normality.
###########################
# CALCULATING DIFFERENCES
###########################
flight_data$diff <- flight_data$Under_capacity_flight - flight_data$Over_capacity_flight
# histogram of differences
hist(flight_data$diff, main="Histogram of Diffences",
xlab="Under - Over", ylab="")# boxplot of differences
boxplot(flight_data$diff, main="Boxplot of Paired Diffeences")# QQ plot of Differences
qqnorm(flight_data$diff, main="QQ Plot of Differences")
qqline(flight_data$diff)A, B and C are all true, which makes D true as well.
Question 2
What type of data has been collected in this experiment, how many samples are there, and what is the relationship between the samples?
Interval data, two samples, dependent.
Ratio scale data, two samples, independent.
Ratio scale data, two samples, dependent.
Interval data, two samples, independent.
We have collected quantitative data here. Since we are measuring duration of the flights when each flight has over and under-capacity, we can observe that a \(0\) value means that there was no duration of the flight. This is a meaningful \(0\) value. So, we have ratio-scaled data.
Also, we are measuring the duration for a particular flight under these conditions. These values will be specific to each flight, and so we have dependent samples.
We choose C.
Question 3
This is a lower tailed one-sided test, since the alternative is “less than”.
True
False
True
Question 4
What is the sample size before conducting the test?
32
Question 5
What is the sample size used to calculate the test statistic?
########################################################
# NUMBER OF DIFFERENCES USED TO FIND THE TEST STATISTIC
########################################################
# remove zero differences
flight_data <- flight_data[flight_data$diff != 0,]
# number of non-zero differences
n <- nrow(flight_data)
n[1] 32
32
Question 6
What is the sum of the signed ranks?
###################################
# SUM OF SIGNED RANKS CALCULATION
###################################
#absolute differences
flight_data$absdiff <- abs(flight_data$diff)
# ranking absolute differences
rank <- rank(flight_data$absdiff, ties.method="average")
# reassign signs
signed_ranks <- rank * sign(flight_data$diff)
# sum of signed ranks
W <- sum(signed_ranks)
W[1] -80
\(W=-80\)
Question 7
What is the p-value reported by the built-in function?
#################################
# WILCOXON SIGNED RANK SUM TEST
#################################
wilcox.test(flight_data$Under_capacity_flight,
flight_data$Over_capacity_flight, paired=TRUE, exact=FALSE,
alternative="less")
Wilcoxon signed rank test with continuity correction
data: flight_data$Under_capacity_flight and flight_data$Over_capacity_flight
V = 224, p-value = 0.2287
alternative hypothesis: true location shift is less than 0
0.23
Question 8
What is the test statistic used to draw a conclusion when you conduct the test manually?
\[ z=\frac{-80-0}{\sqrt{\frac{(32)(32+1)(2(32)+1)}{6}}}\approx-0.75 \]
Question 9
Based on the results, we fail to reject the null hypothesis given that the p-value is quite large.
True
False
True
Experiment 2
A Liverpool FC fan is trying to see if he is biased towards Darwin Núñez or if he truly is just extremely likable.
Two groups of people were randomly selected with 18 members in each group. They were shown videos that were intended to make them smile.
Group 1 was shown a video of kittens and puppies playing together.
Group 2 were shown a clip of Darwin Núñez (the Number 9 for Liverpool FC) scoring goals and trying to converse with his teammates in English.
After watching the respective videos, they were asked to choose a number to represent their increase in happiness.
No increase in happiness
Small increase in happiness
Moderate increase in happiness
Large increase in happiness
Very large increase in happiness
Apply the appropriate non-parametric test at the 5% significance level to confirm whether the Liverpool fan is delusional or if Darwin truly is just a cultivator of happiness.
Question 10
What type of data has been collected, how many samples are there, and what is the relationship between the samples?
Two samples of nominal data and the samples are paired.
Two samples of ordinal data and the samples are independent.
Two samples of ordinal data and the samples are paired.
Two samples of ordinal data and the samples are independent.
We have collected two samples of ordinal data. Since the two experimental units in each of the groups were watching different videos, they observations of the two samples were independent.
So, we choose B.
Question 11
The following hypotheses are correct.
Null: There is no difference in happiness increase between those who were shown videos of Darwin and those who watched kittens and puppies playing.
Alternative: Those who were shown videos of Darwin experienced a greater increase in happiness than those who were shown the animal videos.
True
False
True
Question 12
Which testing approach is appropriate in this case?
Large sample approach (normal approximation)
Small sample approach (exact distribution)
A large sample approach is appropriate since \(n>10\). So, A.
Question 13
What is the test statistic reported by the built-in function?
####################################
# HAPPY VIDEOS MANN-WHITNEY U TEST
####################################
# readin in data
happy_data <- read_excel("happy_vids.xlsx")
# test
wilcox.test(happy_data$Darwin, happy_data$Kittens_and_Puppies,
exact=FALSE, alternative="greater")
Wilcoxon rank sum test with continuity correction
data: happy_data$Darwin and happy_data$Kittens_and_Puppies
W = 233, p-value = 0.01054
alternative hypothesis: true location shift is greater than 0
\(W=233\)
Question 14
What is the p-value reported by the built-in function?
\(p=0.01\)
Question 15
What is the total sample size for this experiment?
36
Experiment 3
A group of agricultural researchers is studying the effectiveness of three different fertilizers on the growth of tomato plants over a 6-week period.
The fertilizers being compared are:
Fertilizer A: A standard organic compost,
Fertilizer B: A synthetic nitrogen-rich commercial mix,
Fertilizer C: A novel eco-friendly biofertilizer made from food waste.
Each group has 12 plants, randomly assigned. After 6 weeks, they measured the number of tomatoes produced per plant.
Question 16
What type of data has this experiment collected, how many samples are there and what is the relationship between the samples?
Three samples of interval data and the samples are paired.
Three samples of ratio scale data and the samples are independent.
Three samples of nominal data and the samples are independent.
Three samples of interval data and the samples are dependent.
We are dealing with quantitative data since we are making an observation of how many tomatoes were produced per plant. Here, the \(0\) value means an absence of tomatoes produced, and since this is a meaningful measurement, we have ratio-scaled data.
Also, by the nature of the experiment, the observations within and between blocks (or samples) are independent. So, we choose B.
Question 17
Inspecting the data before conducting the test reveals two severe outliers. Based on this, the decision is made to use a non-parametric test.
True
False
True
Question 18
What is the p-value reported by the built-in function?
##################################
# FERTILIZER KRUSKAL-WALLIS TEST
##################################
#reading in data
fertiliser_data <- read.csv("plant_growth.csv")
# test
kruskal.test(Tomatoes ~ Fertilizer, data=fertiliser_data)
Kruskal-Wallis rank sum test
data: Tomatoes by Fertilizer
Kruskal-Wallis chi-squared = 16.82, df = 2, p-value = 0.0002226
\(p=0.00\)
Question 19
If I conducted the test manually then the following code would produce the correct p-value:
p_value <- pchisq(H, df = 2, lower.tail = FALSE)
- True
- False
True
Question 20
Based on the results of the test, the following conclusion is correct.
We have strong evidence against the null hypothesis of equal medians (p-value < 0.01), suggesting that the distribution of the number of tomatoes differs across fertilizer types. In other words, the fertilizer did have an effect on the number of tomatoes.
True
False
True