I wanted to test if it is easier to charge a higher price if a wine is sealed with a natural cork or with a screw cap. I wanted to test this due to a belief that one method of closure presents quality and the other one doesn’t.
I found data that presents 1290 wines with their descriptions and many variables of which price and method of closure are of importance for the research question.
Source of data: Kaggle- Wine dataset (Url: https://www.kaggle.com/datasets/elvinrustam/wine-dataset)
library(readr)
Wine <- read_csv("~/Desktop/IMB/Multivariate /HW/H1/WineDataset.csv")
## Rows: 1290 Columns: 17
## ── Column specification ────────────────────────────────────────────────────────────────────────────────────────────────
## Delimiter: ","
## chr (16): Title, Description, Price, Capacity, Grape, Secondary Grape Varieties, Closure, Country, Characteristics, ...
## dbl (1): Unit
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(Wine)
## # A tibble: 6 × 17
## Title Description Price Capacity Grape Secondary Grape Vari…¹ Closure Country Unit Characteristics
## <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <dbl> <chr>
## 1 The Guv'nor, Spain "We asked … £9.9… 75CL Temp… <NA> Natura… Spain 10.5 Vanilla, Black…
## 2 Bread & Butter 'Winemak… "This real… £15.… 75CL Char… <NA> Natura… USA 10.1 Vanilla, Almon…
## 3 Oyster Bay Sauvignon Bl… "Oyster Ba… £12.… 75CL Sauv… <NA> Screwc… New Ze… 9.8 Tropical Fruit…
## 4 Louis Latour Mâcon-Lugn… "We’ve sol… £17.… 75CL Char… <NA> Natura… France 10.1 Peach, Apricot…
## 5 Bread & Butter 'Winemak… "Bread & B… £15.… 75CL Pino… <NA> Natura… USA 10.1 Smoke, Black C…
## 6 Louis Roederer 'Cristal… "Cristal i… £300… 75CL Char… <NA> Natura… France 9 <NA>
## # ℹ abbreviated name: ¹`Secondary Grape Varieties`
## # ℹ 7 more variables: `Per bottle / case / each` <chr>, Type <chr>, ABV <chr>, Region <chr>, Style <chr>,
## # Vintage <chr>, Appellation <chr>
Unit of observation: one wine
Sample size: 1290
Number of variables: 17
Explanation of variables:
Because the sample was too large, we randomly selected 80 wines with the function set.seed, on which we will later perform hypothesis tests.
set.seed(1)
Wine1 <- Wine[sample(nrow(Wine), 80), ]
Using the function mutate from dplyr we removed the unit of measure from the variable price. It changed from for example ‘39.99 per bottle’ to just 39.99.
library(dplyr)
##
## Attaching package: 'dplyr'
## The following object is masked from 'package:car':
##
## recode
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
Wine2 <- Wine1 %>%
mutate(Price = as.numeric(sub("£([0-9.]+).*", "\\1", Price)))
head(Wine2$Price)
## [1] 39.99 37.99 61.99 19.99 14.99 59.94
We then wanted to see if variable Closure had any missing values and found only one. We eliminated it from the data and also deleted the row where the wine was sealed with a synthetic cork, as we are only interested in wines sealed with natural cork and screw caps.
rows_with_missing_values <- which(is.na(Wine2$Closure))
print(rows_with_missing_values)
## [1] 6
Wine3 <- Wine2[complete.cases(Wine2$Closure) & Wine2$Closure != "Synthetic Cork", ]
We changed categorical variables into factors.
Wine3$Closure<- factor(Wine3$Closure,
levels = c("Natural Cork", "Screwcap"),
labels = c("Natural Cork", "Screwcap"))
library(psych)
##
## Attaching package: 'psych'
## The following objects are masked from 'package:ggplot2':
##
## %+%, alpha
## The following object is masked from 'package:car':
##
## logit
describeBy(Wine3$Price, Wine3$Closure)
##
## Descriptive statistics by group
## group: Natural Cork
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 55 31.46 30.55 23.99 26.3 17.79 9.99 210 200.01 3.78 18.68 4.12
## ------------------------------------------------------------------------------------------
## group: Screwcap
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 23 17.97 16.44 12.99 14.49 5.93 6.99 85 78.01 2.96 9.16 3.43
Explanation of results: - N: in the sample are 55 wines sealed with a natural cork and 22 wines sealed with a screw cap
Mean: the average price for wines closed with a natural cork is 31.46 pounds and for wines closed with a screw cap the average price is 17.97 pounds.
Median: 50% of all wines sealed with a natural cork are priced above 30.55 pounds and 50% under 30.55 pounds.
Min/Max: the lowest price of wine sealed with a natural cork is 9.99 pounds and the maximum price is 210 pounds.
Skewness: positive skewness in both methods indicates that the distribution is asymmetrical to the right.
Repeating the research question: We wanted to test if it is easier to charge a higher price if a wine is sealed with a natural cork or a screw cap. We will use medians rather than averages because of outliers.
H0: The median price of wine, based on the method of closure is the sane. H1: The median price of wine, based on the method of closure is not the same.
ASSUMPTIONS for parametrical method:
Compared variable is numeric: this is true because price is numeric.
Normal distribution of price in both populations: this will be later checked with Shapiro-Wilk normality test.
Data needs to come from two independent populations: sample is independent because we divide wines in two groups based on the method of closure.
Variable has the same variance in both populations: we never assume this because the test is not reliable. Instead we use Welch correction.
We will check normality first with a graph and then with Shapiro-Wilk normality test. Because we will not focus on outliers, the graph is only shown till the relevant prices.
We can see that both groups do not look normally distributed as they are both asymmetrical to the right.
library(ggplot2)
NaturalCork <- ggplot(Wine3[Wine3$Closure == "Natural Cork", ], aes(x = Price)) +
theme_linedraw() +
geom_bar(colour = "black", fill = "blue", width = 2) +
ylab("Frequency") +
ggtitle("Natural Cork") +
coord_cartesian(xlim = c(0, 75))
Screwcap <- ggplot(Wine3[Wine3$Closure == "Screwcap", ], aes(x = Price)) +
theme_linedraw() +
geom_bar(colour = "black", fill = "red", width = 1) +
ylab("Frequency") +
ggtitle("Screwcap") +
coord_cartesian(xlim = c(0, 30))
library(ggpubr)
ggarrange(NaturalCork, Screwcap, ncol = 2, nrow = 1)
## Warning: `position_stack()` requires non-overlapping x intervals
## `position_stack()` requires non-overlapping x intervals
library(dplyr)
library(rstatix)
##
## Attaching package: 'rstatix'
## The following object is masked from 'package:stats':
##
## filter
Wine3 %>%
group_by(Closure) %>%
shapiro_test(Price)
## # A tibble: 2 × 4
## Closure variable statistic p
## <fct> <chr> <dbl> <dbl>
## 1 Natural Cork Price 0.614 8.93e-11
## 2 Screwcap Price 0.596 8.14e- 7
The hypothesis for Shapiro-Wilk test:
H0: variable is normally distributed
H1: variable is not normally distributed
BSD we reject the normality assumption for both groups. The corresponding p-values are p<0.001.
Because normality assumption is not met, we can not use the parametric method and need to preform the the Wilcoxon Rank Sum Test- non-parametric option.
wilcox.test(Wine3$Price ~ Wine3$Closure,
paired = FALSE,
correct = FALSE,
exact = FALSE,
alternative = "two.sided")
##
## Wilcoxon rank sum test
##
## data: Wine3$Price by Wine3$Closure
## W = 922, p-value = 0.0015
## alternative hypothesis: true location shift is not equal to 0
The hypothesis for Wilcoxon Rank Sum test:
H0: the locations of distributions are the same.
H1: the locations of distributions are not the same.
Based on the sample data we reject the null hypothesis at p=0.002.
library(ggplot2)
custom_colors <- c("Natural Cork" = "blue", "Screwcap" = "red")
ggplot(Wine3, aes(x = Price, fill = Closure)) +
geom_histogram(position = position_dodge(width = 2.5), binwidth = 5, colour = "Black") +
scale_x_continuous(breaks = seq(0, 75, 5)) +
ylab("Frequency") +
labs(fill = "Closure") +
scale_fill_manual(values = custom_colors)
library(effectsize)
##
## Attaching package: 'effectsize'
## The following objects are masked from 'package:rstatix':
##
## cohens_d, eta_squared
## The following object is masked from 'package:psych':
##
## phi
effectsize(wilcox.test(Wine3$Price ~ Wine3$Closure,
paired = FALSE,
correct = FALSE,
exact = FALSE,
alternative = "two.sided"))
## r (rank biserial) | 95% CI
## --------------------------------
## 0.46 | [0.21, 0.65]
interpret_cohens_d(0.46, rules = "sawilowsky2009")
## [1] "small"
## (Rules: sawilowsky2009)
The difference in distribution is small (𝑟 = 0.46).
If normality would be met, we would continue with the parametric option. Even though in our case norallity was not met we will still show the parametric option:
t.test(Wine3$Price ~ Wine3$Closure,
paired = FALSE,
var.equal = FALSE,
alternative = "two.sided")
##
## Welch Two Sample t-test
##
## data: Wine3$Price by Wine3$Closure
## t = 2.5179, df = 71.052, p-value = 0.01406
## alternative hypothesis: true difference in means between group Natural Cork and group Screwcap is not equal to 0
## 95 percent confidence interval:
## 2.808083 24.180344
## sample estimates:
## mean in group Natural Cork mean in group Screwcap
## 31.46291 17.96870
The hypothesis for t.test with Welch correction:
H0: The median prices of wine, based on the method of closure are the same.
H1: The median prices of wine, based on the method of closure are not the same.
We can reject the null hypothesis at p=0.015.
Based on the sample data, we find that wine price differs based on the method of closure (𝑝 = 0.002) - wine closed with natural cork is more expensive because the min, max, and median prices are higher as well as the location distribution being asymmetrical to the right. The difference in distribution is small (𝑟 = 0.46).