This repository has been archived by the owner on Oct 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.Rmd
1458 lines (1144 loc) · 40.2 KB
/
main.Rmd
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "ZPER - 2nd Competition (Predict Opening & Closing of Hospitals)"
author: "Ali Ezzat"
date: "September 15, 2018"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
#setwd("~/R/ZPER - 2nd Competition (Predict Opening & Closing of Hospitals)")
```
-------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
## Overview
The data for this competition contains information on 430 hospitals gathered from various data sets, including historical financial statements, geographical (location) information, number of sickbeds, etc., for hospitals in South Korea. The main goal of this competition is to predict closing numbers of given hospitals. More information about this competition (and its dataset) may be found at [this link](http://dacon.io/cpt2/10397).
-------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
## First Look at the Data
We start by loading the necessary packages.
```{r, message=FALSE}
library(tidyverse)
library(ggcorrplot)
```
Next, we load the data from their respective files.
```{r, message=FALSE}
train_dta <- read_csv("data/train.csv", col_names = TRUE, trim_ws = TRUE) # load training data
test_dta <- read_csv("data/test.csv", col_names = TRUE, trim_ws = TRUE) # load testing data
```
Let's inspect the data!
```{r}
# initial look at the data
glimpse(train_dta)
```
On first glance, we observe a number of things:
* A couple of the variables that are parsed as `integer` seem to be binary variables in actuality (i.e. `receivableL1`, `receivableL2`). *Note: This turns out to be incorrect later*.
* Some nomimal textual variables are parsed as `character` (e.g. `ownerChange`, `instkind`). These need to be convert to type `factor`.
* Multiple variables have `NA` values in them.
* The variables, `employee1` and `employee2`, are both numerical variables while, at the same time, they were parsed as type `character`.
The `NA` values problem seems to be the most annoying, so let's start with it. Let's see which variables have NA values in them and how frequently `NA` values occur in them.
```{r}
# show NA-containing variables and how frequently these NAs occur in each
train_dta %>%
map_df(is.na) %>% # turn into an is.na() matrix
select_if(colSums(.) > 0) %>% # get columns whose sum > 0 (i.e. variables which contain at least 1 NA value)
colSums() %>% # how many NA values do these variables contain?
t() %>%
t()
```
44 out of the 58 variables have `NA` values in them. An interesting observation here is that most of them seem to specifically have `8` missing values. Let's try viewing rows that have `NA` values in them to see if they coincide in the same rows.
```{r}
# indices of rows (instances) containing NA values in them
row_indices <-
train_dta %>%
map_df(is.na) %>% # turn into an is.na() matrix
transmute(rowHasNAvalue = rowSums(.) > 0) %>% # create variable indicating whether the row has an NA value
as.matrix() %>% # convert into matrix (for the following 'which' function)
which() # return indices of rows having NA values
# display these row indices
cat('#instances with NA values:', length(row_indices), '\n', row_indices)
```
In the training data, 24 instances (out of 301) that have NA values in them. Let's try viewing them using the `View()` function.
```{r}
train_dta[row_indices,] %>% View('train_data_NA_values')
```
Findings from the inspecting the output of the above command:
* For variables containing *exactly* 8 missing values, they *always* coincide in the same row. That is, there are specifically 8 rows (instances) for which these variables *all* have the NA value.
* For variables containing *exactly* 8 missing values, they *all* belong to hospitals that have an `open` value in the target variable, `OC`. It is not the case that these hospitals are so new that such information is not available yet. Indeed some of these hospitals are quite old (as per the `openDate` variable).
* For the remaining variables (i.e. `bedCount`, `instkind`, `employee1`, `employee2`, `ownerChange`), they are mostly scattered among the remaining 16 rows of `row_indices`.
* `NA` values for `bedCount` *all* exist in hospitals having a `close` value in the target variable, `OC`. The same can be said for the `instkind` variable (which has only a single `NA` value).
Before moving on, let's observe the `NA` values in the test data.
```{r}
# indices of rows (instances) containing NA values in them
row_indices <-
test_dta %>%
select(-OC) %>%
map_df(is.na) %>% # turn into an is.na() matrix
transmute(rowHasNAvalue = rowSums(.) > 0) %>% # create variable indicating whether the row has an NA value
as.matrix() %>% # convert into matrix (for the following 'which' function)
which() # return indices of rows having NA values
# display these row indices
cat('#instances with NA values:', length(row_indices), '\n', row_indices)
```
In the test data, 25 instances (out of 127) have NA values in them. Let's try viewing them using the `View()`
```{r}
test_dta[row_indices,] %>% View('test_data_NA_values')
```
A familiar pattern emerged which is:
The same variables whose `NA` values co-occurred together in the same rows in the training data did so in the test data as well (i.e. the ones that specifically had 8 `NA` values in the training data). These variables are in the columns numbered 8 to 55 (in both the training and test data).
Before moving on, let's convert the types of the variables, `employee1` and `employee2`, as numeric ones.
```{r warning=FALSE}
train_dta$employee1 <- as.numeric(train_dta$employee1)
train_dta$employee2 <- as.numeric(train_dta$employee2)
test_dta$employee1 <- as.numeric(test_dta$employee1)
test_dta$employee2 <- as.numeric(test_dta$employee2)
glimpse(train_dta)
```
Now, it's time to dig deeper...
-------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
## Exploratory Data Analysis
Let's explore the variables more closely using some visualizations. We'll grab each and every one of the variables in the data and inspect them. Below are the variables that we will be looking at. A brief description for each of the variables in this dataset can be found in [this link](http://dacon.io/cpt2/10394).
```{r}
# the variables in the data
train_dta %>% colnames()
```
Observe that there are 24 variables that are repeated twice, once with the suffix `1` and once with the suffix `2`. The ones with suffix `1` pertain to the fiscal year of 2017, whereas those with the suffix `2` pertain to the fiscal year of 2016.
-------------------------------------------------------------------------------------------------
### OC: Open/Close (Target Variable)
The target variable is a binary indicator showing whether a hospital has closed since its inception or not.
```{r}
train_dta %>%
select(OC) %>%
group_by(OC) %>%
summarise(count = n())
```
Okay. So we now know that the ratio between open and closed hospitals is around 20:1 in the training data. Of course, we must bear in mind that this ratio could be quite different in the test data.
-------------------------------------------------------------------------------------------------
### sido: Local information of hospital
```{r}
train_dta %>%
select(OC, sido) %>%
ggplot(aes(x = sido, fill = OC)) +
geom_bar() +
coord_flip()
```
```{r}
test_dta %>%
select(OC, sido) %>%
ggplot(aes(x = sido)) +
geom_bar() +
coord_flip()
```
We can notice from the above plots that while most cities/provinces appear in both the training and test sets, there are a few that appear only one of them (i.e. `jeju`, `gwangju`, `gangwon`)
-------------------------------------------------------------------------------------------------
### sgg: Local detail information of hospital
```{r}
train_dta %>%
select(OC, sgg) %>%
ggplot(aes(x = sgg, y = OC, fill = OC)) +
geom_point()
```
On first glance, the `sgg` variable does not seem to be useful in our goal of trying to predict whether a hospital would close or not (well... not on its own, anyway).
Before we move on though, let's check something first.
```{r}
length(unique(unlist(train_dta$sgg)))
```
We are guessing that `sgg` is some kind of ID used to indicate the district where each hospital is located and this dataset consists of 155 distinct ones. Before we continue, let's see if the test set contains any districts that do not exist in the training set.
```{r}
length(unique(union(unlist(train_dta$sgg),unlist(test_dta$sgg))))
```
```{r}
length(unique(unlist(test_dta$sgg)))
```
It seems that there are districts that exist in the test set and not in the training set. This may lead to the `sgg` variable being eliminated before training the prediction model later as it cannot be used to discriminate opening hospoital from closing ones (at least not in a straightforward manner).
```{r}
train_dta %>%
group_by(sido,sgg) %>%
summarise(count = n()) %>%
arrange(sgg)
```
The above command was to make sure that each `sgg` belongs to only one `sido` (i.e. that no `sgg` appears with more than one `sido` in the data). This makes sense as each district should only belong to one provinc/city (a district belonging to two provinces would not make sense).
```{r}
test_dta %>%
group_by(sido,sgg) %>%
summarise(count = n()) %>%
arrange(sgg)
```
The above command was to make sure that, for each `sgg` that existed in both the training and test data, it co-occured with the same `sido` in the training and test sets.
-------------------------------------------------------------------------------------------------
### openDate: Hospital establishment date
```{r}
# view some values of the 'openDate' variable
train_dta %>%
select(openDate) %>%
head()
```
Some parsing is in order. We shall separate it into three variables: year, month and day.
```{r}
# create new variables to hold the year/month/day values of 'openDate'
train_dta %>%
mutate(openDateYYYY = substr(openDate,1,4),
openDateMM = substr(openDate,5,6),
openDateDD = substr(openDate,7,8)) %>%
select(OC, openDateYYYY, openDateMM, openDateDD) %>%
head()
```
```{r}
# create new variables to hold the year/month/day values of 'openDate'
train_dta %>%
mutate(openDateYYYY = substr(openDate,1,4),
openDateMM = substr(openDate,5,6),
openDateDD = substr(openDate,7,8)) %>%
select(OC, openDateYYYY, openDateMM, openDateDD) %>%
ggplot(aes(x = openDateYYYY, fill = OC)) +
geom_bar() +
theme(axis.text.x = element_text(angle=90, vjust=0.5))
```
It seems that older hospitals are less likely to close than newer ones.
For fun, let's just see what the above plot looks like for `openDateMM`.
```{r}
# create new variables to hold the year/month/day values of 'openDate'
train_dta %>%
mutate(openDateYYYY = substr(openDate,1,4),
openDateMM = substr(openDate,5,6),
openDateDD = substr(openDate,7,8)) %>%
select(OC, openDateYYYY, openDateMM, openDateDD) %>%
ggplot(aes(x = openDateMM, fill = OC)) +
geom_bar() +
theme(axis.text.x = element_text(angle=90, vjust=0.5))
```
-------------------------------------------------------------------------------------------------
### bedCount: Number of sickbeds
```{r}
summary(train_dta$bedCount)
```
```{r}
train_dta %>%
select(OC, bedCount) %>%
filter(!is.na(bedCount)) %>%
ggplot(aes(x = bedCount, fill = OC)) +
geom_histogram(binwidth = 50)
```
Finally, something worth noting. It seems that hospitals that have a greater-than-average number of sickbeds tend to stay open (with a few rare exceptions). Let's have a look at the hospitals that have `NA` values in the `bedCount` variable.
```{r}
train_dta %>%
select(OC, bedCount) %>%
filter(is.na(bedCount))
```
For whatever it is worth, the hospitals having `NA` values in the `bedCount` variable are usually ones that eventually `close`. This finding is to be taken with a grain of salt since it is based on only 5 records.
There are some records that a value of `0` in the `bedCount` variable. Let's look at these too.
```{r}
train_dta %>%
select(OC, bedCount) %>%
filter(bedCount == 0) %>%
group_by(OC) %>%
summarise(count = n())
```
Similar to the distribution observed from the entire training data, the majority of the hospitals having a value of `0` in the `bedCount` variable are `open`. Nothing interesting to report here.
-------------------------------------------------------------------------------------------------
### instkind: Sort of hospital
```{r}
train_dta %>%
select(OC, instkind) %>%
filter(!is.na(instkind)) %>%
ggplot(aes(x = instkind, fill = OC)) +
geom_bar() +
theme(axis.text.x = element_text(angle=90, vjust=0.5)) +
coord_flip()
```
Each of the seven types of hospitals had its failed ventures. No one type of hospitals was 100% successful (except for `dental_clinic`).
-------------------------------------------------------------------------------------------------
### employee1: Number of employees employed (fiscal year 2017)
```{r}
train_dta$employee1 <- as.numeric(train_dta$employee1)
summary(train_dta$employee1)
```
```{r}
head(sort(train_dta$employee1), 20)
```
```{r}
train_dta %>%
select(OC, employee1) %>%
filter(!is.na(employee1)) %>%
ggplot(aes(x = employee1, fill = OC)) +
geom_histogram(binwidth = 50)
```
```{r}
train_dta %>%
select(OC, employee1) %>%
filter(is.na(employee1))
```
-------------------------------------------------------------------------------------------------
### employee2: Number of employees employed (fiscal year 2016)
```{r}
train_dta$employee2 <- as.numeric(train_dta$employee2)
summary(train_dta$employee2)
```
```{r}
head(sort(train_dta$employee2), 20)
```
```{r}
train_dta %>%
select(OC, employee2) %>%
filter(!is.na(employee2)) %>%
ggplot(aes(x = employee2, fill = OC)) +
geom_histogram(binwidth = 50)
```
```{r}
train_dta %>%
select(OC, employee2) %>%
filter(is.na(employee2))
```
```{r}
train_dta %>%
select(employee1, employee2) %>%
filter(!is.na(employee1) & !is.na(employee2)) %>%
as.matrix() %>%
cor()
```
-------------------------------------------------------------------------------------------------
### ownerChange: change of company representative
```{r}
train_dta %>%
select(OC, ownerChange) %>%
filter(!is.na(ownerChange)) %>%
ggplot(aes(x = ownerChange, fill = OC)) +
geom_bar() +
coord_flip()
```
It does not seem that value of `ownerChange` matters much, although proportions-wise, it seems that the hospitals that had an owner change had a bigger portion of failed hospitals than those that did not have an owner change. That is to say, when a hospital gets an owner change, the hospital becomes more likely to close. For example, the hospital may have been sold to another owner due to financial difficulties that the hospital was facing.
```{r}
train_dta %>%
select(OC, ownerChange) %>%
group_by(ownerChange) %>%
summarise(open = sum(OC == "open"), close = sum(OC == "close")) %>%
mutate(close_to_open_ratio = close/open)
```
-------------------------------------------------------------------------------------------------
### Variables of Fiscal Years, 2016 & 2017
Before moving on with the rest of the variables let's view the variables having the suffix `1` in a correlogram to sniff out any relations between them.
```{r}
# indices of rows (instances) containing NA values in them
row_indices <-
train_dta %>%
map_df(is.na) %>% # turn into an is.na() matrix
transmute(rowHasNAvalue = rowSums(.) > 0) %>% # create variable indicating whether the row has an NA value
as.matrix() %>% # convert into matrix (for the following 'which' function)
which() # return indices of rows having NA values
# display a correlogram of all the variables together
train_dta[-row_indices,8:31] %>%
cor() %>% # compute pairwise correlations
round(1) %>% # round to one decimal point
ggcorrplot(hc.order = FALSE,
type = "lower",
#lab = TRUE,
#lab_size = 3,
method="square",
colors = c("tomato2", "white", "springgreen3"),
title="Correlogram of all features",
ggtheme=theme_bw)
```
The above figure shows an important observation. That is, most variables highly with each other. Some exceptions include `profit1`, `interest1`, `shortLoan1`, `longLoan1`, `OnonCAsset1` and `surplus1`. Based on the high correlations observed in the figure above, the plots that will be generated for the variables in the figure should look similar to one another.
-------------------------------------------------------------------------------------------------
### revenue1: revenue (fiscal year 2017)
```{r}
train_dta %>%
select(OC, revenue1) %>%
filter(!is.na(revenue1)) %>%
ggplot(aes(x = revenue1, fill = OC)) +
geom_histogram(bins = 10)
```
Another finding worth mentioning; hospitals that `close` all seem to be at the lower end of the revenu scale. It may be useful to separate the data into two box plots (one for `open` hospitals and one for hospitals that `close`).
```{r}
train_dta %>%
select(OC, revenue1) %>%
filter(!is.na(revenue1)) %>%
ggplot(aes(x = OC, y = revenue1, fill = OC)) +
geom_boxplot()
```
Some of the hopsitals have the value `0` in the `revenue1` variable. Let's check those out.
```{r}
train_dta %>%
select(OC, revenue1) %>%
filter(revenue1 == 0) %>%
group_by(OC) %>%
summarise(count = n())
```
```{r}
train_dta %>%
select(OC, revenue1) %>%
filter(revenue1 > 0) %>%
group_by(OC) %>%
summarise(count = n())
```
-------------------------------------------------------------------------------------------------
### salescost1: sales cost (fiscal year 2017)
```{r}
summary(train_dta$salescost1)
```
```{r}
train_dta %>%
select(OC, salescost1) %>%
filter(!is.na(salescost1)) %>%
filter(salescost1 > 0) %>%
ggplot(aes(x = salescost1, fill = OC)) +
geom_histogram(bins = 10)
```
```{r}
train_dta %>%
select(OC, salescost1) %>%
filter(!is.na(salescost1)) %>%
filter(salescost1 != 0) %>%
#ggplot(aes(x = OC, y = log(salescost1), fill = OC)) +
ggplot(aes(x = OC, y = salescost1, fill = OC)) +
geom_boxplot()
```
-------------------------------------------------------------------------------------------------
### sga1: selling and general administrative expense (fiscal year 2017)
```{r}
train_dta %>%
select(OC, sga1) %>%
summary()
```
```{r}
train_dta %>%
select(OC, sga1) %>%
filter(!is.na(sga1)) %>%
ggplot(aes(x = sga1, fill = OC)) +
geom_histogram(bins = 10)
```
```{r}
train_dta %>%
select(OC, sga1) %>%
filter(!is.na(sga1)) %>%
filter(sga1 != 0) %>%
ggplot(aes(x = OC, y = sga1, fill = OC)) +
geom_boxplot()
```
```{r}
train_dta %>%
select(OC, sga1) %>%
filter(sga1 == 0) %>%
group_by(OC) %>%
summarise(count = n())
```
-------------------------------------------------------------------------------------------------
### salary1: salary account (fiscal year 2017)
```{r}
train_dta %>%
select(OC, salary1) %>%
summary()
```
```{r}
train_dta %>%
select(OC, salary1) %>%
filter(!is.na(salary1)) %>%
ggplot(aes(x = salary1, fill = OC)) +
geom_histogram(bins = 10)
```
```{r}
train_dta %>%
select(OC, salary1) %>%
filter(!is.na(salary1)) %>%
filter(salary1 != 0) %>%
ggplot(aes(x = OC, y = salary1, fill = OC)) +
geom_boxplot()
```
```{r}
train_dta %>%
select(OC, salary1) %>%
filter(salary1 == 0) %>%
group_by(OC) %>%
summarise(count = n())
```
-------------------------------------------------------------------------------------------------
### noi1: non-operating income (fiscal year 2017)
```{r}
train_dta %>%
select(OC, noi1) %>%
summary()
```
```{r}
train_dta %>%
select(OC, noi1) %>%
filter(!is.na(noi1)) %>%
ggplot(aes(x = noi1, fill = OC)) +
geom_histogram(bins = 10)
```
```{r}
train_dta %>%
select(OC, noi1) %>%
filter(!is.na(noi1)) %>%
filter(noi1 != 0) %>%
ggplot(aes(x = OC, y = noi1, fill = OC)) +
geom_boxplot()
```
```{r}
train_dta %>%
select(OC, noi1) %>%
filter(noi1 == 0) %>%
group_by(OC) %>%
summarise(count = n())
```
-------------------------------------------------------------------------------------------------
### noe1: non-operating expenses (fiscal year 2017)
```{r}
train_dta %>%
select(OC, noe1) %>%
summary()
```
```{r}
train_dta %>%
select(OC, noe1) %>%
filter(!is.na(noe1)) %>%
ggplot(aes(x = noe1, fill = OC)) +
geom_histogram(bins = 10)
```
```{r}
train_dta %>%
select(OC, noe1) %>%
filter(!is.na(noe1)) %>%
filter(noe1 != 0) %>%
ggplot(aes(x = OC, y = noe1, fill = OC)) +
geom_boxplot()
```
```{r}
train_dta %>%
select(OC, noe1) %>%
filter(noe1 == 0) %>%
group_by(OC) %>%
summarise(count = n())
```
-------------------------------------------------------------------------------------------------
### interest1: interest cost (fiscal year 2017)
```{r}
train_dta %>%
select(OC, interest1) %>%
summary()
```
```{r}
train_dta %>%
select(OC, interest1) %>%
filter(!is.na(interest1)) %>%
ggplot(aes(x = interest1, fill = OC)) +
geom_histogram(bins = 10)
```
```{r}
train_dta %>%
select(OC, interest1) %>%
filter(!is.na(interest1)) %>%
filter(interest1 != 0) %>%
ggplot(aes(x = OC, y = interest1, fill = OC)) +
geom_boxplot()
```
```{r}
train_dta %>%
select(OC, interest1) %>%
filter(interest1 == 0) %>%
group_by(OC) %>%
summarise(count = n())
```
```{r}
train_dta %>%
select(OC, interest1) %>%
filter(interest1 != 0) %>%
group_by(OC) %>%
summarise(count = n())
```
-------------------------------------------------------------------------------------------------
### ctax1: corporate tax (fiscal year 2017)
```{r}
train_dta %>%
select(OC, ctax1) %>%
summary()
```
```{r}
train_dta %>%
select(OC, ctax1) %>%
filter(!is.na(ctax1)) %>%
ggplot(aes(x = ctax1, fill = OC)) +
geom_histogram(bins = 10)
```
```{r}
train_dta %>%
select(OC, ctax1) %>%
filter(!is.na(ctax1)) %>%
filter(ctax1 != 0) %>%
ggplot(aes(x = OC, y = ctax1, fill = OC)) +
geom_boxplot()
```
```{r}
train_dta %>%
select(OC, ctax1) %>%
filter(ctax1 == 0) %>%
group_by(OC) %>%
summarise(count = n())
```
-------------------------------------------------------------------------------------------------
### profit1: net profit during the term (fiscal year 2017)
```{r}
train_dta %>%
select(OC, profit1) %>%
summary()
```
```{r}
train_dta %>%
select(OC, profit1) %>%
filter(!is.na(profit1)) %>%
ggplot(aes(x = profit1, fill = OC)) +
geom_histogram(bins = 10)
```
```{r}
train_dta %>%
select(OC, profit1) %>%
filter(!is.na(profit1)) %>%
filter(profit1 != 0) %>%
ggplot(aes(x = OC, y = profit1, fill = OC)) +
geom_boxplot()
```
```{r}
train_dta %>%
select(OC, profit1) %>%
filter(profit1 > 0) %>%
group_by(OC) %>%
summarise(count = n())
```
```{r}
train_dta %>%
select(OC, profit1) %>%
filter(profit1 == 0) %>%
group_by(OC) %>%
summarise(count = n())
```
```{r}
train_dta %>%
select(OC, profit1) %>%
filter(profit1 < 0) %>%
group_by(OC) %>%
summarise(count = n())
```
-------------------------------------------------------------------------------------------------
### liquidAsset1: liquid asset (fiscal year 2017)
```{r}
train_dta %>%
select(OC, liquidAsset1) %>%
summary()
```
```{r}
train_dta %>%
select(OC, liquidAsset1) %>%
filter(!is.na(liquidAsset1)) %>%
ggplot(aes(x = liquidAsset1, fill = OC)) +
geom_histogram(bins = 10)
```
```{r}
train_dta %>%
select(OC, liquidAsset1) %>%
filter(!is.na(liquidAsset1)) %>%
filter(liquidAsset1 != 0) %>%
ggplot(aes(x = OC, y = liquidAsset1, fill = OC)) +
geom_boxplot()
```
```{r}
train_dta %>%
select(OC, liquidAsset1) %>%
filter(liquidAsset1 == 0) %>%
group_by(OC) %>%
summarise(count = n())
```
-------------------------------------------------------------------------------------------------
### quickAsset1: quick asset (fiscal year 2017)
```{r}
train_dta %>%
select(quickAsset1) %>%
summary()
```
```{r}
train_dta %>%
select(OC, quickAsset1) %>%
filter(!is.na(quickAsset1)) %>%
ggplot(aes(x = quickAsset1, fill = OC)) +
geom_histogram(bins = 10)
```
```{r}
train_dta %>%
select(OC, quickAsset1) %>%
filter(!is.na(quickAsset1)) %>%
filter(quickAsset1 != 0) %>%
ggplot(aes(x = OC, y = quickAsset1, fill = OC)) +
geom_boxplot()
```
```{r}
train_dta %>%
select(OC, quickAsset1) %>%
filter(quickAsset1 == 0) %>%
group_by(OC) %>%
summarise(count = n())
```
-------------------------------------------------------------------------------------------------
### receivableS1: accounts receivable(short-term) (fiscal year 2017)
```{r}
train_dta %>%
select(receivableS1) %>%
summary()
```
```{r}
train_dta %>%
select(OC, receivableS1) %>%
filter(!is.na(receivableS1)) %>%
ggplot(aes(x = receivableS1, fill = OC)) +
geom_histogram(bins = 10)
```
```{r}
train_dta %>%
select(OC, receivableS1) %>%
filter(!is.na(receivableS1)) %>%
filter(receivableS1 != 0) %>%
ggplot(aes(x = OC, y = receivableS1, fill = OC)) +
geom_boxplot()
```
```{r}
train_dta %>%
select(OC, receivableS1) %>%
filter(receivableS1 == 0) %>%
group_by(OC) %>%
summarise(count = n())
```
-------------------------------------------------------------------------------------------------
### inventoryAsset1: inventory asset (fiscal year 2017)
```{r}
train_dta %>%
select(inventoryAsset1) %>%
summary()
```
```{r}
train_dta %>%
select(OC, inventoryAsset1) %>%
filter(!is.na(inventoryAsset1)) %>%
ggplot(aes(x = inventoryAsset1, fill = OC)) +
geom_histogram(bins = 10)
```
```{r}
train_dta %>%
select(OC, inventoryAsset1) %>%
filter(!is.na(inventoryAsset1)) %>%
filter(inventoryAsset1 != 0) %>%
ggplot(aes(x = OC, y = inventoryAsset1, fill = OC)) +
geom_boxplot()
```
```{r}
train_dta %>%
select(OC, inventoryAsset1) %>%
filter(inventoryAsset1 == 0) %>%
group_by(OC) %>%
summarise(count = n())
```
-------------------------------------------------------------------------------------------------
### nonCAsset1: noncurrent asset (fiscal year 2017)
```{r}
train_dta %>%
select(nonCAsset1) %>%
summary()
```
```{r}
train_dta %>%
select(OC, nonCAsset1) %>%
filter(!is.na(nonCAsset1)) %>%
ggplot(aes(x = nonCAsset1, fill = OC)) +
geom_histogram(bins = 10)
```
```{r}
train_dta %>%
select(OC, nonCAsset1) %>%
filter(!is.na(nonCAsset1)) %>%
filter(nonCAsset1 != 0) %>%
ggplot(aes(x = OC, y = nonCAsset1, fill = OC)) +
geom_boxplot()
```
```{r}
train_dta %>%
select(OC, nonCAsset1) %>%
filter(nonCAsset1 == 0) %>%
group_by(OC) %>%
summarise(count = n())
```
-------------------------------------------------------------------------------------------------
### tanAsset1: tangible assets (fiscal year 2017)
```{r}
train_dta %>%
select(tanAsset1) %>%
summary()
```
```{r}
train_dta %>%
select(OC, tanAsset1) %>%
filter(!is.na(tanAsset1)) %>%
ggplot(aes(x = tanAsset1, fill = OC)) +
geom_histogram(bins = 10)
```
```{r}
train_dta %>%
select(OC, tanAsset1) %>%
filter(!is.na(tanAsset1)) %>%
filter(tanAsset1 != 0) %>%
ggplot(aes(x = OC, y = tanAsset1, fill = OC)) +
geom_boxplot()
```
```{r}
train_dta %>%
select(OC, tanAsset1) %>%
filter(tanAsset1 == 0) %>%
group_by(OC) %>%
summarise(count = n())