Part 1

Part 2

library(ggplot2)
data("diamonds")

For Hypothesis 1 (Carat Weight):

# Subset the data
diamonds_subset_1 <- subset(diamonds, cut %in% c("Ideal", "Premium"))

# Perform the t-test for Neyman-Pearson
if (nrow(diamonds_subset_1) >= 20) {
  result_np <- t.test(carat ~ cut, data = diamonds_subset_1, alternative = "two.sided")
  cat("Neyman-Pearson Test for Hypothesis 1 (Carat Weight):\n")
  print(result_np)
} else {
  cat("Not enough data to perform Neyman-Pearson test for Hypothesis 1.\n")
}
## Neyman-Pearson Test for Hypothesis 1 (Carat Weight):
## 
##  Welch Two Sample t-test
## 
## data:  carat by cut
## t = 35.774, df = 25704, p-value < 2.2e-16
## alternative hypothesis: true difference in means between group Premium and group Ideal is not equal to 0
## 95 percent confidence interval:
##  0.1787563 0.1994796
## sample estimates:
## mean in group Premium   mean in group Ideal 
##             0.8919549             0.7028370
# Perform the t-test for Fisher's style test
result_fisher <- t.test(carat ~ cut, data = diamonds_subset_1, alternative = "two.sided")
cat("Fisher's Style Test for Hypothesis 1 (Carat Weight):\n")
## Fisher's Style Test for Hypothesis 1 (Carat Weight):
print(result_fisher)
## 
##  Welch Two Sample t-test
## 
## data:  carat by cut
## t = 35.774, df = 25704, p-value < 2.2e-16
## alternative hypothesis: true difference in means between group Premium and group Ideal is not equal to 0
## 95 percent confidence interval:
##  0.1787563 0.1994796
## sample estimates:
## mean in group Premium   mean in group Ideal 
##             0.8919549             0.7028370

For Hypothesis 2 (Price):

# Subset the data
diamonds_subset_2 <- subset(diamonds, cut %in% c("Fair", "Good"))

# Perform the t-test for Neyman-Pearson
if (nrow(diamonds_subset_2) >= 20) {
  result_np <- t.test(price ~ cut, data = diamonds_subset_2, alternative = "two.sided")
  cat("Neyman-Pearson Test for Hypothesis 2 (Price):\n")
  print(result_np)
} else {
  cat("Not enough data to perform Neyman-Pearson test for Hypothesis 2.\n")
}
## Neyman-Pearson Test for Hypothesis 2 (Price):
## 
##  Welch Two Sample t-test
## 
## data:  price by cut
## t = 4.1684, df = 2822.3, p-value = 3.16e-05
## alternative hypothesis: true difference in means between group Fair and group Good is not equal to 0
## 95 percent confidence interval:
##  227.6710 632.1156
## sample estimates:
## mean in group Fair mean in group Good 
##           4358.758           3928.864
# Perform the t-test for Fisher's style test
result_fisher <- t.test(price ~ cut, data = diamonds_subset_2, alternative = "two.sided")
cat("Fisher's Style Test for Hypothesis 2 (Price):\n")
## Fisher's Style Test for Hypothesis 2 (Price):
print(result_fisher)
## 
##  Welch Two Sample t-test
## 
## data:  price by cut
## t = 4.1684, df = 2822.3, p-value = 3.16e-05
## alternative hypothesis: true difference in means between group Fair and group Good is not equal to 0
## 95 percent confidence interval:
##  227.6710 632.1156
## sample estimates:
## mean in group Fair mean in group Good 
##           4358.758           3928.864

Visualization 1 (Carat Weight - Hypothesis 1):

# Create a box plot
boxplot(carat ~ cut, data = diamonds_subset_1, main = "Carat Weight by Cut",
        xlab = "Cut", ylab = "Carat Weight")

# Add significance asterisk
if (result_fisher$p.value < 0.05) {
  text(1.5, max(diamonds_subset_1$carat), "*", cex = 1.5)
}

# Add legend
legend("topright", legend = ifelse(result_fisher$p.value < 0.05, "p < 0.05", "p >= 0.05"), 
       pch = "*", col = "red")

Visualization 2 (Price - Hypothesis 2):

# Create a box plot
boxplot(price ~ cut, data = diamonds_subset_2, main = "Price by Cut",
        xlab = "Cut", ylab = "Price")

# Add significance asterisk
if (result_fisher$p.value < 0.05) {
  text(1.5, max(diamonds_subset_2$price), "*", cex = 1.5)
}

# Add legend
legend("topright", legend = ifelse(result_fisher$p.value < 0.05, "p < 0.05", "p >= 0.05"), 
       pch = "*", col = "red")

Hypothesis 1 (Carat Weight):

Insight Gathered: The hypothesis test comparing the average carat weight of diamonds with “Ideal” and “Premium” cuts reveals whether there is a statistically significant difference in carat weight between these two cut categories.

Significance:

If the p-value is less than the chosen alpha level (0.05), we would reject the null hypothesis, indicating a significant difference in average carat weight between diamonds with “Ideal” and “Premium” cuts. If the p-value is greater than alpha, we would fail to reject the null hypothesis, suggesting no significant difference. Further Questions:

If we reject the null hypothesis, it’s important to understand the practical significance of the difference. What impact does a small difference in carat weight have on the perceived value and desirability of the diamonds? Additional analysis could explore whether other factors like color, clarity, or price contribute to the variation in carat weight. Investigate whether these findings align with consumer preferences and market trends in the diamond industry. Hypothesis 2 (Price):

Insight Gathered: The hypothesis test comparing the average price of diamonds with “Fair” and “Good” cuts reveals whether there is a statistically significant difference in price between these two cut categories.

Significance:

If the p-value is less than the chosen alpha level (0.05), we would reject the null hypothesis, indicating a significant difference in average price between diamonds with “Fair” and “Good” cuts. If the p-value is greater than alpha, we would fail to reject the null hypothesis, suggesting no significant difference. Further Questions:

If we reject the null hypothesis, it suggests a significant difference in price. To understand the implications, we may investigate the practical significance of this price difference and whether it impacts consumer choices. Consider whether other attributes, such as carat weight, color, or clarity, are contributing to the variation in price. Explore market dynamics and consumer preferences to determine if this price difference aligns with industry trends.