generated from jtr13/quarto-edav-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata.qmd
247 lines (175 loc) · 8.04 KB
/
data.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# Data
All data was obtained from the Wall Street Journal based on data from Payscale, Inc
## Description
1. degrees-that-pay-back.csv
This file contains median salary data (starting, mid-career, percentiles) for various undergraduate majors such as Engineering, Business, Liberal Arts, Healthcare, etc. Useful for seeing salary trajectories and ranges for different majors.
2. salaries-by-college-type.csv
This file shows median salaries (starting and mid-career) grouped by college type - Engineering colleges, Liberal Arts colleges, Ivy League schools, etc. Gives salary outcomes based on college types rather than majors specifically.
3. salaries-by-region.csv
This file aggregates salaries by region - West, Midwest, Northeast, South. Shows range of salaries for graduates from schools in different geographic areas. Helps compare regional salary differences.
### Format:
- Data is structured as CSV files with header rows naming each column, and subsequent rows containing the data values
- There is a mix of text and numeric data in columns
- Varying number of columns across the files (13-16 columns)
### Dimensions:
- degrees-that-pay-back.csv: 32 rows x 16 columns
- salaries-by-college-type.csv: 130 rows x 12 columns
- salaries-by-region.csv: 344 rows x 12 columns
### Issues:
- Some inconsistent formatting (e.g. school names sometimes abbreviated, use of "---" instead of "N/A")
- Salary columns contain string values with "\$" and "," formatting rather than standardized numeric values
- It is not clear what year(s) the salary data represents
## Missing value analysis
We took a look at the % of missing values per column in each table (all the code is below the analysis points):
1. degrees-that-pay-back.csv:
- No missing values
2. salaries-by-college-type.csv:
- Mid-Career 10th Percentile Salary: approx 14% missing
- Mid-Career 90th Percentile Salary: approx 26% missing
- Other columns are complete
3. salaries-by-region.csv:
- Mid-Career 10th Percentile Salary: approx 14% missing
- Mid-Career 90th Percentile Salary: approx 14% missing
- Other columns are complete
So the main missing data is related to the salary range percentiles in some cases. We could consider dropping those columns or trying imputation methods to fill them in for analysis.
## CODE:
```{r}
# install.packages(c('viridis', 'tidyverse', 'reshape2'))
```
```{r}
degrees_that_pay_back <- read.csv("data//raw_data//degrees-that-pay-back.csv")
salaries_by_college_type <- read.csv("data//raw_data//salaries-by-college-type.csv")
salaries_by_region <- read.csv("data//raw_data//salaries-by-region.csv")
```
### Exploring the data
#### Table : degrees_that_pay_back
```{r}
for (col in colnames(degrees_that_pay_back)){
print(col)
}
```
```{r}
head(degrees_that_pay_back,5)
```
#### Table : salaries_by_college_type
```{r}
for (col in colnames(salaries_by_college_type)){
print(col)
}
```
```{r}
head(salaries_by_college_type,5)
```
#### Table : salaries_by_region
```{r}
for (col in colnames(salaries_by_region)){
print(col)
}
```
```{r}
head(salaries_by_region,5)
```
### Missing Value Analysis
```{r}
cat("For degrees_that_pay_back:", "\n", "\n")
degrees_missing <- sapply(degrees_that_pay_back, function(x) {
mean(x == "N/A") * 100
})
print(degrees_missing)
```
```{r}
cat("For salaries_by_college_type:", "\n", "\n")
college_missing <- sapply(salaries_by_college_type, function(x) {
mean(x == "N/A") * 100
})
print(college_missing)
```
```{r}
cat("For salaries_by_region:", "\n", "\n")
region_missing <- sapply(salaries_by_region, function(x) {
mean(x == "N/A") * 100
})
print(region_missing)
```
```{r}
library(tidyverse)
# Replacing "N/A" with NA in the entire data frame
degrees_that_pay_back <- degrees_that_pay_back %>% mutate_all(~ ifelse(. == "N/A", NA, .))
salaries_by_college_type <- salaries_by_college_type %>% mutate_all(~ ifelse(. == "N/A", NA, .))
salaries_by_region <- salaries_by_region %>% mutate_all(~ ifelse(. == "N/A", NA, .))
missing_percentage_degrees_that_pay_back <- colMeans(is.na(degrees_that_pay_back)) * 100
missing_percentage_salaries_by_college_type <- colMeans(is.na(salaries_by_college_type)) * 100
missing_percentage_salaries_by_region <- colMeans(is.na(salaries_by_region)) * 100
df_degrees_that_pay_back <- data.frame(Column = names(degrees_that_pay_back), Missing_Percentage = missing_percentage_degrees_that_pay_back)
df_salaries_by_college_type <- data.frame(Column = names(salaries_by_college_type), Missing_Percentage = missing_percentage_salaries_by_college_type)
df_salaries_by_region <- data.frame(Column = names(salaries_by_region), Missing_Percentage = missing_percentage_salaries_by_region)
combined_df <- bind_rows(
mutate(df_degrees_that_pay_back, File = "degrees_that_pay_back"),
mutate(df_salaries_by_college_type, File = "File 2"),
mutate(df_salaries_by_region, File = "File 3")
)
ggplot(combined_df, aes(x = Column, y = Missing_Percentage, fill = File)) +
geom_bar(stat = "identity", position = "dodge") +
labs(title = "Percentage of Missing Values in Each Column",
x = "Column",
y = "Missing Percentage") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
```
```{r}
library(tidyverse)
library(viridis)
library(tidyverse)
library(reshape2)
# Define function to load CSV files with 'N/A' as missing values
df1 <- read.csv("data//raw_data//salaries-by-college-type.csv", na.strings = "N/A")
df2 <- read.csv("data//raw_data//salaries-by-region.csv", na.strings = "N/A")
# Function to plot missing values
plot_missing_values <- function(df, title) {
df %>%
is.na() %>%
melt() %>%
ggplot(aes(x = Var2, y = Var1, fill = factor(value, labels = c("Present", "Missing")))) +
geom_tile(color = "white") +
scale_fill_manual(values = c("Present" = "Green", "Missing" = "Red")) +
labs(title = title, x = "Columns", y = "Rows") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))+
guides(fill = guide_legend(title = "Values"))
}
# Plot missing values for each column in the first CSV file
plot_missing_values(df1, "Missing Values in File 1")
# Plot missing values for each column in the second CSV file
plot_missing_values(df2, "Missing Values in File 2")
```
#### Observations from the graph
In both the tables, the missing values of both columns are occuring in the same rows.
## Cleaning up data and saving the cleaned csv files
```{r}
degrees_that_pay_back <- read.csv("data//raw_data//degrees-that-pay-back.csv")
salaries_by_college_type <- read.csv("data//raw_data//salaries-by-college-type.csv")
salaries_by_region <- read.csv("data//raw_data//salaries-by-region.csv")
```
```{r}
salaries_col <- salaries_by_college_type
salaries_col <- na.omit(salaries_col)
salaries_reg <- salaries_by_region
salaries_reg <- na.omit(salaries_reg)
degrees <- degrees_that_pay_back
degrees <- na.omit(degrees)
```
```{r}
# install.packages("dplyr")
library(dplyr)
# Converting character strings to numbers for plotting
salaries_col <- salaries_col %>%
mutate_at(vars(Mid.Career.Median.Salary, Mid.Career.10th.Percentile.Salary, Mid.Career.25th.Percentile.Salary, Mid.Career.75th.Percentile.Salary, Mid.Career.90th.Percentile.Salary, Starting.Median.Salary), function(x) as.numeric(gsub("[\\$,]", "", x)))
salaries_reg <- salaries_reg %>%
mutate_at(vars(Mid.Career.Median.Salary, Mid.Career.10th.Percentile.Salary, Mid.Career.25th.Percentile.Salary, Mid.Career.75th.Percentile.Salary, Mid.Career.90th.Percentile.Salary, Starting.Median.Salary), function(x) as.numeric(gsub("[\\$,]", "", x)))
degrees <- degrees %>%
mutate_at(vars(Mid.Career.Median.Salary, Mid.Career.10th.Percentile.Salary, Mid.Career.25th.Percentile.Salary, Mid.Career.75th.Percentile.Salary, Mid.Career.90th.Percentile.Salary, Starting.Median.Salary), function(x) as.numeric(gsub("[\\$,]", "", x)))
```
```{r}
write.csv(degrees, "data//cleaned_data//degrees-that-pay-back-cleaned.csv", row.names = FALSE)
write.csv(salaries_col, "data//cleaned_data//salaries-by-college-type-cleaned.csv", row.names = FALSE)
write.csv(salaries_reg, "data//cleaned_data//salaries-by-region-cleaned.csv", row.names = FALSE)
```