Packages Used

library(tidyr)
library(psych)
library(ggplot2)
## 
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
## 
##     %+%, alpha
library(rstatix)
## 
## Attaching package: 'rstatix'
## The following object is masked from 'package:stats':
## 
##     filter
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

Research Question:

Is there a difference in salaries between male and female employees?

The variables needed to be collected are data on gender of employees and corresponding salary to those employees

Importing data and explaining variables

SalaryData <- read.csv("Salary_Data.csv", header = TRUE)

head(SalaryData)
##   Age Gender Education.Level         Job.Title Years.of.Experience Salary
## 1  32   Male      Bachelor's Software Engineer                   5  90000
## 2  28 Female        Master's      Data Analyst                   3  65000
## 3  45   Male             PhD    Senior Manager                  15 150000
## 4  36 Female      Bachelor's   Sales Associate                   7  60000
## 5  52   Male        Master's          Director                  20 200000
## 6  29   Male      Bachelor's Marketing Analyst                   2  55000

We have these variables for a sample size of 6685

Source: Kaggle

Carrying out data manipulation

SalaryData$GenderFactor <- factor(SalaryData$Gender, levels = c("Male", "Female"))
# Thought to factor gender like this for the levels as "Male" and "Female" because they were coded as Male and Female in the dataset rather than 0 and 1

SalaryData <- drop_na(SalaryData)

Assessing whether assumptions are met

The assumptions are the variable is numeric and the variable on population is normally distributed

#We must check for normality

describeBy(SalaryData$Salary, g = SalaryData$GenderFactor)
## 
##  Descriptive statistics by group 
## group: Male
##    vars    n     mean       sd median  trimmed     mad min    max  range skew
## X1    1 3672 121389.9 52092.73 120000 121691.5 71164.8 350 250000 249650    0
##    kurtosis     se
## X1     -1.2 859.66
## ------------------------------------------------------------ 
## group: Female
##    vars    n   mean       sd median  trimmed   mad min    max  range skew
## X1    1 3013 107889 52723.61 105000 106776.6 66717 500 220000 219500 0.15
##    kurtosis     se
## X1    -1.13 960.52

Explaining some descriptive statistics

-n: It is the number of observations in both groups for male there are 3672 observations for female 3013.

-Mean: It means the average salary for our individuals for male it is 121389.9INR for female it is 107889INR.

-Median: It means 50% of the observations lie before and including the median and 50% after and including the median, 120000 for males 105000 for females.

-SD : Is the standard deviation of our observations which is a measure of the spread of the data around the mean, 52092.73 for males and 52723.61 for females.

Also looking at the descriptive statistics we can obtain that our variable Salary is numeric

Graphical Assessment

library(ggplot2)
ggplot(SalaryData, aes(x = Salary)) +
  geom_histogram(binwidth = 20000, colour="blue") +
  facet_wrap(~GenderFactor, ncol = 1) + 
  ylab("Frequency")

Shapiro-Wilk Test for Normality

SalaryData %>%
  group_by(GenderFactor) %>%
  shapiro_test(Salary)
## # A tibble: 2 × 4
##   GenderFactor variable statistic        p
##   <fct>        <chr>        <dbl>    <dbl>
## 1 Male         Salary       0.956 4.95e-32
## 2 Female       Salary       0.957 4.19e-29
#H0: The variable Salary is distributed normally
#H1: The variable Salary is not distributed normally

Using Wilcoxon Rank Sum Test

We Use a non parametric test as the normality assumption is violated and we are testing differences between two independent groups (male and female)

wilcox.test(SalaryData$Salary ~ SalaryData$GenderFactor,
            paired = FALSE,
            correct = FALSE,
            exact = FALSE,
            alternative = "two.sided")
## 
##  Wilcoxon rank sum test
## 
## data:  SalaryData$Salary by SalaryData$GenderFactor
## W = 6339557, p-value < 2.2e-16
## alternative hypothesis: true location shift is not equal to 0
#H0: True location shift is equal to 0
#H1: True location shift is not equal to 0

Calculating and interpreting effect size

library(effectsize)
effectsize(wilcox.test(SalaryData$Salary ~ SalaryData$GenderFactor,
                       paired = FALSE,
                       correct = FALSE,
                       exact = FALSE,
                       alternative = "two.sided"))
## r (rank biserial) |       95% CI
## --------------------------------
## 0.15              | [0.12, 0.17]
interpret_rank_biserial(0.15)
## [1] "small"
## (Rules: funder2019)

Conclusion: Based on the sample data we find that male and female employees differ in the salary they are paid (p<0.001) - men get paid more on average than women the difference in distribution is small.