#INRTODUCTION: The teachers salary and years of experience data set I selected was of interest because my wife works for the UFT. The column headers required were not very helpful and required renaming. Also, some rows contained data that was not useful or relevant and that needed to be changed to NAs. I believe it would help to see a visual analysis of the salaries when compared to the the average salary.
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.1.3
## -- Attaching packages --------------------------------------- tidyverse 1.3.2 --
## v ggplot2 3.3.6 v purrr 1.0.1
## v tibble 3.1.8 v dplyr 1.0.10
## v tidyr 1.3.0 v stringr 1.5.0
## v readr 2.1.2 v forcats 0.5.2
## Warning: package 'ggplot2' was built under R version 4.1.3
## Warning: package 'tibble' was built under R version 4.1.3
## Warning: package 'tidyr' was built under R version 4.1.3
## Warning: package 'readr' was built under R version 4.1.3
## Warning: package 'purrr' was built under R version 4.1.3
## Warning: package 'dplyr' was built under R version 4.1.3
## Warning: package 'stringr' was built under R version 4.1.3
## Warning: package 'forcats' was built under R version 4.1.3
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(ggplot2)
Reading in the salary data.
salary_data = read.csv("Teacher_Salary_Data.csv")
str(salary_data)
## 'data.frame': 30734 obs. of 9 variables:
## $ NCESSCH : num 4e+10 4e+10 4e+10 4e+10 4e+10 ...
## $ PCT_BACH: num 51.6 70.8 56.8 48.6 52.8 35 53.3 60 58.3 65.8 ...
## $ PCT_ADVC: num 48.4 29.2 43.2 51.4 47.2 65 46.7 40 41.7 34.2 ...
## $ P_EXPLT6: num 41.9 12.5 43.2 23 33.3 22.5 53.3 53.3 19.4 52.6 ...
## $ P_EXPGT5: num 58.1 87.5 56.8 77 66.7 77.5 46.7 46.7 80.6 47.4 ...
## $ MEAN_EXP: int 9 12 8 11 8 10 7 6 11 8 ...
## $ M_BSALT6: int 37223 36300 36419 36898 38584 40447 37587 37688 32787 33500 ...
## $ M_BSAGT5: int 47784 49764 46909 49443 45746 45870 44821 43221 41512 42286 ...
## $ M_BSAL : int 43355 48081 42373 46561 43359 44650 40963 40270 39815 37662 ...
Data cleaning. Turning all -1 and -2 into NAs.
salary_data = salary_data %>% mutate_all(~na_if(.,-1))
salary_data = salary_data %>% mutate_all(~na_if(.,-2))
Changing the column title to better represent the data.
salary_data = salary_data %>% rename(School_ID_Number = NCESSCH, Percent_BA_Degree = PCT_BACH, Percent_Advanced_Degree = PCT_ADVC, Proportion_Under_6_Yrs_Exp = P_EXPLT6, Proportion_Over_5_Yrs_Exp = P_EXPGT5, Mean_Yrs_Exp = MEAN_EXP, Mean_Salary_Under_6_Yrs_Exp = M_BSALT6, Mean_Salary_Over_5_Yrs_Exp = M_BSAGT5, Mean_Baseline_Salary = M_BSAL)
head(salary_data)
## School_ID_Number Percent_BA_Degree Percent_Advanced_Degree
## 1 40000100120 51.6 48.4
## 2 40000100616 70.8 29.2
## 3 40000101203 56.8 43.2
## 4 40000101204 48.6 51.4
## 5 40000101871 52.8 47.2
## 6 40000101872 35.0 65.0
## Proportion_Under_6_Yrs_Exp Proportion_Over_5_Yrs_Exp Mean_Yrs_Exp
## 1 41.9 58.1 9
## 2 12.5 87.5 12
## 3 43.2 56.8 8
## 4 23.0 77.0 11
## 5 33.3 66.7 8
## 6 22.5 77.5 10
## Mean_Salary_Under_6_Yrs_Exp Mean_Salary_Over_5_Yrs_Exp Mean_Baseline_Salary
## 1 37223 47784 43355
## 2 36300 49764 48081
## 3 36419 46909 42373
## 4 36898 49443 46561
## 5 38584 45746 43359
## 6 40447 45870 44650
To analyze if there is a relationship between mean salary and years of experience.
ggplot(salary_data, aes(x = Mean_Yrs_Exp, y = Mean_Baseline_Salary)) +
geom_point() +
geom_smooth(method = "lm") +
ylab("Mean Baseline Salary USD") +
xlab("Mean Years of Experience")
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 1421 rows containing non-finite values (stat_smooth).
## Warning: Removed 1421 rows containing missing values (geom_point).
#CONCLUSION As expected there is a positive linear relationship between years of experience and average baseline salary.When organized and cleaned the data tell story that is easily readable and a relationship is easily identified.