Author: Yaren Yılmaz
Does gender of employees have an effect on the salary they earn?
My purpose is to investigate whether there is a difference in the amount of salary between male and female employees. Therefore, my research hypotheses are as follows:
#Importing data by reading the csv file with the headers which is separated by comma and has no numbers with decimals
mydata <- read.table("./salary.csv",
header = TRUE,
sep = ",")
#Displaying the first 6 rows of the data
head(mydata)
## Education Experience Location Job_Title Age Gender Salary
## 1 High School 8 Urban Manager 63 Male 84620.05
## 2 PhD 11 Suburban Director 59 Male 142591.26
## 3 Bachelor 28 Suburban Manager 61 Female 97800.26
## 4 High School 29 Rural Director 45 Male 96834.67
## 5 PhD 25 Urban Analyst 26 Female 132157.79
## 6 PhD 19 Rural Director 27 Female 156312.94
Definition of the variables:
Education: The highest level of education attained by the employee. Options include ‘High School’, ‘Bachelor’, ‘Master’, and ‘PhD’. Categorical.
Experience: The number of years of professional experience of the employee. Numerical.
Location: The geographical location of employment, categorized as ‘Urban’, ‘Suburban’, or ‘Rural’. Categorical.
Job_Title: The job title or position held by the employee, with options such as ‘Engineer’, ‘Manager’, ‘Analyst’, and ‘Director’. Categorical.
Age: The age of the employee. Numerical.
Gender: The gender of the employee, categorized as ‘Male’ or ‘Female’. Categorical. (This is one of the variables needed to answer the research question.)
Salary: The annual salary of the employee. Currency is not indicated in the source. Numerical. (This is the other variable needed to answer the research question.)
The data set is obtained from https://www.kaggle.com/. Here is the direct link to the web page from which the data is obtained: https://www.kaggle.com/datasets/mrsimple07/salary-prediction-data.
#First, I will convert the variable Gender to a factor since I will need it for my research question.
mydata$GenderF <- factor(mydata$Gender,
levels = c("Male","Female"),
labels = c("Male","Female"))
#Then, I can display descriptive statistics for the variables that I will need for the research of interest. Therefore, I will only include seventh and eighth columns.
summary(mydata[ ,c(7,8)])
## Salary GenderF
## Min. : 33511 Male :516
## 1st Qu.: 85032 Female:484
## Median :104315
## Mean :105558
## 3rd Qu.:126804
## Max. :193017
#Descriptive statistics by group
library(psych)
describeBy(mydata$Salary, mydata$GenderF)
##
## Descriptive statistics by group
## group: Male
## vars n mean sd median trimmed mad min max
## X1 1 516 106329 28795.87 105174.8 106049.4 31261.94 33510.51 186452.9
## range skew kurtosis se
## X1 152942.3 0.1 -0.61 1267.67
## ------------------------------------------------------------
## group: Female
## vars n mean sd median trimmed mad min max
## X1 1 484 104736.8 27676.99 103702.1 104412.2 29617.05 37185.88 193016.6
## range skew kurtosis se
## X1 155830.7 0.1 -0.58 1258.05
I am going to use independent samples t-test if the assumptions are met because there are two different groups (male employees and female employees) that need to be analyzed. Data (salary) comes from two different groups and is measured once.
Assumptions of the independent samples t-test are as follows:
The data must come from two independent populations: This assumption is met as explained in section 3.1 above.
Variable should be numeric: The key variable that I am interested in is salary and it is numeric. So, the assumption is met.
The distribution of the variable should be normal in both populations: This needs to be checked (please see below) to see whether salary is normally distributed for both male and female employees.
Variable should have the same variance in both populations: Salary does not have the same variance in male and female employees as it can be seen in the section 2.4. Therefore, this assumption is not met. However, this is not a problem since the independent samples t-test includes Welch correction.
Normality Check (assumption c):
library(ggplot2)
##
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
##
## %+%, alpha
MaleEmployee <- ggplot(mydata[mydata$GenderF == "Male", ], aes(x = Salary)) +
theme_linedraw() +
geom_histogram() +
ggtitle("Male")
FemaleEmployee <- ggplot(mydata[mydata$GenderF == "Female", ], aes(x = Salary)) +
theme_linedraw() +
geom_histogram() +
ggtitle("Female")
library(ggpubr)
ggarrange(MaleEmployee, FemaleEmployee,
ncol = 2, nrow = 1)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Since the sample is so large, I use histograms to decide about normality rather than using Shapiro-Wilk Normality Test. Histograms show normal distribution of salary in both male and female employees. So, assumption c is met.
Because all the assumptions except d are satisfied I am going to use the parametric test, which is independent samples t-test. The test will apply Welch correction for the violation of assumption d.
Independent samples t-test:
t.test(mydata$Salary ~ mydata$GenderF,
paired = FALSE,
var.equal = FALSE,
alternative = "two.sided")
##
## Welch Two Sample t-test
##
## data: mydata$Salary by mydata$GenderF
## t = 0.89151, df = 997.4, p-value = 0.3729
## alternative hypothesis: true difference in means between group Male and group Female is not equal to 0
## 95 percent confidence interval:
## -1912.468 5096.879
## sample estimates:
## mean in group Male mean in group Female
## 106329.0 104736.8
Since p = 0.3729 > 0.05, we fail to reject H0 at p = 0.373. This means that we cannot reject that mean of the salary of male employees is the same as the mean of the salary of female employees.
library(effectsize)
##
## Attaching package: 'effectsize'
## The following object is masked from 'package:psych':
##
## phi
effectsize::cohens_d(mydata$Salary ~ mydata$GenderF,
pooled_sd = FALSE)
## Cohen's d | 95% CI
## -------------------------
## 0.06 | [-0.07, 0.18]
##
## - Estimated using un-pooled SD.
Interpretation:
interpret_cohens_d(0.06, rules = "sawilowsky2009")
## [1] "tiny"
## (Rules: sawilowsky2009)
The number Cohen’s d = 0.06 shows that the effect size is tiny.
Based on the sample data, we are unable to prove that the average annual salary differs between male and female employees (the effect size is tiny, d = 0.06.). This means that we cannot claim that gender has an affect on salary.