Author: Yaren Yılmaz


1 Research question

1.1 My research question that can be tested statistically:

Does gender of employees have an effect on the salary they earn?

1.2 The variables that need to be collected to answer my research question:
  • gender
  • salary
1.3 The research hypotheses:

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:

  • H0 (Null Hypothesis): \(\mu_M\) = \(\mu_F\) (Mean of the salary of male employees is the same as the mean of the salary of female employees.)
  • H1 (Alternative Hypothesis): \(\mu_M\) ≠ \(\mu_F\) (Mean of the salary of male employees is not the same as the mean of the salary of female employees.)

2 Data (2.5 points)

2.1 Import of the data, presentation of the data using a function head, definition of the variables used:
#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.)

2.2 Definition of the unit of observation and the sample size:
  • the unit of observation: one employee
  • the sample size: 1000
2.3 Source of the data set:

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.

2.4 Basic descriptive statistics and explanation:
#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
  • There are 516 male and 484 female employees in the sample.
  • The lowest annual salary of employees is 33511 while the highest annual salary is 193017.
  • 50% of the employees have an annual salary of 104315 or less while the other half have an annual salary of more than 104315.
  • The average annual salary of an employee is 105558.
#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
  • Average annual salary of a male employee is 106329 while a female employee has an annual salary of 104736.8 on average.
  • A male employee has 1592.2 higher annual salary on average, in comparison to a female employee.
  • The variance of salary in male employees is (28795.87 )2 = 829202129 while it is (27676.99)2 = 766015775 in female employees.

3 Analysis

3.1 Determining which statistical test to use and why:

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.

3.2 Evaluation of all assumptions:

Assumptions of the independent samples t-test are as follows:

  1. The data must come from two independent populations: This assumption is met as explained in section 3.1 above.

  2. Variable should be numeric: The key variable that I am interested in is salary and it is numeric. So, the assumption is met.

  3. 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.

  4. 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):

  • Using histogram:
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.

3.3 Appropriate statistical test based on the results of the assumption evaluation and its interpretation

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.

3.4 Calculation of the effect size and its interpretation:
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.

4 Conclusion

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.