-
Notifications
You must be signed in to change notification settings - Fork 0
/
final_analysis.html
348 lines (322 loc) · 20.8 KB
/
final_analysis.html
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="quarto-1.3.450">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<meta name="author" content="Putra Farrel Azhar, Lauryn Edwards, Meilin Chen, Yanji Wang">
<meta name="dcterms.date" content="2024-03-18">
<title>Analyzing Labor Action Events: Predicting Strike Outcomes with R and Tidymodels</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
ul.task-list li input[type="checkbox"] {
width: 0.8em;
margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
vertical-align: middle;
}
</style>
<script src="final_analysis_files/libs/clipboard/clipboard.min.js"></script>
<script src="final_analysis_files/libs/quarto-html/quarto.js"></script>
<script src="final_analysis_files/libs/quarto-html/popper.min.js"></script>
<script src="final_analysis_files/libs/quarto-html/tippy.umd.min.js"></script>
<script src="final_analysis_files/libs/quarto-html/anchor.min.js"></script>
<link href="final_analysis_files/libs/quarto-html/tippy.css" rel="stylesheet">
<link href="final_analysis_files/libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="final_analysis_files/libs/bootstrap/bootstrap.min.js"></script>
<link href="final_analysis_files/libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="final_analysis_files/libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light">
</head>
<body class="fullcontent">
<div id="quarto-content" class="page-columns page-rows-contents page-layout-article">
<main class="content" id="quarto-document-content">
<header id="title-block-header" class="quarto-title-block default">
<div class="quarto-title">
<h1 class="title">Analyzing Labor Action Events: Predicting Strike Outcomes with R and Tidymodels</h1>
<p class="subtitle lead">GPIM 452 - Group 1</p>
</div>
<div class="quarto-title-meta">
<div>
<div class="quarto-title-meta-heading">Author</div>
<div class="quarto-title-meta-contents">
<p>Putra Farrel Azhar, Lauryn Edwards, Meilin Chen, Yanji Wang </p>
</div>
</div>
<div>
<div class="quarto-title-meta-heading">Published</div>
<div class="quarto-title-meta-contents">
<p class="date">March 18, 2024</p>
</div>
</div>
</div>
</header>
<section id="introduction" class="level2">
<h2 class="anchored" data-anchor-id="introduction">1. Introduction</h2>
<p>The topic chosen by our group is the prediction of a labor action, whether it is a strike or a non-strike. After carefully considering and evaluating various options to find the most suitable approach for predicting strike or non-strike labor behavior, we decided on the LASSO logistics model as our prediction model. According to our analysis, the LASSO logistics model we chose exhibited impressive performance on the training set, achieving an accuracy rate of 92.79% and a ROC AUC of 96.74%. This indicated its ability to classify between strike and non-strike events effectively. Ultimately, testing on the latest data showed a maintained accuracy rate of 88.13%. The following part of this report will mainly focus on how we deal with the data, run different models, and evaluate their performance.</p>
</section>
<section id="data" class="level2">
<h2 class="anchored" data-anchor-id="data">2. Data</h2>
<p>In addition to the provided labor action data dataset (LAT), we incorporated the American Community Survey (ACS) data to enrich our analysis. This supplementary dataset offers valuable demographic and socio-economic information that can provide deeper insights into the factors influencing labor actions.To enhance the compatibility of the dataset, our team implemented various adjustments. We first filtered and cleaned the LAT dataset, keeping only labor actions with a single location and extracting longitude and latitude information. Next, we downloaded the shapefile for U.S. county boundaries and converted it to our dataset’s coordinate reference system. By spatially joining the dataset with the county boundary data, we associated each labor action with its respective county, facilitating the merge with ACS data to generate a dataset with the units of observations being counties.Next, we create a binary variable that shows whether the labor action is a Strike. Based on the value of the “strike_or_non-strike” column, if it is “Strike,” then the binary variable is set to 1. Then, for those observations with various measurement units, such as the labor action duration unit, which varies from days to seconds, we standardized the unit and transferred all the observations into a single unit measured. In terms of data cleansing and modifying, we standardized names and dates to ensure consistency and accuracy of datasets. We removed white space to improve the readability and cleanliness of the data. We identified and eliminated redundant columns that do not contribute significantly to our predictive model. We preserved only the first value for variables containing multiple values, simplifying the data set for analysis. Additionally, given that the LASSO model does not support time variables, we removed all time-related variables to meet the model’s requirements better.</p>
<p>In dealing with missing variables, we adopted different strategies based on the nature of the variables and the number of missing values to maximize data integrity and usability. Firstly, we chose to remove all the columns directly for variables with many missing values and with minimal impact on the model. This approach benefits the model by reducing interference and allowing it to focus on relevant and representative variables. Secondly, we filled in missing values with “Missing” for categorical variables. This step helps maintain the structural integrity of the data, avoiding situations where missing values are ignored or removed during analysis. Lastly, for variables with fewer missing values, we filled them with the median. This method helps preserve the distribution characteristics of the data, preventing data biases caused by missing values and thus improving the accuracy and stability of the model.</p>
</section>
<section id="model" class="level2">
<h2 class="anchored" data-anchor-id="model">3. Model</h2>
<p>Of the three models considered (linear and logistic regression, KNN, and Random Forest), the model that provides the best result and is commonly used to predict binary variables, as in our case of predicting whether a labor event is a strike or a non-strike, is the logistic regression model. On top of using logit, we implemented the LASSO estimator, which provides variable selection and regularization to improve the accuracy and interpretability of the model it creates. Implementing the LASSO estimator in a logistic regression allows for the usage of a penalty value equivalent to the absolute value of the magnitude of the coefficient of the loss function. The higher the penalty value, the more severe the model’s feature selection is, and vice versa for a lower penalty value. Therefore, logistic regression would be especially helpful for binary classification problems, and the LASSO estimator will deduce multiple variables in our recipe and keep only those that are significant.</p>
<p>One of the benefits of LASSO logistics is its ability to perform feature selection. Feature selection within LASSO logistics is when the model analyzes all the variables within the model and determines which variables have the most significant impact on the outcome variable. Feature selection achieves this by shrinking the coefficients related to less important variables to zero, effectively removing irrelevant variables from the model. Given the large number of variables within the Labor Action Tracker data, this feature will be useful here in finding which variables are important in predicting whether an event is a strike. The penalty value was applied to the coefficients in the LASSO logistics model for parameter tuning and tuned through cross-validation. To find the best parameter that would produce a model with the highest accuracy, each penalty value between 0.01 and 2 was tried for the LASSO logistics regression in a 5-fold cross-validation until it found the penalty value that produces the best performance on average from the cross-validation. As evident in the figure, the best penalty tuning value was 0.01, providing a model with a 0.913 accuracy rate.</p>
<div class="cell">
<div class="cell-output-display">
<p><img src="final_analysis_files/figure-html/unnamed-chunk-25-1.png" class="img-fluid" width="672"></p>
</div>
</div>
<p>To evaluate the performance of our LASSO logistics regression model, we used a Confusion Matrix. The Confusion Matrix is useful in estimating the accuracy of the LASSO logistics regression model as it measures how well a model can predict the true strike and non-strike of a predictive model. Given that the goal of this model is to predict whether a labor event is a strike or a non-strike, the performance metric being prioritized was the model’s accuracy rate. After running the Confusion Matrix on the training data, the matrix revealed that the model had an accuracy rate of 0.928, meaning that the model was running with a relatively high accuracy rate. With the initially high accuracy rate on the training data, there were concerns about overfitting. However, the model still performed well when the data was run on the new 2024 LAT dataset. With a slightly lower accuracy rate, the model run on the 2024 LAT dataset had an accuracy rate of 0.881, thus confirming that the model is generalizable overall. Considering the interpretability of LASSO logistics regression, this model is highly interpretable. Through its feature selection method, it can identify and list the predictor variables that have the greatest impact on the outcome variable. The list of predictors and their coefficients is ordered to highlight the most important predictor variables and bring the coefficients of less important variables to 0, making the model easy to interpret.</p>
</section>
<section id="conclusion" class="level2">
<h2 class="anchored" data-anchor-id="conclusion">4. Conclusion</h2>
<p>Given the amount of missing data within the LAT data and the formation of some of the features within the dataset, assumptions about the data that may not be true were created. For instance, the Labor Organization variable had to be removed from consideration for the model because the data entry had several missing value names that indicated the same labor organization—identifying the different types of naming schema proves to be a massive undertaking. To solve this issue, allocating a unique identifier representing a labor organization may have been useful to avoid the problem created by multiple names representing one organization. In addition to missing data, numerous features contained more than one value. There was no information on why these variables were created this way or if there was a purpose for ordering the multiple values. This led our group to assume that the first value holds the most important indicator and remove the rest in order to create the model. If the data had been organized tidier, meaning one cell holds one value, the importance of the variables with multiple values in a cell may have changed the outcome of which variables had the most significant effect that led to a strike vs non-strike.</p>
<div class="cell">
<div class="cell-output-display">
<p><img src="final_analysis_files/figure-html/unnamed-chunk-27-1.png" class="img-fluid" width="672"></p>
</div>
</div>
<p>Accordingly, our model strength determines which features are most important to consider when predicting whether a labor event is a strike or a non-strike. The figure above shows the features that impact the prediction of whether or not an event is a strike versus a non-strike. This information is specifically useful for employers and policymakers as it allows them to look at the features with the greatest effect and use them to implement policies that improve conditions for workers before they feel the need to strike.</p>
</section>
</main>
<!-- /main column -->
<script id="quarto-html-after-body" type="application/javascript">
window.document.addEventListener("DOMContentLoaded", function (event) {
const toggleBodyColorMode = (bsSheetEl) => {
const mode = bsSheetEl.getAttribute("data-mode");
const bodyEl = window.document.querySelector("body");
if (mode === "dark") {
bodyEl.classList.add("quarto-dark");
bodyEl.classList.remove("quarto-light");
} else {
bodyEl.classList.add("quarto-light");
bodyEl.classList.remove("quarto-dark");
}
}
const toggleBodyColorPrimary = () => {
const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
if (bsSheetEl) {
toggleBodyColorMode(bsSheetEl);
}
}
toggleBodyColorPrimary();
const icon = "";
const anchorJS = new window.AnchorJS();
anchorJS.options = {
placement: 'right',
icon: icon
};
anchorJS.add('.anchored');
const isCodeAnnotation = (el) => {
for (const clz of el.classList) {
if (clz.startsWith('code-annotation-')) {
return true;
}
}
return false;
}
const clipboard = new window.ClipboardJS('.code-copy-button', {
text: function(trigger) {
const codeEl = trigger.previousElementSibling.cloneNode(true);
for (const childEl of codeEl.children) {
if (isCodeAnnotation(childEl)) {
childEl.remove();
}
}
return codeEl.innerText;
}
});
clipboard.on('success', function(e) {
// button target
const button = e.trigger;
// don't keep focus
button.blur();
// flash "checked"
button.classList.add('code-copy-button-checked');
var currentTitle = button.getAttribute("title");
button.setAttribute("title", "Copied!");
let tooltip;
if (window.bootstrap) {
button.setAttribute("data-bs-toggle", "tooltip");
button.setAttribute("data-bs-placement", "left");
button.setAttribute("data-bs-title", "Copied!");
tooltip = new bootstrap.Tooltip(button,
{ trigger: "manual",
customClass: "code-copy-button-tooltip",
offset: [0, -8]});
tooltip.show();
}
setTimeout(function() {
if (tooltip) {
tooltip.hide();
button.removeAttribute("data-bs-title");
button.removeAttribute("data-bs-toggle");
button.removeAttribute("data-bs-placement");
}
button.setAttribute("title", currentTitle);
button.classList.remove('code-copy-button-checked');
}, 1000);
// clear code selection
e.clearSelection();
});
function tippyHover(el, contentFn) {
const config = {
allowHTML: true,
content: contentFn,
maxWidth: 500,
delay: 100,
arrow: false,
appendTo: function(el) {
return el.parentElement;
},
interactive: true,
interactiveBorder: 10,
theme: 'quarto',
placement: 'bottom-start'
};
window.tippy(el, config);
}
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
for (var i=0; i<noterefs.length; i++) {
const ref = noterefs[i];
tippyHover(ref, function() {
// use id or data attribute instead here
let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
try { href = new URL(href).hash; } catch {}
const id = href.replace(/^#\/?/, "");
const note = window.document.getElementById(id);
return note.innerHTML;
});
}
let selectedAnnoteEl;
const selectorForAnnotation = ( cell, annotation) => {
let cellAttr = 'data-code-cell="' + cell + '"';
let lineAttr = 'data-code-annotation="' + annotation + '"';
const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
return selector;
}
const selectCodeLines = (annoteEl) => {
const doc = window.document;
const targetCell = annoteEl.getAttribute("data-target-cell");
const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
const lines = annoteSpan.getAttribute("data-code-lines").split(",");
const lineIds = lines.map((line) => {
return targetCell + "-" + line;
})
let top = null;
let height = null;
let parent = null;
if (lineIds.length > 0) {
//compute the position of the single el (top and bottom and make a div)
const el = window.document.getElementById(lineIds[0]);
top = el.offsetTop;
height = el.offsetHeight;
parent = el.parentElement.parentElement;
if (lineIds.length > 1) {
const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
const bottom = lastEl.offsetTop + lastEl.offsetHeight;
height = bottom - top;
}
if (top !== null && height !== null && parent !== null) {
// cook up a div (if necessary) and position it
let div = window.document.getElementById("code-annotation-line-highlight");
if (div === null) {
div = window.document.createElement("div");
div.setAttribute("id", "code-annotation-line-highlight");
div.style.position = 'absolute';
parent.appendChild(div);
}
div.style.top = top - 2 + "px";
div.style.height = height + 4 + "px";
let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
if (gutterDiv === null) {
gutterDiv = window.document.createElement("div");
gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
gutterDiv.style.position = 'absolute';
const codeCell = window.document.getElementById(targetCell);
const gutter = codeCell.querySelector('.code-annotation-gutter');
gutter.appendChild(gutterDiv);
}
gutterDiv.style.top = top - 2 + "px";
gutterDiv.style.height = height + 4 + "px";
}
selectedAnnoteEl = annoteEl;
}
};
const unselectCodeLines = () => {
const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
elementsIds.forEach((elId) => {
const div = window.document.getElementById(elId);
if (div) {
div.remove();
}
});
selectedAnnoteEl = undefined;
};
// Attach click handler to the DT
const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
for (const annoteDlNode of annoteDls) {
annoteDlNode.addEventListener('click', (event) => {
const clickedEl = event.target;
if (clickedEl !== selectedAnnoteEl) {
unselectCodeLines();
const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
if (activeEl) {
activeEl.classList.remove('code-annotation-active');
}
selectCodeLines(clickedEl);
clickedEl.classList.add('code-annotation-active');
} else {
// Unselect the line
unselectCodeLines();
clickedEl.classList.remove('code-annotation-active');
}
});
}
const findCites = (el) => {
const parentEl = el.parentElement;
if (parentEl) {
const cites = parentEl.dataset.cites;
if (cites) {
return {
el,
cites: cites.split(' ')
};
} else {
return findCites(el.parentElement)
}
} else {
return undefined;
}
};
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
for (var i=0; i<bibliorefs.length; i++) {
const ref = bibliorefs[i];
const citeInfo = findCites(ref);
if (citeInfo) {
tippyHover(citeInfo.el, function() {
var popup = window.document.createElement('div');
citeInfo.cites.forEach(function(cite) {
var citeDiv = window.document.createElement('div');
citeDiv.classList.add('hanging-indent');
citeDiv.classList.add('csl-entry');
var biblioDiv = window.document.getElementById('ref-' + cite);
if (biblioDiv) {
citeDiv.innerHTML = biblioDiv.innerHTML;
}
popup.appendChild(citeDiv);
});
return popup.innerHTML;
});
}
}
});
</script>
</div> <!-- /content -->
</body></html>