- We will analyze how compensation of roles varies between roles in the industry of data science
- How experience level affects the compensation
- Are certain roles more high-paying than others?
- Use different statistical methods to analyze the differences
- Data-set is sourced from Kaggle, give a comprehensive record of salary, experience level, and employment type (vast majority is full-time)
Statistical Methods (Pt. 1)
- First, we separate the data-set by experience and group them by job title
- Mean \(\bar{x}\): Captures the overall compensation level per job title and allows us to compare job titles to one another
- Median \(M\): Give the midpoint of salaries by job title; useful when there are few observations per job title -> results in skewed mean \[ \bar{x} = \frac{\sum x}{n} \] \[ \text{$\sum$ x: sum of all data point} \] \[ \text{n: total number of data points} \] \[ \text{M = } (\frac{n+1}{2}) \text{th term; if n is odd} \] \[ \text{Median} = \frac{\left(\frac{n}{2}\right)^{\text{th}} \text{ term} + \left(\frac{n}{2} + 1\right)^{\text{th}} \text{ term}}{2} \text{; if n is even} \]
Statistical Methods (Pt. 2)
- Standard Deviation (σ): Statistical measure that shows how much the data points are spread out from average (mean)
- Standard Error: measures precision of a sample statistic (mean, median, etc)
- Confidence Interval: uses standard error to build a range of plausible values from mean to account for unknown variables \[ \sigma = \sqrt{\frac{\sum_{i=1}^{n} (x_i - \bar{x})^2}{n-1}} \] \[ \text{SE = } \frac{\sigma}{\sqrt{n}} \] \[ \text{CI = } \bar{x} \pm z^* (\text{SE}) \] \[ \Rightarrow \bar{x} \pm z^* \frac{\sigma}{\sqrt{n}} \] \[ \text{where $z^*$ is the critical value (1.96 for 95% confidence)} \]
Density Plot of Compensation vs. Experience Level
- What is it: shows the distribution of a continuous variable rather than binning in into columns like a histogram; total area under a curve is equal to 1
- Purpose: Allows us to see skewness in the distribution of a data-set; also ideal when comparing multiple data-sets and comparing them side-by-side
CI Function
- Formula: We are using the formulas shown earlier to calculate the error in the data-points plotted; you can think of this as a range of salaries.
ci_function <- function(dataset) {
dataset |>
group_by(job_title) |>
filter(n() >= 10) |>
summarize(
# calculating mean, standard deviation
in_profession = n(),
mean_salary = mean(salary_in_usd),
salary_standard_deviation = sd(salary_in_usd),
# standard error
standard_error = salary_standard_deviation / sqrt(in_profession),
# 95% critical t-value
t_crit = qt(0.975, df = in_profession - 1),
# Error Margin
error_margin = t_crit * standard_error,
# Bounds
lower_bound = mean_salary - error_margin,
upper_bound = mean_salary + error_margin
) |>
arrange(desc(mean_salary))
}
entry_ci <- ci_function(entry_level_USA)
medium_ci <- ci_function(mid_level_USA)
senior_ci <- ci_function(senior_level_USA)
Plotting Confidence Intervals
- We plot three different plots based on experience level, filter out job titles that have less than 10 observations in them, and plot Avg. Salary vs. Job Title, with the lines considered as the range of salary for the respective job -Entry Level:
Plotting Confidence Intervals
-Mid-Level:
Plotting Confidence Intervals
-Senior Level:
Code for CI PLots
# Plotting with Confidence Interval (95%)
plotting_CIs <- function(dataset, level) {
top_20_jobs <- dataset |>
slice_max(mean_salary, n = 20)
plot <- ggplot(
data = top_20_jobs,
aes(
x = mean_salary,
y = reorder(job_title, desc(mean_salary)),
text = paste0(
"<b>Job Title: </b>", job_title,
"<br><b>Avg. Salary: </b>$", scales::comma(round(mean_salary, 2)),
"<br><b>95% CI: </b>[$", scales::comma(round(lower_bound, 2)),
" - $", scales::comma(round(upper_bound, 2)), "]",
"<br><b>Number in Job: </b>", in_profession
)
)
) +
geom_errorbar(
aes(xmin = lower_bound, xmax = upper_bound),
orientation = "y",
height = 0.5,
color = "tomato"
) +
scale_x_continuous(labels = scales::label_comma(prefix = "$")) +
geom_point(color = "forestgreen", size = 2, shape = 17) +
labs(
title = paste("Top 20 Avg. Salaries (95% Confidence)", level, sep = ": "),
x = "Average Salary (USD)",
y = "Job Title"
)
ggplotly(plot, tooltip = "text")
}
plotting_CIs(entry_ci, "Entry Level")
plotting_CIs(medium_ci, "Mid-Level")
plotting_CIs(senior_ci, "Senior Level")
Conclusion & Key Takeaways
- Clear Career Trajectory: Analysis of the Kaggle data-set reveals that there is a quantifiable increase in compensation as experience level increases
- Statistical Confidence: 95%, the range of the salaries can reliably take into account unknown factors that are not too impactful to the observations
- Final Thought: This analysis gave us a small glimpse of what it is like to be a data scientists and some of the various techniques that are utilized to analyze data effectively
- THANK YOU!