knitr::opts_chunk$set(echo = TRUE)
#1. Clearly write your research question.
#Question a: The average revenue of the same companies was 613.25 thousands US dollar 2 years ago (2019). Is the average revenue different than 2 year ago. Was the revenue of the companies affected by the Covid pandemic in 2020?
#Question B: The average number customer visits to the same companies was 304.7 customers per month 2 years ago. Is the average number of customer visiting different from that in 2019? Was average number of customer visiting affected by the Covid pandemic in 2020?
#Question C: Are the average operating and financing costs different?
#Question D: We would like to find out, if the revenue of the selected 50 companies differed based on the fact, if the company operates on international or domestic markets.
#Question E: We would like to find out, if the producitivity is related to the fact, if the group did the break, had 15 or 30 minutes. breaks
#2. Find your data: I asked Chat gpt to create an appropriate data set. #3. Import it into R Studio.
setwd("/Users/admin/Desktop")
data<-read.table("dataset2.csv", header = TRUE, sep =",", dec = ".")
#4. Display your data using the head function.
head(data)
## Revenue Operating.Costs Financing.Cost Customer.Visits Website.Visits Market
## 1 720.51 258.94 258.3093 262 299 1
## 2 550.02 191.00 184.9953 208 281 0
## 3 622.34 146.46 141.6450 48 315 0
## 4 780.11 252.72 244.7697 41 280 0
## 5 733.44 179.84 176.7538 330 308 0
## 6 377.84 261.12 263.5091 275 291 1
## Product.Type
## 1 1
## 2 2
## 3 3
## 4 3
## 5 3
## 6 1
#5. Explain your data (what is the unit of observation,sample size,definition of all variables,units of measurement, etc.).
summary(data)
## Revenue Operating.Costs Financing.Cost Customer.Visits
## Min. :180.9 Min. :132.6 Min. :132.6 Min. : 2.00
## 1st Qu.:438.5 1st Qu.:179.4 1st Qu.:176.9 1st Qu.: 47.25
## Median :518.7 Median :219.5 Median :218.8 Median :168.00
## Mean :517.6 Mean :218.0 Mean :217.5 Mean :192.66
## 3rd Qu.:616.1 3rd Qu.:248.7 3rd Qu.:253.5 3rd Qu.:272.00
## Max. :783.7 Max. :297.2 Max. :302.9 Max. :831.00
## Website.Visits Market Product.Type
## Min. :259.0 Min. :0.00 Min. :1.00
## 1st Qu.:286.0 1st Qu.:0.00 1st Qu.:1.00
## Median :299.0 Median :1.00 Median :2.00
## Mean :298.8 Mean :0.56 Mean :1.96
## 3rd Qu.:312.8 3rd Qu.:1.00 3rd Qu.:2.75
## Max. :341.0 Max. :1.00 Max. :3.00
#Number of observations - 50 #Number of variables - 6 (4 numerical; 2 categorical)
#Data set describe revenues, net income and operating costs of 50 different companies Austrian in 2021 companies performing whether on international or domestic markets,supplying consumer, industrial goods or ones related to technology
#Revenue #Type:numerical #Definition: This is the total revenue earned by the company. #Unit of Measurement: Thousands of dollars
#Operating Costs: #Type:numerical #Definition: This is the total cost incurred from the company’s operations, excluding costs like taxes and interest. #Unit of Measurement: Thousands of dollars
#Financing Cost: #Definition: This variable represents the costs associated with financing, such as interest expenses. #Type:numerical #Unit of Measurement: Thousands of dollars
#Customer visits #Type:numerical #Definition: This variable measures the number of customer visits #Unit of Measurement: Number of visits.
#Website Visits: #Definition: The number of visits to a company’s website, #Type:numerical #Unit of Measurement: Number of visits
#Market: #Definition: This categorical variable identifies whether the company operates primarily in the domestic or international market. #Type:categorical #Categories: ‘Domestic’, ‘International’.
#Product Type: #Definition: This variable describes the type of products the company primarily sells. #Type:categorical #Categories: ‘Consumer Goods’, ‘Technology’, ‘Industrial’.
#6. Name the source of the data clearly. Write the link. # I asked chat gpt to create a data set. The command given: Generate data send in csv format with 50 observations, include 4 numeric variables and 2 categorical. Data set should be related to economics or business
#7. Carry our data manipulation if necessary (e.g., clean the data, convert categorical variables to factors, etc.)
factor(data$Market, levels = c("1","0"),labels = c("International","Domestic"))
## [1] International Domestic Domestic Domestic Domestic
## [6] International International International Domestic International
## [11] Domestic International Domestic Domestic Domestic
## [16] Domestic International International International Domestic
## [21] International Domestic Domestic International International
## [26] International Domestic International International Domestic
## [31] International Domestic International International Domestic
## [36] Domestic International International Domestic International
## [41] International International International International International
## [46] Domestic Domestic International Domestic International
## Levels: International Domestic
factor(data$Product.type, levels = c("1","2","3"),labels = c("Industrial","Consumer Goods","Technology"))
## factor()
## Levels: Industrial Consumer Goods Technology
#8. Perform the statistical hypothesis test to answer your research question.
#Hypothesis about the arithemtic mean #Requirements: # - Varible is numeric # - Normality - variable on the population is normally distributed
#Question a: The average revenue of the same companies was 613.25 thousands US dollar 2 years ago (2019). Is the average revenue different than 2 year ago. Was the revenue of the companies affected by the Covid pandemic in 2020?
mean(data$Revenue)
## [1] 517.5698
sd(data$Revenue)
## [1] 142.1186
hist(data$Revenue, ylab = "Frequency", xlab = "Revenue", main = "Distribution of Revenue", col = "darkblue")
#Shapiro test #H0: Variable is normally distributed
shapiro.test(data$Revenue)
##
## Shapiro-Wilk normality test
##
## data: data$Revenue
## W = 0.98765, p-value = 0.8766
#Since, p-value = 0.8766, variable is normally distributed and it is numeric, so we can conduct parametric t.test
t.test(data$Revenue, mu = 613.25, alternative = "two.sided")
##
## One Sample t-test
##
## data: data$Revenue
## t = -4.7605, df = 49, p-value = 1.749e-05
## alternative hypothesis: true mean is not equal to 613.25
## 95 percent confidence interval:
## 477.1801 557.9595
## sample estimates:
## mean of x
## 517.5698
library(effectsize)
effectsize::cohens_d(data$Revenue, mu = 613.25)
## Cohen's d | 95% CI
## --------------------------
## -0.67 | [-0.98, -0.36]
##
## - Deviation from a difference of 613.25.
interpret_cohens_d(0.73,rules = "sawilowsky2009")
## [1] "medium"
## (Rules: sawilowsky2009)
#Conclusion: We found out that the average revenue of 50 selected companies has decrease within 2 last years an is not equal to the value estimate previously (p<0.05, r= -0.67, medium effect) We can conclude, that due to the Covid-pandemic, the average revenue of 50 selected companies went down
#Question B: The average number customer visits to the same companies was 304.7 customer per month 2 years ago. Is the average number of customer visiting different from that in 2019? Was average number of customer visiting affected by the Covid pandemic in 2020?
#Hypothesis about the arithemtic mean #Requirements: # - Varible is numeric # - Normality - variable on the population is normally distributed
hist(data$Customer.Visits, ylab = "Frequency", xlab = "Revenue", main = "Distribution of Customer Visits", col = "lightgreen")
shapiro.test(data$Customer.Visits)
##
## Shapiro-Wilk normality test
##
## data: data$Customer.Visits
## W = 0.84743, p-value = 1.319e-05
#The variable is not normally distributed, since the p-value<0.05 (H:0 - Variable is normally distributed). That is why, we will go for non-parametric test
median(data$Customer.Visits)
## [1] 168
wilcox.test(data$Customer.Visits, mu = 304.7, correct = FALSE)
##
## Wilcoxon signed rank test
##
## data: data$Customer.Visits
## V = 184, p-value = 1.199e-05
## alternative hypothesis: true location is not equal to 304.7
library(effectsize)
effectsize(wilcox.test(data$Customer.Visits, mu = 304.7, correct = FALSE))
## r (rank biserial) | 95% CI
## ----------------------------------
## -0.71 | [-0.84, -0.52]
##
## - Deviation from a difference of 304.7.
interpret_rank_biserial(-0.71, rules = "funder2019")
## [1] "very large"
## (Rules: funder2019)
#Conclusion: We found out that the average number of visitors has decreased within 2 last years an is not equal to the value estimate previously (p<0.05, r= -0.71, very large effect) We can conclude, that Covid-pandemic has negatively affected the number of visitors of the selected companies
#Hypothesis about the difference between two population arithmetic means #Requirements for parametric tests
#Variable is numeric. # Normality: #- Paired Samples t-test: Differences on the population are normally distributed. #- Independent Samples t-test: The distribution of the variable is normal in both populations. #For independent Samples t-test: #- The data must come from two independent populations. #- Variable has the same variance in both populations – since this assumption is often violated, we apply Welch correction.
#Question C: Are the average operating and financing costs different?
data$Difference<-data$Operating.Costs-data$Financing.Cost
library(ggplot2)
ggplot(data, aes(x = Difference))+
geom_histogram(binwidth = 4, color = "black")+
xlab("Differences")
library(psych)
##
## Attaching package: 'psych'
## The following objects are masked from 'package:ggplot2':
##
## %+%, alpha
## The following object is masked from 'package:effectsize':
##
## phi
describe(data[,-1])
## vars n mean sd median trimmed mad min max
## Operating.Costs 1 50 218.03 48.03 219.46 218.07 53.92 132.61 297.18
## Financing.Cost 2 50 217.53 48.99 218.77 217.18 60.31 132.65 302.85
## Customer.Visits 3 50 192.66 171.82 168.00 170.75 176.43 2.00 831.00
## Website.Visits 4 50 298.76 19.16 299.00 298.55 19.27 259.00 341.00
## Market 5 50 0.56 0.50 1.00 0.57 0.00 0.00 1.00
## Product.Type 6 50 1.96 0.75 2.00 1.95 1.48 1.00 3.00
## Difference 7 50 0.49 5.65 0.18 0.45 5.54 -13.90 14.85
## range skew kurtosis se
## Operating.Costs 164.57 0.01 -1.07 6.79
## Financing.Cost 170.21 0.07 -1.10 6.93
## Customer.Visits 829.00 1.53 3.21 24.30
## Website.Visits 82.00 0.03 -0.67 2.71
## Market 1.00 -0.23 -1.98 0.07
## Product.Type 2.00 0.06 -1.28 0.11
## Difference 28.76 0.05 -0.20 0.80
shapiro.test(data$Difference)
##
## Shapiro-Wilk normality test
##
## data: data$Difference
## W = 0.99196, p-value = 0.981
#p-value>0.05, which means that differences on the population are normally distributed.
t.test(data$Operating.Costs, data$Financing.Cost, paired = TRUE, alternative = "two.sided")
##
## Paired t-test
##
## data: data$Operating.Costs and data$Financing.Cost
## t = 0.61777, df = 49, p-value = 0.5396
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
## -1.111640 2.098461
## sample estimates:
## mean difference
## 0.4934107
library(effectsize)
cohens_d(data$Difference)
## Cohen's d | 95% CI
## -------------------------
## 0.09 | [-0.19, 0.36]
interpret_cohens_d(0.09, rules = "sawilowsky2009")
## [1] "tiny"
## (Rules: sawilowsky2009)
#Conclusion: #The average operating costs (mean = 218.03) and financing costs (mean = 217.53) are different. The differnece is not statisticaly significant (p-value>0.05), the effect is tiny
#Question d: We would like to find out, if the revenue of the selected 50 companies differed based on the fact, if the operate on international or domestic markets.
data$Market<-factor(data$Market, levels = c("1","0"), labels = c("International","Domestic"))
library(psych)
describeBy(data$Revenue, data$Market == "International")
##
## Descriptive statistics by group
## group: FALSE
## vars n mean sd median trimmed mad min max range skew
## X1 1 22 533.31 115.3 530.62 532.08 102.76 298.26 780.11 481.85 0.11
## kurtosis se
## X1 -0.22 24.58
## ------------------------------------------------------------
## group: TRUE
## vars n mean sd median trimmed mad min max range skew
## X1 1 28 505.21 161.1 478.84 507.7 191.46 180.88 783.72 602.84 -0.08
## kurtosis se
## X1 -1.06 30.45
describeBy(data$Revenue, data$Market == "Domestic")
##
## Descriptive statistics by group
## group: FALSE
## vars n mean sd median trimmed mad min max range skew
## X1 1 28 505.21 161.1 478.84 507.7 191.46 180.88 783.72 602.84 -0.08
## kurtosis se
## X1 -1.06 30.45
## ------------------------------------------------------------
## group: TRUE
## vars n mean sd median trimmed mad min max range skew
## X1 1 22 533.31 115.3 530.62 532.08 102.76 298.26 780.11 481.85 0.11
## kurtosis se
## X1 -0.22 24.58
library(ggplot2)
Domestic<-ggplot(data[data$Market == "Domestic", ], aes(x = Revenue))+
theme_linedraw() +
geom_histogram() +
ggtitle("Domestic")
International<-ggplot(data[data$Market == "International", ], aes(x = Revenue))+
theme_linedraw() +
geom_histogram() +
ggtitle("International")
library(ggpubr)
ggarrange(Domestic, International, ncol = 2, nrow = 1)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
t.test(data$Revenue ~ data$Market, paired = FALSE, var.equal = FALSE, alternative = "two.sided")
##
## Welch Two Sample t-test
##
## data: data$Revenue by data$Market
## t = -0.7181, df = 47.645, p-value = 0.4762
## alternative hypothesis: true difference in means between group International and group Domestic is not equal to 0
## 95 percent confidence interval:
## -106.79407 50.59368
## sample estimates:
## mean in group International mean in group Domestic
## 505.2057 533.3059
library(effectsize)
effectsize::cohens_d(data$Revenue~data$Market, pooled_sd = FALSE)
## Cohen's d | 95% CI
## -------------------------
## -0.20 | [-0.75, 0.35]
##
## - Estimated using un-pooled SD.
interpret_cohens_d(0.2, rules = "sawilowsky2009")
## [1] "small"
## (Rules: sawilowsky2009)
#Conclusin: Based on the analysis, it cannot be statetd tha the average revenue differes depending on the fact if firm operates on the domestic or international market. The effect size is small (d=0.2)
#One-way analysis of variance (ANOVA) #Kruskal-valls rank sum test
#HO: all means in the independent samples are equal
#Assumptions and requirements : #• Analyzed variable is numeric. #• Variable in the population is normally distributed within each group. #• Homoscedasticity: the variance of analyzed variable is the same within all groups.
#Question E: We would like to find out, if the producitivity is related to the fact, if the group did the break, had 15 or 30 minutes. breaks
#I used another data set for this question
#3. Import it into R Studio.
setwd("/Users/admin/Desktop")
mydata<-read.table("dataset0.csv", header = TRUE, sep =",", dec = ".")
#4. Display your data using the head function.
head(mydata)
## Group Productivity.Level
## 1 1 59
## 2 1 52
## 3 1 55
## 4 1 61
## 5 1 59
## 6 1 45
#Descrobe your data #Group #Definition: Categorical independent variable indicating the type of work break activity. #Type:categorical #Categories: #1 - No Break: Employees who did not have a break activity. # 2 - 15 minutes Break #3 - 30 minues Breal
#Productivity Level: #Type:numerical #Definition: Continuous dependent variable measured to evaluate the employee’s productivity after the break.
mydata$Group<-factor(mydata$Group,levels = c(1,2,3), labels = c("No break", "15 minutes Break", "30 minutes break") )
library(psych)
describe(mydata$Productivity.Level)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 150 60.64 9.88 60.5 60.59 10.38 37 82 45 0.04 -0.66 0.81
describeBy(x = mydata$Productivity.Level, group = mydata$Group == "No break" )
##
## Descriptive statistics by group
## group: FALSE
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 100 65.62 7.48 65 65.42 8.15 51 82 31 0.19 -0.81 0.75
## ------------------------------------------------------------
## group: TRUE
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 50 50.68 5.67 51 50.77 5.93 37 61 24 -0.16 -0.57 0.8
describeBy(x = mydata$Productivity.Level, group = mydata$Group == "15 minutes Break" )
##
## Descriptive statistics by group
## group: FALSE
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 100 61.01 11.71 62 61.08 14.83 37 82 45 -0.05 -1.24 1.17
## ------------------------------------------------------------
## group: TRUE
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 50 59.9 4.39 60 59.88 4.45 51 69 18 0.07 -0.67 0.62
describeBy(x = mydata$Productivity.Level, group = mydata$Group == "30 minutes Break" )
##
## Descriptive statistics by group
## group: FALSE
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 150 60.64 9.88 60.5 60.59 10.38 37 82 45 0.04 -0.66 0.81
library(car)
## Loading required package: carData
##
## Attaching package: 'car'
## The following object is masked from 'package:psych':
##
## logit
leveneTest(mydata$Productivity.Level, group = mydata$Group)
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 2 1.5576 0.2141
## 147
#H0: the variances in the population are equal. Since p-value >0.05, we reject the null hypothesis and state that the variances are not equal
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
library(rstatix)
##
## Attaching package: 'rstatix'
## The following objects are masked from 'package:effectsize':
##
## cohens_d, eta_squared
## The following object is masked from 'package:stats':
##
## filter
mydata%>%
group_by(Group) %>%
shapiro_test(Productivity.Level)
## # A tibble: 3 × 4
## Group variable statistic p
## <fct> <chr> <dbl> <dbl>
## 1 No break Productivity.Level 0.986 0.802
## 2 15 minutes Break Productivity.Level 0.981 0.592
## 3 30 minutes break Productivity.Level 0.963 0.117
#H0: the data is normally distributed, so we cannot reject the null-hupothesis, since p-value>0.05 and state that the data is normally distributed
ANOVA_results<-aov(mydata$Productivity.Level~mydata$Group)
summary(ANOVA_results)
## Df Sum Sq Mean Sq F value Pr(>F)
## mydata$Group 2 10712 5356 204.7 <2e-16 ***
## Residuals 147 3847 26
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#HO: there is no difference between means, since the p-value<0.05, we can state that there are differences between group means
library(effectsize)
eta_squared(ANOVA_results)
## mydata$Group
## 0.7357843
interpret_eta_squared(0.54, rules = "cohen1992")
## [1] "large"
## (Rules: cohen1992)
#Since the variances in the groups are diffrerent, we will use Welch-F.test
library(onewaytests)
##
## Attaching package: 'onewaytests'
## The following object is masked from 'package:psych':
##
## describe
welch.test(Productivity.Level~Group, data = mydata)
##
## Welch's Heteroscedastic F Test (alpha = 0.05)
## -------------------------------------------------------------
## data : Productivity.Level and Group
##
## statistic : 181.6941
## num df : 2
## denom df : 96.82658
## p.value : 1.682083e-33
##
## Result : Difference is statistically significant.
## -------------------------------------------------------------
#Ho the mean between the groups are different. Since the p-value<0.05, we can state that the means between groups differ
pairwise.t.test(x=mydata$Productivity.Level, g = mydata$Group, p.adj = "none")
##
## Pairwise comparisons using t tests with pooled SD
##
## data: mydata$Productivity.Level and mydata$Group
##
## No break 15 minutes Break
## 15 minutes Break 9.9e-16 -
## 30 minutes break < 2e-16 < 2e-16
##
## P value adjustment method: none
pairwise.t.test(x=mydata$Productivity.Level, g = mydata$Group, p.adj = "bonf")
##
## Pairwise comparisons using t tests with pooled SD
##
## data: mydata$Productivity.Level and mydata$Group
##
## No break 15 minutes Break
## 15 minutes Break 3e-15 -
## 30 minutes break <2e-16 <2e-16
##
## P value adjustment method: bonferroni
#Ho the mean between the groups are different. Since the p-value<0.05, we can state that the means between groups differ
summary(ANOVA_results)
## Df Sum Sq Mean Sq F value Pr(>F)
## mydata$Group 2 10712 5356 204.7 <2e-16 ***
## Residuals 147 3847 26
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#The relationship between the productivity levels and the fact, if there was a break, or it was whether 15 or 30 minutes. F=204.7; p-value<-0.05; #The effect size is large, n= 0.54