-
Notifications
You must be signed in to change notification settings - Fork 1
/
Curso_Auditoria_Dados_Estudo_Caso_Hospital.html
3221 lines (3166 loc) · 97.8 KB
/
Curso_Auditoria_Dados_Estudo_Caso_Hospital.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
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
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="author" content="Flávio Brito" />
<meta name="date" content="2016-12-10" />
<title>Curso Auditoria de Dados - Caso Estudo Pagamento Hospitalar</title>
<script src="Curso_Auditoria_Dados_Estudo_Caso_Hospital_files/jquery-1.11.3/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="Curso_Auditoria_Dados_Estudo_Caso_Hospital_files/bootstrap-3.3.5/css/cerulean.min.css" rel="stylesheet" />
<script src="Curso_Auditoria_Dados_Estudo_Caso_Hospital_files/bootstrap-3.3.5/js/bootstrap.min.js"></script>
<script src="Curso_Auditoria_Dados_Estudo_Caso_Hospital_files/bootstrap-3.3.5/shim/html5shiv.min.js"></script>
<script src="Curso_Auditoria_Dados_Estudo_Caso_Hospital_files/bootstrap-3.3.5/shim/respond.min.js"></script>
<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">
div.sourceCode { overflow-x: auto; }
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
margin: 0; padding: 0; vertical-align: baseline; border: none; }
table.sourceCode { width: 100%; line-height: 100%; background-color: #f8f8f8; }
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
td.sourceCode { padding-left: 5px; }
pre, code { background-color: #f8f8f8; }
code > span.kw { color: #204a87; font-weight: bold; } /* Keyword */
code > span.dt { color: #204a87; } /* DataType */
code > span.dv { color: #0000cf; } /* DecVal */
code > span.bn { color: #0000cf; } /* BaseN */
code > span.fl { color: #0000cf; } /* Float */
code > span.ch { color: #4e9a06; } /* Char */
code > span.st { color: #4e9a06; } /* String */
code > span.co { color: #8f5902; font-style: italic; } /* Comment */
code > span.ot { color: #8f5902; } /* Other */
code > span.al { color: #ef2929; } /* Alert */
code > span.fu { color: #000000; } /* Function */
code > span.er { color: #a40000; font-weight: bold; } /* Error */
code > span.wa { color: #8f5902; font-weight: bold; font-style: italic; } /* Warning */
code > span.cn { color: #000000; } /* Constant */
code > span.sc { color: #000000; } /* SpecialChar */
code > span.vs { color: #4e9a06; } /* VerbatimString */
code > span.ss { color: #4e9a06; } /* SpecialString */
code > span.im { } /* Import */
code > span.va { color: #000000; } /* Variable */
code > span.cf { color: #204a87; font-weight: bold; } /* ControlFlow */
code > span.op { color: #ce5c00; font-weight: bold; } /* Operator */
code > span.pp { color: #8f5902; font-style: italic; } /* Preprocessor */
code > span.ex { } /* Extension */
code > span.at { color: #c4a000; } /* Attribute */
code > span.do { color: #8f5902; font-weight: bold; font-style: italic; } /* Documentation */
code > span.an { color: #8f5902; font-weight: bold; font-style: italic; } /* Annotation */
code > span.cv { color: #8f5902; font-weight: bold; font-style: italic; } /* CommentVar */
code > span.in { color: #8f5902; font-weight: bold; font-style: italic; } /* Information */
</style>
<style type="text/css">
pre:not([class]) {
background-color: white;
}
</style>
</head>
<body>
<style type = "text/css">
.main-container {
max-width: 940px;
margin-left: auto;
margin-right: auto;
}
code {
color: inherit;
background-color: rgba(0, 0, 0, 0.04);
}
img {
max-width:100%;
height: auto;
}
h1 {
font-size: 34px;
}
h1.title {
font-size: 38px;
}
h2 {
font-size: 30px;
}
h3 {
font-size: 24px;
}
h4 {
font-size: 18px;
}
h5 {
font-size: 16px;
}
h6 {
font-size: 12px;
}
.tabbed-pane {
padding-top: 12px;
}
button.code-folding-btn:focus {
outline: none;
}
</style>
<div class="container-fluid main-container">
<!-- tabsets -->
<script src="Curso_Auditoria_Dados_Estudo_Caso_Hospital_files/navigation-1.0/tabsets.js"></script>
<script>
$(document).ready(function () {
window.buildTabsets("TOC");
});
</script>
<!-- code folding -->
<div class="fluid-row" id="header">
<h1 class="title">Curso Auditoria de Dados - Caso Estudo Pagamento Hospitalar</h1>
<h4 class="author"><em>Flávio Brito</em></h4>
<h4 class="date"><em>23/10/2016</em></h4>
</div>
<div id="TOC">
<ul>
<li><a href="#arquivos"><span class="toc-section-number">1</span> Arquivos</a></li>
<li><a href="#pacotes-instalados-e-carregados"><span class="toc-section-number">2</span> Pacotes instalados e carregados</a></li>
</ul>
</div>
<div id="arquivos" class="section level1">
<h1><span class="header-section-number">1</span> Arquivos</h1>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co">#Retirando um data frame da memoria</span>
hospay <-<span class="st"> </span><span class="ot">NULL</span>
<span class="co">#Lendo o arquivo no padrão csv com separador ; e criando o data frame nf</span>
<span class="co"># hospay <- read.csv(file="./dados/Hospital.csv", sep=";",stringsAsFactors = FALSE, na.strings = c(""," ")) </span>
hospay <-<span class="st"> </span><span class="kw">read.csv</span>(<span class="dt">file=</span><span class="st">"https://raw.githubusercontent.com/flaviobrito/dataudit/master/dados/Hospital.csv"</span>, <span class="dt">sep=</span><span class="st">";"</span>,<span class="dt">stringsAsFactors =</span> <span class="ot">FALSE</span>, <span class="dt">na.strings =</span> <span class="kw">c</span>(<span class="st">""</span>,<span class="st">" "</span>))
<span class="co">#Estrutura do Arquivo</span>
<span class="kw">str</span>(hospay)</code></pre></div>
<pre><code>## 'data.frame': 14454 obs. of 23 variables:
## $ Provider.ID : int 10005 10005 10005 10032 10032 10032 10131 10131 10131 20001 ...
## $ Hospital.name : chr "MARSHALL MEDICAL CENTER SOUTH" "MARSHALL MEDICAL CENTER SOUTH" "MARSHALL MEDICAL CENTER SOUTH" "WEDOWEE HOSPITAL" ...
## $ Address : chr "2505 U S HIGHWAY 431 NORTH" "2505 U S HIGHWAY 431 NORTH" "2505 U S HIGHWAY 431 NORTH" "209 NORTH MAIN STREET" ...
## $ City : chr "BOAZ" "BOAZ" "BOAZ" "WEDOWEE" ...
## $ State : chr "AL" "AL" "AL" "AL" ...
## $ ZIP.Code : int 35957 35957 35957 36278 36278 36278 35801 35801 35801 99508 ...
## $ County.name : chr "MARSHALL" "MARSHALL" "MARSHALL" "RANDOLPH" ...
## $ Phone.number : num 2.57e+09 2.57e+09 2.57e+09 2.56e+09 2.56e+09 ...
## $ Payment.measure.name : chr "Payment for heart attack patients" "Payment for heart failure patients" "Payment for pneumonia patients" "Payment for heart attack patients" ...
## $ Payment.measure.ID : chr "PAYM_30_AMI" "PAYM_30_HF" "PAYM_30_PN" "PAYM_30_AMI" ...
## $ Payment.category : chr "No Different than the National Average Payment" "No Different than the National Average Payment" "No Different than the National Average Payment" "Number of Cases Too Small" ...
## $ Denominator : chr "53" "347" "646" "Not Available" ...
## $ Payment : chr "$23171.00" "$16376.00" "$14384.00" NA ...
## $ Lower.estimate : chr "$20,404" "$15,237" "$13,642" "Not Available" ...
## $ Higher.estimate : chr "$26,226" "$17,547" "$15,118" "Not Available" ...
## $ Payment.footnote : chr NA NA NA "1 - The number of cases/patients is too few to report." ...
## $ Value.of.care.display.name: chr "Value of Care Heart Attack measure" "Value of Care Heart Failure measure" "Value of Care Pneumonia measure" "Value of Care Heart Attack measure" ...
## $ Value.of.care.display.ID : chr "MORT_PAYM_30_AMI" "MORT_PAYM_30_HF" "MORT_PAYM_30_PN" "MORT_PAYM_30_AMI" ...
## $ Value.of.care.category : chr "Average mortality and average payment" "Worse mortality and average payment" "Worse mortality and average payment" "Not Available" ...
## $ Value.of.care.footnote : chr NA NA NA "13 - Results cannot be calculated for this reporting period." ...
## $ Measure.start.date : chr "07/01/2012" "07/01/2012" "07/01/2012" "07/01/2012" ...
## $ Measure.End.Date : chr "06/30/2015" "06/30/2015" "06/30/2015" "06/30/2015" ...
## $ Location : chr "2505 U S HIGHWAY 431 NORTH\nBOAZ, AL 35957\n" "2505 U S HIGHWAY 431 NORTH\nBOAZ, AL 35957\n" "2505 U S HIGHWAY 431 NORTH\nBOAZ, AL 35957\n" "209 NORTH MAIN STREET\nWEDOWEE, AL 36278\n" ...</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co">#Resumo dos Dados</span>
<span class="kw">summary</span>(hospay$Measure.start.date)</code></pre></div>
<pre><code>## Length Class Mode
## 14454 character character</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">summary</span>(hospay$Measure.End.Date)</code></pre></div>
<pre><code>## Length Class Mode
## 14454 character character</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co">#Lista as categorias em um </span>
<span class="kw">unique</span>(hospay$Measure.start.date) %>%<span class="st"> </span>head</code></pre></div>
<pre><code>## Error in eval(expr, envir, enclos): não foi possível encontrar a função "%>%"</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">levels</span>(hospay$Measure.End.Date) %>%<span class="st"> </span>head</code></pre></div>
<pre><code>## Error in eval(expr, envir, enclos): não foi possível encontrar a função "%>%"</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co">#Checando</span>
hospay$Measure.start.date <-<span class="st"> </span><span class="kw">trimws</span>(hospay$Measure.start.date, <span class="dt">which =</span> <span class="st">"both"</span>)
hospay$Measure.End.Date <-<span class="st"> </span><span class="kw">trimws</span>(hospay$Measure.End.Date, <span class="dt">which =</span> <span class="st">"both"</span>)
<span class="co">#Datas com Missing</span>
<span class="kw">any</span>(<span class="kw">is.na</span>(<span class="kw">as.character</span>(hospay$Measure.start.date)))</code></pre></div>
<pre><code>## [1] FALSE</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">any</span>(<span class="kw">is.na</span>(<span class="kw">as.character</span>(hospay$Measure.End.Date)))</code></pre></div>
<pre><code>## [1] FALSE</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co">#Pagamentos com Missing</span>
<span class="kw">any</span>(<span class="kw">is.na</span>(<span class="kw">as.numeric</span>(hospay$Payment)))</code></pre></div>
<pre><code>## Warning: NAs introduzidos por coerção</code></pre>
<pre><code>## [1] TRUE</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co">#Tratando data</span>
hospay$Measure.start.date <-<span class="st"> </span><span class="kw">as.Date</span>(hospay$Measure.start.date,<span class="st">"%m/%d/%Y"</span> )
hospay$Measure.End.Date <-<span class="st"> </span><span class="kw">as.Date</span>(hospay$Measure.End.Date,<span class="st">"%m/%d/%Y"</span> )
<span class="kw">class</span>(hospay$Measure.start.date)</code></pre></div>
<pre><code>## [1] "Date"</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">class</span>(hospay$Measure.End.Date)</code></pre></div>
<pre><code>## [1] "Date"</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">str</span>(hospay$Measure.start.date)</code></pre></div>
<pre><code>## Date[1:14454], format: "2012-07-01" "2012-07-01" "2012-07-01" "2012-07-01" ...</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">str</span>(hospay$Measure.End.Date)</code></pre></div>
<pre><code>## Date[1:14454], format: "2015-06-30" "2015-06-30" "2015-06-30" "2015-06-30" ...</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># Tratamento de valores em Strings</span>
<span class="co"># Remover sinal de dollar e vírgula</span>
hospay$Payment <-<span class="st"> </span><span class="kw">as.numeric</span>(<span class="kw">gsub</span>(<span class="st">"[$,]"</span>, <span class="st">""</span>, hospay$Payment))
hospay$Lower.estimate <-<span class="st"> </span><span class="kw">as.numeric</span>(<span class="kw">gsub</span>(<span class="st">"[$,]"</span>, <span class="st">""</span>, hospay$Lower.estimate))</code></pre></div>
<pre><code>## Warning: NAs introduzidos por coerção</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">hospay$Higher.estimate <-<span class="kw">as.numeric</span>(<span class="kw">gsub</span>(<span class="st">"[$,]"</span>, <span class="st">""</span>, hospay$Lower.estimate))
<span class="co">#Limpa os brancos </span>
hospay$Hospital.name<-<span class="st"> </span><span class="kw">gsub</span>(<span class="st">"[ ]"</span>, <span class="st">""</span>, hospay$Hospital.name)
<span class="co">#Qual o total de hospitais prentes na lista</span>
<span class="kw">length</span>(hospay$Hospital.name) </code></pre></div>
<pre><code>## [1] 14454</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co">#Quantos hospitais</span>
<span class="kw">length</span>((<span class="kw">unique</span>(hospay$Hospital.name)))</code></pre></div>
<pre><code>## [1] 4615</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co">#Quais os hostitais</span>
<span class="kw">unique</span>(hospay$Hospital.name) %>%<span class="st"> </span>head</code></pre></div>
<pre><code>## Error in eval(expr, envir, enclos): não foi possível encontrar a função "%>%"</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co">#Pivot</span>
<span class="co"># Contagem de casos por Hospital</span>
pv1 <-<span class="kw">data.frame</span>(<span class="kw">table</span>(hospay$City, hospay$Value.of.care.category, hospay$State))
<span class="kw">table</span>(hospay$City, hospay$State) %>%<span class="st"> </span>head</code></pre></div>
<pre><code>## Error in eval(expr, envir, enclos): não foi possível encontrar a função "%>%"</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co">#Frequencia</span>
pv1 <-<span class="st"> </span><span class="ot">NULL</span>
pv1 <-<span class="st"> </span><span class="kw">with</span>(hospay,<span class="kw">table</span>(hospay$State))
pv1.freq <-<span class="st"> </span><span class="kw">table</span>(hospay$State)
pv1.prob <-<span class="st"> </span><span class="kw">prop.table</span>(pv1.freq)
pv1.out <-<span class="st"> </span><span class="kw">cbind</span>(pv1.freq, pv1.prob)
<span class="co">#Mudando o nome das colunas</span>
<span class="kw">colnames</span>(pv1.out) <-<span class="kw">c</span>(<span class="st">"Freq"</span>,<span class="st">"Perc(%)"</span>)
<span class="co">#Frequencia por faixa - dados numéricos</span>
faixa1 <-<span class="kw">cut</span>(hospay$Payment, <span class="dt">breaks =</span> <span class="dv">10</span>,<span class="dt">dig.lab =</span> <span class="dv">10</span>,<span class="dt">include.lowest =</span> <span class="ot">TRUE</span>)
<span class="kw">stack</span>(<span class="kw">table</span>(faixa1)) <span class="co">#transpoe</span></code></pre></div>
<pre><code>## values ind
## 1 34 [9481.168,11585.2]
## 2 856 (11585.2,13668.4]
## 3 3861 (13668.4,15751.6]
## 4 2314 (15751.6,17834.8]
## 5 475 (17834.8,19918]
## 6 650 (19918,22001.2]
## 7 1130 (22001.2,24084.4]
## 8 490 (24084.4,26167.6]
## 9 64 (26167.6,28250.8]
## 10 6 (28250.8,30354.832]</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">faixa1 <-<span class="kw">cut</span>(hospay$Payment, <span class="kw">seq</span>(<span class="dt">from =</span> <span class="dv">1000</span>, <span class="dt">to =</span> <span class="dv">40000</span>, <span class="dt">by =</span> <span class="dv">5000</span>),<span class="dt">dig.lab =</span> <span class="dv">10</span>,<span class="dt">include.lowest =</span> <span class="ot">TRUE</span>,<span class="dt">right =</span> <span class="ot">TRUE</span>)
<span class="kw">stack</span>(<span class="kw">table</span>(faixa1)) <span class="co">#transpoe</span></code></pre></div>
<pre><code>## values ind
## 1 0 [1000,6000]
## 2 6 (6000,11000]
## 3 5211 (11000,16000]
## 4 2539 (16000,21000]
## 5 2043 (21000,26000]
## 6 81 (26000,31000]
## 7 0 (31000,36000]</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">faixa1 <-<span class="kw">cut</span>(hospay$Payment, <span class="kw">seq</span>(<span class="dv">1000</span>, <span class="dv">40000</span>, <span class="dv">5000</span>),<span class="dt">dig.lab =</span> <span class="dv">10</span>,<span class="dt">right =</span> <span class="ot">FALSE</span>)
<span class="kw">stack</span>(<span class="kw">table</span>(faixa1)) <span class="co">#transpoe</span></code></pre></div>
<pre><code>## values ind
## 1 0 [1000,6000)
## 2 6 [6000,11000)
## 3 5211 [11000,16000)
## 4 2539 [16000,21000)
## 5 2043 [21000,26000)
## 6 81 [26000,31000)
## 7 0 [31000,36000)</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co">#include.lowest = TRUE inclui o menor</span>
faixa2 <-<span class="kw">cut</span>(hospay$Payment, <span class="dt">breaks =</span> <span class="dv">10</span>, <span class="dt">dig.lab =</span> <span class="dv">10</span>,<span class="dt">labels=</span><span class="kw">c</span>(<span class="st">"A"</span>,<span class="st">"B"</span>, <span class="st">"C"</span>, <span class="st">"D"</span>, <span class="st">"E"</span>, <span class="st">"F"</span>, <span class="st">"G"</span>, <span class="st">"H"</span>, <span class="st">"I"</span>, <span class="st">"J"</span>)) <span class="co"># força os labels</span>
<span class="kw">summary</span>(faixa2)</code></pre></div>
<pre><code>## A B C D E F G H I J NA's
## 34 856 3861 2314 475 650 1130 490 64 6 4574</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">stack</span>(<span class="kw">summary</span>(faixa2))</code></pre></div>
<pre><code>## values ind
## 1 34 A
## 2 856 B
## 3 3861 C
## 4 2314 D
## 5 475 E
## 6 650 F
## 7 1130 G
## 8 490 H
## 9 64 I
## 10 6 J
## 11 4574 NA's</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">faixa2 <-<span class="kw">cut</span>(hospay$Payment, <span class="dt">breaks =</span> <span class="dv">10</span>, <span class="dt">dig.lab =</span> <span class="dv">10</span>,<span class="dt">labels=</span><span class="kw">c</span>(<span class="dv">1</span>:<span class="dv">10</span>)) <span class="co"># força os labels</span>
<span class="kw">summary</span>(faixa2)</code></pre></div>
<pre><code>## 1 2 3 4 5 6 7 8 9 10 NA's
## 34 856 3861 2314 475 650 1130 490 64 6 4574</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">stack</span>(<span class="kw">summary</span>(faixa2)) </code></pre></div>
<pre><code>## values ind
## 1 34 1
## 2 856 2
## 3 3861 3
## 4 2314 4
## 5 475 5
## 6 650 6
## 7 1130 7
## 8 490 8
## 9 64 9
## 10 6 10
## 11 4574 NA's</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">faixa <-<span class="kw">cut</span>(hospay$Payment, <span class="dt">breaks =</span> <span class="kw">c</span>(<span class="dv">100</span>,<span class="dv">10000</span>,<span class="dv">20000</span>, <span class="dv">30000</span>), <span class="dt">labels=</span><span class="kw">c</span>(<span class="st">"medio"</span>, <span class="st">"maior"</span>, <span class="st">"avaliar"</span>))
<span class="kw">stack</span>(<span class="kw">table</span>(faixa)) <span class="co">#transpoe</span></code></pre></div>
<pre><code>## values ind
## 1 1 medio
## 2 7554 maior
## 3 2324 avaliar</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co">#Steam and Leaf - dados num?ricos</span>
<span class="kw">stem</span>(hospay$Payment)</code></pre></div>
<pre><code>##
## The decimal point is 3 digit(s) to the right of the |
##
## 9 | 5
## 10 | 22478
## 11 | 01112222233344444444555555566666666677788888888889999999999999
## 12 | 00000000000000001111111111111111122222222222222222222333333333333333+194
## 13 | 00000000000000000000000000000000000000000000000000011111111111111111+861
## 14 | 00000000000000000000000000000000000000000000000000000000000000000000+1712
## 15 | 00000000000000000000000000000000000000000000000000000000000000000000+1972
## 16 | 00000000000000000000000000000000000000000000000000000000000000000000+1258
## 17 | 00000000000000000000000000000000000000000000000000000000000000000000+578
## 18 | 00000000000000000000000000000000000000000000011111111111111111111111+208
## 19 | 00000000000000000001111111111112222222222222333333333333344444444444+59
## 20 | 00000000011111111111111111111111111222222222222222223333333333333333+113
## 21 | 00000000000000000000000000000111111111111111111111111111111111222222+343
## 22 | 00000000000000000000000000000000000000000000000000000000111111111111+484
## 23 | 00000000000000000000000000000000000000000000000000000000111111111111+460
## 24 | 00000000000000000000000000000000000000011111111111111111111111111111+280
## 25 | 00000000000000000000000111111111111111111111111122222222222222222222+83
## 26 | 00000000001111122222222333333333344444444555566666666777788999
## 27 | 0000222345567778889
## 28 | 555
## 29 | 25
## 30 | 3</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">plot</span>(<span class="kw">density</span>(<span class="kw">na.omit</span>(hospay$Payment)))</code></pre></div>
<p><img src="Curso_Auditoria_Dados_Estudo_Caso_Hospital_files/figure-html/unnamed-chunk-1-1.png" title="" alt="" width="960" /></p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co">#Boxplot</span>
bl <-<span class="kw">boxplot</span>(<span class="kw">na.omit</span>(hospay$Payment))</code></pre></div>
<p><img src="Curso_Auditoria_Dados_Estudo_Caso_Hospital_files/figure-html/unnamed-chunk-1-2.png" title="" alt="" width="960" /></p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">which</span>(hospay$Payment %in%<span class="st"> </span>bl$out)</code></pre></div>
<pre><code>## [1] 95 133 260 300 399 494 500 506 509 515 661
## [12] 831 976 1041 1267 1348 1403 1449 1501 1572 1716 1772
## [23] 1808 1857 1991 2065 2086 2114 2154 2210 2213 2215 2259
## [34] 2295 2310 2338 2390 2478 2566 2580 2582 2875 3072 3099
## [45] 3156 3270 3282 3330 3589 3796 3983 4132 4148 4159 4166
## [56] 4336 4377 4411 4424 4603 4613 4677 4763 4937 5238 5306
## [67] 5532 5617 5938 6404 6709 6755 7092 7303 7488 7518 7553
## [78] 7603 7614 7783 7869 7988 8178 8191 8287 8521 8567 8570
## [89] 8578 8584 8625 8645 8649 8658 8661 8691 8694 8714 8756
## [100] 8791 8838 8853 8871 8950 8972 9073 9172 9207 9224 9269
## [111] 9270 9273 9318 9324 9376 9405 9541 9583 9698 9732 9811
## [122] 10069 10137 10271 10404 10636 10694 11373 12168 12285 12296 12319
## [133] 12350 12376 12378 12779 12848 12912 12913 12947 12978 12996 13048
## [144] 13085 13171 13310 13644 13699 13837 13860 13953 13990 14030</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">hospay$Payment[<span class="dv">95</span>]</code></pre></div>
<pre><code>## [1] 25411</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">bl$out</code></pre></div>
<pre><code>## [1] 25411 27718 25586 25429 26241 25674 25718 26316 26043 25795 27835
## [12] 25556 26159 25489 25466 25878 25941 25690 26166 25530 26186 26619
## [23] 26060 25464 30334 25656 27770 27042 25510 26674 25521 25635 26266
## [34] 27547 27152 25450 27758 27347 26395 25606 25913 27004 26731 25917
## [45] 26642 26325 25635 25408 26880 28451 26995 26044 25807 26473 25751
## [56] 26346 25455 26375 25654 26850 26278 26583 26913 28468 25579 26433
## [67] 27360 25692 25756 25985 25987 26184 27236 26014 27220 25928 26317
## [78] 26280 25856 26427 25756 26106 26200 27480 25966 25515 25582 25895
## [89] 25933 25979 25581 25529 26654 25507 26183 25428 27683 25869 26184
## [100] 25799 25527 27931 25662 25458 26999 26810 26604 25932 26459 26101
## [111] 26562 26438 26379 26110 25829 25978 26112 25720 25907 26332 25988
## [122] 25941 25624 25893 25910 25545 25704 26415 25391 26539 27743 26260
## [133] 26347 26596 26726 25932 26483 29548 25385 28454 25495 25457 25790
## [144] 26406 25701 29193 26759 25400 25625 26565 26001 26614 27616</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">hospay$Payment[<span class="kw">which</span>(hospay$Payment %in%<span class="st"> </span>bl$out)]</code></pre></div>
<pre><code>## [1] 25411 27718 25586 25429 26241 25674 25718 26316 26043 25795 27835
## [12] 25556 26159 25489 25466 25878 25941 25690 26166 25530 26186 26619
## [23] 26060 25464 30334 25656 27770 27042 25510 26674 25521 25635 26266
## [34] 27547 27152 25450 27758 27347 26395 25606 25913 27004 26731 25917
## [45] 26642 26325 25635 25408 26880 28451 26995 26044 25807 26473 25751
## [56] 26346 25455 26375 25654 26850 26278 26583 26913 28468 25579 26433
## [67] 27360 25692 25756 25985 25987 26184 27236 26014 27220 25928 26317
## [78] 26280 25856 26427 25756 26106 26200 27480 25966 25515 25582 25895
## [89] 25933 25979 25581 25529 26654 25507 26183 25428 27683 25869 26184
## [100] 25799 25527 27931 25662 25458 26999 26810 26604 25932 26459 26101
## [111] 26562 26438 26379 26110 25829 25978 26112 25720 25907 26332 25988
## [122] 25941 25624 25893 25910 25545 25704 26415 25391 26539 27743 26260
## [133] 26347 26596 26726 25932 26483 29548 25385 28454 25495 25457 25790
## [144] 26406 25701 29193 26759 25400 25625 26565 26001 26614 27616</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co">#Agregação</span>
<span class="kw">with</span>(hospay, <span class="kw">by</span>(hospay$Payment, <span class="kw">list</span>(hospay$Payment.category,hospay$State), mean))</code></pre></div>
<pre><code>## : Greater than the National Average Payment
## : AK
## [1] NA
## --------------------------------------------------------
## : Less than the National Average Payment
## : AK
## [1] 12421.77
## --------------------------------------------------------
## : No Different than the National Average Payment
## : AK
## [1] 18001.92
## --------------------------------------------------------
## : Not Available
## : AK
## [1] NA
## --------------------------------------------------------
## : Number of Cases Too Small
## : AK
## [1] NA
## --------------------------------------------------------
## : Greater than the National Average Payment
## : AL
## [1] 17285.4
## --------------------------------------------------------
## : Less than the National Average Payment
## : AL
## [1] 14089.67
## --------------------------------------------------------
## : No Different than the National Average Payment
## : AL
## [1] 16991.26
## --------------------------------------------------------
## : Not Available
## : AL
## [1] NA
## --------------------------------------------------------
## : Number of Cases Too Small
## : AL
## [1] NA
## --------------------------------------------------------
## : Greater than the National Average Payment
## : AR
## [1] 18900
## --------------------------------------------------------
## : Less than the National Average Payment
## : AR
## [1] 13911.93
## --------------------------------------------------------
## : No Different than the National Average Payment
## : AR
## [1] 16608.69
## --------------------------------------------------------
## : Not Available
## : AR
## [1] NA
## --------------------------------------------------------
## : Number of Cases Too Small
## : AR
## [1] NA
## --------------------------------------------------------
## : Greater than the National Average Payment
## : AS
## [1] NA
## --------------------------------------------------------
## : Less than the National Average Payment
## : AS
## [1] NA
## --------------------------------------------------------
## : No Different than the National Average Payment
## : AS
## [1] NA
## --------------------------------------------------------
## : Not Available
## : AS
## [1] NA
## --------------------------------------------------------
## : Number of Cases Too Small
## : AS
## [1] NA
## --------------------------------------------------------
## : Greater than the National Average Payment
## : AZ
## [1] 19012.15
## --------------------------------------------------------
## : Less than the National Average Payment
## : AZ
## [1] 13673.56
## --------------------------------------------------------
## : No Different than the National Average Payment
## : AZ
## [1] 17926.23
## --------------------------------------------------------
## : Not Available
## : AZ
## [1] NA
## --------------------------------------------------------
## : Number of Cases Too Small
## : AZ
## [1] NA
## --------------------------------------------------------
## : Greater than the National Average Payment
## : CA
## [1] 19526.76
## --------------------------------------------------------
## : Less than the National Average Payment
## : CA
## [1] 14102.07
## --------------------------------------------------------
## : No Different than the National Average Payment
## : CA
## [1] 17927.4
## --------------------------------------------------------
## : Not Available
## : CA
## [1] NA
## --------------------------------------------------------
## : Number of Cases Too Small
## : CA
## [1] NA
## --------------------------------------------------------
## : Greater than the National Average Payment
## : CO
## [1] 19856.8
## --------------------------------------------------------
## : Less than the National Average Payment
## : CO
## [1] 14245.82
## --------------------------------------------------------
## : No Different than the National Average Payment
## : CO
## [1] 16897.44
## --------------------------------------------------------
## : Not Available
## : CO
## [1] NA
## --------------------------------------------------------
## : Number of Cases Too Small
## : CO
## [1] NA
## --------------------------------------------------------
## : Greater than the National Average Payment
## : CT
## [1] 18467.96
## --------------------------------------------------------
## : Less than the National Average Payment
## : CT
## [1] 13376
## --------------------------------------------------------
## : No Different than the National Average Payment
## : CT
## [1] 18478.34
## --------------------------------------------------------
## : Not Available
## : CT
## [1] NA
## --------------------------------------------------------
## : Number of Cases Too Small
## : CT
## [1] NA
## --------------------------------------------------------
## : Greater than the National Average Payment
## : DC
## [1] 19980
## --------------------------------------------------------
## : Less than the National Average Payment
## : DC
## [1] 14614
## --------------------------------------------------------
## : No Different than the National Average Payment
## : DC
## [1] 17993.81
## --------------------------------------------------------
## : Not Available
## : DC
## [1] NA
## --------------------------------------------------------
## : Number of Cases Too Small
## : DC
## [1] NA
## --------------------------------------------------------
## : Greater than the National Average Payment
## : DE
## [1] 19066.43
## --------------------------------------------------------
## : Less than the National Average Payment
## : DE
## [1] 14277
## --------------------------------------------------------
## : No Different than the National Average Payment
## : DE
## [1] 18641
## --------------------------------------------------------
## : Not Available
## : DE
## [1] NA
## --------------------------------------------------------
## : Number of Cases Too Small
## : DE
## [1] NA
## --------------------------------------------------------
## : Greater than the National Average Payment
## : FL
## [1] 18734.56
## --------------------------------------------------------
## : Less than the National Average Payment
## : FL
## [1] 15144.15
## --------------------------------------------------------
## : No Different than the National Average Payment
## : FL
## [1] 18339.71
## --------------------------------------------------------
## : Not Available
## : FL
## [1] NA
## --------------------------------------------------------
## : Number of Cases Too Small
## : FL
## [1] NA
## --------------------------------------------------------
## : Greater than the National Average Payment
## : GA
## [1] 17076
## --------------------------------------------------------
## : Less than the National Average Payment
## : GA
## [1] 14434.22
## --------------------------------------------------------
## : No Different than the National Average Payment
## : GA
## [1] 17038.91
## --------------------------------------------------------
## : Not Available
## : GA
## [1] NA
## --------------------------------------------------------
## : Number of Cases Too Small
## : GA
## [1] NA
## --------------------------------------------------------
## : Greater than the National Average Payment
## : GU
## [1] NA
## --------------------------------------------------------
## : Less than the National Average Payment
## : GU
## [1] 12149.67
## --------------------------------------------------------
## : No Different than the National Average Payment
## : GU
## [1] NA
## --------------------------------------------------------
## : Not Available
## : GU
## [1] NA
## --------------------------------------------------------
## : Number of Cases Too Small
## : GU
## [1] NA
## --------------------------------------------------------
## : Greater than the National Average Payment
## : HI
## [1] NA
## --------------------------------------------------------
## : Less than the National Average Payment
## : HI
## [1] 15432.78
## --------------------------------------------------------
## : No Different than the National Average Payment
## : HI
## [1] 16613.5
## --------------------------------------------------------
## : Not Available
## : HI
## [1] NA
## --------------------------------------------------------
## : Number of Cases Too Small
## : HI
## [1] NA
## --------------------------------------------------------
## : Greater than the National Average Payment
## : IA
## [1] 18486.14
## --------------------------------------------------------
## : Less than the National Average Payment
## : IA
## [1] 14022.19
## --------------------------------------------------------
## : No Different than the National Average Payment
## : IA
## [1] 16551.7
## --------------------------------------------------------
## : Not Available
## : IA
## [1] NA
## --------------------------------------------------------
## : Number of Cases Too Small
## : IA
## [1] NA
## --------------------------------------------------------
## : Greater than the National Average Payment
## : ID
## [1] 18422.67
## --------------------------------------------------------
## : Less than the National Average Payment
## : ID
## [1] 13592.5
## --------------------------------------------------------
## : No Different than the National Average Payment
## : ID
## [1] 16271.21
## --------------------------------------------------------
## : Not Available
## : ID
## [1] NA
## --------------------------------------------------------
## : Number of Cases Too Small
## : ID
## [1] NA
## --------------------------------------------------------
## : Greater than the National Average Payment
## : IL
## [1] 19709.63
## --------------------------------------------------------
## : Less than the National Average Payment
## : IL
## [1] 13980.79
## --------------------------------------------------------
## : No Different than the National Average Payment
## : IL
## [1] 17290.41
## --------------------------------------------------------
## : Not Available
## : IL
## [1] NA
## --------------------------------------------------------
## : Number of Cases Too Small
## : IL
## [1] NA
## --------------------------------------------------------
## : Greater than the National Average Payment
## : IN
## [1] 18901.9
## --------------------------------------------------------
## : Less than the National Average Payment
## : IN
## [1] 15603.47
## --------------------------------------------------------
## : No Different than the National Average Payment
## : IN
## [1] 17187.11
## --------------------------------------------------------
## : Not Available
## : IN
## [1] NA
## --------------------------------------------------------
## : Number of Cases Too Small
## : IN
## [1] NA
## --------------------------------------------------------
## : Greater than the National Average Payment
## : KS
## [1] 18664.09
## --------------------------------------------------------
## : Less than the National Average Payment
## : KS
## [1] 13865.12
## --------------------------------------------------------
## : No Different than the National Average Payment
## : KS
## [1] 16484.98
## --------------------------------------------------------
## : Not Available
## : KS
## [1] NA
## --------------------------------------------------------
## : Number of Cases Too Small
## : KS
## [1] NA
## --------------------------------------------------------
## : Greater than the National Average Payment
## : KY
## [1] 18545.82
## --------------------------------------------------------
## : Less than the National Average Payment
## : KY
## [1] 13187.05
## --------------------------------------------------------
## : No Different than the National Average Payment
## : KY
## [1] 17354.3
## --------------------------------------------------------
## : Not Available
## : KY
## [1] NA
## --------------------------------------------------------
## : Number of Cases Too Small
## : KY
## [1] NA
## --------------------------------------------------------
## : Greater than the National Average Payment
## : LA
## [1] 17996.38
## --------------------------------------------------------
## : Less than the National Average Payment
## : LA
## [1] 15541.38
## --------------------------------------------------------
## : No Different than the National Average Payment
## : LA
## [1] 17134.23
## --------------------------------------------------------
## : Not Available
## : LA
## [1] NA
## --------------------------------------------------------
## : Number of Cases Too Small
## : LA
## [1] NA
## --------------------------------------------------------
## : Greater than the National Average Payment
## : MA
## [1] 19177.19
## --------------------------------------------------------
## : Less than the National Average Payment
## : MA
## [1] 16682.38
## --------------------------------------------------------
## : No Different than the National Average Payment
## : MA
## [1] 17873.73
## --------------------------------------------------------
## : Not Available
## : MA
## [1] NA
## --------------------------------------------------------
## : Number of Cases Too Small
## : MA
## [1] NA
## --------------------------------------------------------
## : Greater than the National Average Payment
## : MD
## [1] NA
## --------------------------------------------------------
## : Less than the National Average Payment
## : MD
## [1] NA
## --------------------------------------------------------
## : No Different than the National Average Payment
## : MD
## [1] NA
## --------------------------------------------------------
## : Not Available
## : MD
## [1] NA
## --------------------------------------------------------
## : Number of Cases Too Small
## : MD
## [1] NA
## --------------------------------------------------------
## : Greater than the National Average Payment
## : ME
## [1] 20552
## --------------------------------------------------------
## : Less than the National Average Payment
## : ME
## [1] 15176.4
## --------------------------------------------------------
## : No Different than the National Average Payment
## : ME
## [1] 17161.68
## --------------------------------------------------------
## : Not Available
## : ME
## [1] NA
## --------------------------------------------------------
## : Number of Cases Too Small
## : ME
## [1] NA
## --------------------------------------------------------
## : Greater than the National Average Payment
## : MI
## [1] 18154.17
## --------------------------------------------------------
## : Less than the National Average Payment
## : MI
## [1] 14686.7
## --------------------------------------------------------
## : No Different than the National Average Payment
## : MI
## [1] 17030.3
## --------------------------------------------------------
## : Not Available
## : MI
## [1] NA
## --------------------------------------------------------
## : Number of Cases Too Small
## : MI
## [1] NA
## --------------------------------------------------------
## : Greater than the National Average Payment
## : MN
## [1] 19346.8
## --------------------------------------------------------
## : Less than the National Average Payment
## : MN
## [1] 14003.88
## --------------------------------------------------------
## : No Different than the National Average Payment
## : MN
## [1] 16028.23
## --------------------------------------------------------
## : Not Available
## : MN
## [1] NA
## --------------------------------------------------------
## : Number of Cases Too Small
## : MN
## [1] NA
## --------------------------------------------------------
## : Greater than the National Average Payment
## : MO
## [1] 18579.87
## --------------------------------------------------------
## : Less than the National Average Payment
## : MO
## [1] 14045.55
## --------------------------------------------------------
## : No Different than the National Average Payment
## : MO
## [1] 17288.05
## --------------------------------------------------------
## : Not Available
## : MO
## [1] NA
## --------------------------------------------------------
## : Number of Cases Too Small
## : MO
## [1] NA
## --------------------------------------------------------
## : Greater than the National Average Payment
## : MP
## [1] NA
## --------------------------------------------------------
## : Less than the National Average Payment
## : MP
## [1] 13827
## --------------------------------------------------------
## : No Different than the National Average Payment
## : MP
## [1] NA
## --------------------------------------------------------
## : Not Available
## : MP
## [1] NA
## --------------------------------------------------------
## : Number of Cases Too Small
## : MP
## [1] NA
## --------------------------------------------------------
## : Greater than the National Average Payment
## : MS
## [1] 20148.77
## --------------------------------------------------------
## : Less than the National Average Payment
## : MS
## [1] 14244
## --------------------------------------------------------
## : No Different than the National Average Payment
## : MS
## [1] 16124.33
## --------------------------------------------------------
## : Not Available
## : MS
## [1] NA
## --------------------------------------------------------
## : Number of Cases Too Small
## : MS
## [1] NA
## --------------------------------------------------------
## : Greater than the National Average Payment
## : MT