Model Equation: \[ Y_i = \mu + \tau_i + \epsilon_i \]
Null Hypothesis (\(H_0\)): \(\mu_A = \mu_B\)
Alternative Hypothesis (\(H_a\)): $\mu_A \neq \mu_B$
# Loading Data
lifespans <- read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/refs/heads/main/lifespans.csv")
# Boxplot
boxplot(lifespans$Lifespan ~ lifespans$Supplier,
main = "Boxplot of Lifespans by Supplier",
xlab = "Supplier",
ylab = "Lifespan (hours)",
col = c("blue", "red"))
# two-sample t-test with pooled variances
t_test_result <- t.test(Lifespan ~ Supplier, data = lifespans, var.equal = TRUE)
t_test_result
##
## Two Sample t-test
##
## data: Lifespan by Supplier
## t = 2.6682, df = 18, p-value = 0.01567
## alternative hypothesis: true difference in means between group A and group B is not equal to 0
## 95 percent confidence interval:
## 2.411193 20.269776
## sample estimates:
## mean in group A mean in group B
## 504.4806 493.1401
The p-value<0.05.
we fail to reject \(H_0\)
There is no significant differnce in the mean lifespan between Supplier A and Supplier B.
# defining data
Before <- c(35, 40, 32, 38, 36, 42, 39, 41)
After <- c(30, 38, 31, 36, 34, 40, 37, 39)
# Paired t-test
t_test_result <- t.test(Before, After, paired = TRUE)
t_test_result
##
## Paired t-test
##
## data: Before and After
## t = 5.4628, df = 7, p-value = 0.0009431
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
## 1.276065 3.223935
## sample estimates:
## mean difference
## 2.25
The P-value <0.05.
we fail to reject \(H_0\)
The training program significantly reduces tasks completion time
Model equation : \[ Y_{ij} = \mu + \tau_i + \epsilon_{ij} \] Null Hypothesis (\(H_0\)): All material means are equal. Alternative Hypothesis (\(H_a\)): At least one material mean differs.
# Load the dataset from the csv file
tensile_strength <- read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/refs/heads/main/tensile_strength.csv")
# Performing ANOVA
anova_result <- aov(Strength ~ Material, data = tensile_strength)
summary(anova_result)
## Df Sum Sq Mean Sq F value Pr(>F)
## Material 2 972.2 486.1 3.039 0.0855 .
## Residuals 12 1919.3 159.9
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#Anova Result significant: Performing Tukey's post-hoc test if significant
if (summary(anova_result)[[1]]["Material", "Pr(>F)"] < 0.05) {
tukey_result <- TukeyHSD(anova_result)
tukey_result
}
The ANOVA p-value <0.05.
we reject \(H_0\)
Atleast one material differs significantly in mean tensile strenght.
Model Equation : \[ Y_{ijk} = \mu + \tau_i + \beta_j + (\tau\beta)_{ij} + \epsilon_{ijk} \]
# Loading the yield data
yield_data <- read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/refs/heads/main/yield_data.csv")
yield_data$Temperature <- as.factor(yield_data$Temperature)
yield_data$Pressure <- as.factor(yield_data$Pressure)
# Performing two-way ANOVA
anova_result <- aov(Yield ~ Temperature * Pressure, data = yield_data)
summary(anova_result)
## Df Sum Sq Mean Sq F value Pr(>F)
## Temperature 1 433.8 433.8 26.637 0.000863 ***
## Pressure 1 95.9 95.9 5.889 0.041412 *
## Temperature:Pressure 1 1.0 1.0 0.060 0.811915
## Residuals 8 130.3 16.3
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Extracting and displaying main effects and interaction effects
summary(anova_result)
## Df Sum Sq Mean Sq F value Pr(>F)
## Temperature 1 433.8 433.8 26.637 0.000863 ***
## Pressure 1 95.9 95.9 5.889 0.041412 *
## Temperature:Pressure 1 1.0 1.0 0.060 0.811915
## Residuals 8 130.3 16.3
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
P-Value <0.05 for both temperature and pressure.
we reject \(H_o\) for all factors. both Temperature and pressure as well as their interaction significantly affect yield.
# Combined R Code from Questions 1-4
# Question 1
lifespans <- read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/refs/heads/main/lifespans.csv")
boxplot(lifespans$Lifespan ~ lifespans$Supplier, main = "Boxplot of Lifespans by Supplier", xlab = "Supplier", ylab = "Lifespan (hours)", col = c("blue", "red"))
t_test_result <- t.test(Lifespan ~ Supplier, data = lifespans, var.equal = TRUE)
print(t_test_result)
# Question 2
Before <- c(35, 40, 32, 38, 36, 42, 39, 41)
After <- c(30, 38, 31, 36, 34, 40, 37, 39)
t_test_result <- t.test(Before, After, paired = TRUE)
print(t_test_result)
# Question 3
tensile_strength <- read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/refs/heads/main/tensile_strength.csv")
anova_result <- aov(Strength ~ Material, data = tensile_strength)
summary(anova_result)
if (summary(anova_result)[[1]]["Material", "Pr(>F)"] < 0.05) {
tukey_result <- TukeyHSD(anova_result)
print(tukey_result)
}
# Question 4
yield_data <- read.csv("https://raw.githubusercontent.com/tmatis12/datafiles/refs/heads/main/yield_data.csv")
yield_data$Temperature <- as.factor(yield_data$Temperature)
yield_data$Pressure <- as.factor(yield_data$Pressure)
anova_result <- aov(Yield ~ Temperature * Pressure, data = yield_data)
summary(anova_result)