/
ejanalysis.html
7164 lines (5792 loc) · 471 KB
/
ejanalysis.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>
<head>
<title>Package 'ejanalysis' reference manual</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<!-- styling for math and syntax -->
<link rel="stylesheet" type="text/css" href="https://r-universe.dev/static/katex.min.css">
<link rel="stylesheet" type="text/css" href="https://r-universe.dev/static/R.css">
<link rel="stylesheet" type="text/css" href="https://r-universe.dev/static/prism.css">
<!-- for (future) customizations -->
<script src="https://r-universe.dev/static/manual.js"></script>
<link rel="stylesheet" type="text/css" href="https://r-universe.dev/static/manual.css?nocache=1">
</head>
<body class="macintosh">
<h1 class="manual-title">Package 'ejanalysis'</h1>
<table class="description-table">
<tr>
<th>Title:</th>
<td class="description-title">Tools for Environmental Justice (EJ) Analysis</td>
</tr>
<tr>
<th>Description:</th>
<td class="description-description">Tools that simplify some basic tasks in exploring and analyzing
a dataset in a matrix or data.frame that contains data on demographics
(e.g., counts of residents in poverty) and local environmental indicators
(e.g., an air quality index), with one row per spatial location (e.g., Census
block group). Key functions help to find relative risk or similar ratios of
means in demographic groups, etc.
For any imported/suggested packages not on CRAN, see http://ejanalysis.github.io</td>
</tr>
<tr>
<th>Authors:</th>
<td class="description-author"><span>info@ejanalysis.com</span></td>
</tr>
<tr>
<th>Maintainer:</th>
<td class="description-maintainer">info@ejanalysis.com <info@ejanalysis.com></td>
</tr>
<tr>
<th>License:</th>
<td class="description-license">MIT + file LICENSE</td>
</tr>
<tr>
<th>Version:</th>
<td class="description-version">2.1.1</td>
</tr>
<tr>
<th>Built:</th>
<td class="description-date">2023-04-28 19:27:47 UTC</td>
</tr>
<tr>
<th>Source:</th>
<td class="description-source">GitHub</td>
</tr>
</table>
<a href="#help-index" style="color:black;"><h2 id="help-index">Help Index</h2></a>
<ul id="help-index-list">
<li class="help-index-item"><a href="#addFIPScomponents">Add col for each component of longer FIPS</a></li>
<li class="help-index-item"><a href="#assign.map.bins">Assign Each Row (Place) to a Bin Based on Cutpoints</a></li>
<li class="help-index-item"><a href="#assign.pctiles">Assign percentiles to vector of values (weighted, by zone)</a></li>
<li class="help-index-item"><a href="#assign.pctiles.alt2">Assign percentiles to values (alternative formula, and not by zone)</a></li>
<li class="help-index-item"><a href="#bgtest">Test dataset for ejanalysis</a></li>
<li class="help-index-item"><a href="#clean.fips">Clean up US Census FIPS (Add Missing Leading Zeroes)</a></li>
<li class="help-index-item"><a href="#clean.fips1215">Check and clean Census block group or block FIPS - only check number of characters and if NA, not if valid number otherwise</a></li>
<li class="help-index-item"><a href="#ej.added">Contribution of each place to net excess people-points in demographic group</a></li>
<li class="help-index-item"><a href="#ej.indexes">Calculate environmental justice (EJ) index for each place</a></li>
<li class="help-index-item"><a href="#ejanalysis">Tools for Environmental Justice (EJ) Analysis</a></li>
<li class="help-index-item"><a href="#ejRRadded">Formulas for local contributions to EJ metrics</a></li>
<li class="help-index-item"><a href="#flagged">Which rows have a value above cutoff in at least one column</a></li>
<li class="help-index-item"><a href="#flagged.by">flagged.by</a></li>
<li class="help-index-item"><a href="#flagged.only.by">flagged.only.by</a></li>
<li class="help-index-item"><a href="#geofips">Convert between FIPS / ANSI codes and Names of U.S. Geographies</a></li>
<li class="help-index-item"><a href="#geotype">Infer Type of Data as FIPS / ANSI Codes or Names of U.S. Geographies</a></li>
<li class="help-index-item"><a href="#get.county.info">Get info on US Counties</a></li>
<li class="help-index-item"><a href="#get.epa.region">Identify EPA Region for given state (or FIPS)</a></li>
<li class="help-index-item"><a href="#get.fips.bg">Get Census block group FIPS from block or block group FIPS</a></li>
<li class="help-index-item"><a href="#get.fips.county">Get County FIPS from block or block group FIPS</a></li>
<li class="help-index-item"><a href="#get.fips.etc">Get tract, county, state, region info from US Census block group FIPS codes (unused?)</a></li>
<li class="help-index-item"><a href="#get.fips.st">Get State FIPS from block or block group FIPS</a></li>
<li class="help-index-item"><a href="#get.fips.tract">Get Census tract FIPS from block or block group FIPS</a></li>
<li class="help-index-item"><a href="#get.name.county">Extract county name from Census geo name field</a></li>
<li class="help-index-item"><a href="#get.name.state">Extract state name from Census geo name field</a></li>
<li class="help-index-item"><a href="#get.pctile">Determine (Weighted) Percentiles</a></li>
<li class="help-index-item"><a href="#get.state.info">Get information on U.S. State(s)</a></li>
<li class="help-index-item"><a href="#KolmPollak">Kolm-Pollak Inequality Index adjustable for indexing inequality in bad outcomes</a></li>
<li class="help-index-item"><a href="#lookup.pctile">Find approx wtd percentiles in lookup table that is in memory</a></li>
<li class="help-index-item"><a href="#make.bin.cols">Create a Bin Numbers Column for each Percentiles Column</a></li>
<li class="help-index-item"><a href="#make.bin.pctile.cols">Weighted Percentiles and Bin Numbers for Each Column, by zone, such as percentiles within each State</a></li>
<li class="help-index-item"><a href="#make.bin.pctile.cols.byzone">May be obsolete-not used -was Percentile and bin number fields, by zone, such as percentiles within each State</a></li>
<li class="help-index-item"><a href="#make.pctile.cols">Make columns of (weighted) percentiles from columns of values</a></li>
<li class="help-index-item"><a href="#make.pctile.cols.alt2">Alternative way to make columns of (weighted) percentiles from columns of values</a></li>
<li class="help-index-item"><a href="#names.d">Fieldnames of demographic columns in ejscreen data</a></li>
<li class="help-index-item"><a href="#names.e">Fieldnames of environmental indicator columns in ejscreen data</a></li>
<li class="help-index-item"><a href="#names.ej">Fieldnames of EJ index columns in ejscreen data</a></li>
<li class="help-index-item"><a href="#narrativeprofile">Get County or Tract Narrative Profile webpage from Census</a></li>
<li class="help-index-item"><a href="#pct.moe">Margin of Error for a Percent (Ratio)</a></li>
<li class="help-index-item"><a href="#plot_3_by_distance">create plot of 3 indicators versus distance
This makes a very simple scatter plot of 3 variables on y axis
as a function of distance on the x axis.
For example, it can show risk, percent demographic score, and population
density, e.g., using numbers created at random by sim_riskbydistance()</a></li>
<li class="help-index-item"><a href="#pop.cdf">Draw PDF (overlays histograms) comparing distributions of scores in selected demographic groups</a></li>
<li class="help-index-item"><a href="#pop.cdf.density">Overlay 2 PDFs as Weighted Histograms</a></li>
<li class="help-index-item"><a href="#pop.cdf2">Overlay Two PDFs as Weighted Histograms</a></li>
<li class="help-index-item"><a href="#pop.ecdf">Draw an Ecdf plot comparing distributions of scores in selected demographic groups</a></li>
<li class="help-index-item"><a href="#pop.ecdf.dd">Draw an Ecdf plot showing the distribution of scores in each demographic subgroup</a></li>
<li class="help-index-item"><a href="#rollup">Aggregate multiple columns of values by group</a></li>
<li class="help-index-item"><a href="#rollup.pct">Calculate a/b for each Subset</a></li>
<li class="help-index-item"><a href="#RR">Relative Risk (RR) by demographic group by indicator based on Census data</a></li>
<li class="help-index-item"><a href="#RR.cut.if.gone">How much is overal RR reduced if a given place did not exist?</a></li>
<li class="help-index-item"><a href="#RR.if.address.top.x">Analyze how much RR would change if top-ranked places were addressed - ** NOT WORKING/ IN PROGRESS</a></li>
<li class="help-index-item"><a href="#RR.means">Relative Risk (RR) components - Means in demographic group and in rest of pop, based on Census data</a></li>
<li class="help-index-item"><a href="#RR.plot">Draw lineplot comparing RR values by group</a></li>
<li class="help-index-item"><a href="#RR.plotbar">Draw barplot comparing mean score in a group vs reference group</a></li>
<li class="help-index-item"><a href="#RR.table">Table of Relative Risk results by zone by group by envt risk factor</a></li>
<li class="help-index-item"><a href="#RR.table.add">Merge tables of Relative Risk results</a></li>
<li class="help-index-item"><a href="#RR.table.addmaxzone">Add to an existing RR.table the max relative risk value from any zone in the table
This function adds RR values from the max zone but RR.table already does this.</a></li>
<li class="help-index-item"><a href="#RR.table.max">See which group and risk indicator (in zone) have max values in RR table</a></li>
<li class="help-index-item"><a href="#RR.table.sort">Sort table of Relative Risk results by zone by group by envt risk factor</a></li>
<li class="help-index-item"><a href="#RR.table.view">Just print Relative Risks (RR) info by demog group by risk type by zone</a></li>
<li class="help-index-item"><a href="#RR.table.vs.us">Relative Risks (RR) in zones as ratios to US values</a></li>
<li class="help-index-item"><a href="#rrf">RR for one environmental indicator, one demographic group</a></li>
<li class="help-index-item"><a href="#rrfv">Vectorized version of rrf (relative risk) - **not tested, possibly obsolete</a></li>
<li class="help-index-item"><a href="#scatterEJ_D_E">scatterplot EJScreen Demog vs Envt vs EJ Index
See one point per blockgroup, x=demog pctile, y=envt pctile, color=EJ pctile</a></li>
<li class="help-index-item"><a href="#sim_plotratios">create plot of ratios indicating disparity, from sim_riskbydistance output</a></li>
<li class="help-index-item"><a href="#sim_riskbydistance">Simulate disparities as risk, pop density, and demographics vary by distance</a></li>
<li class="help-index-item"><a href="#state.health.url">Get URL(s) with State health indicator data from RWJF - ** url scheme obsolete now so needs to be redone</a></li>
<li class="help-index-item"><a href="#sumoe">Margin of Error for a Sum</a></li>
<li class="help-index-item"><a href="#url.census">See webpage with data on Census units from American Fact Finder - may not be used</a></li>
<li class="help-index-item"><a href="#url.censusblock">See webpage with data on Census block(s)</a></li>
<li class="help-index-item"><a href="#url.open">Launch a web browser to go to a URL, like browseURL does</a></li>
<li class="help-index-item"><a href="#url.qf">US Census Quickfacts Webpage URL</a></li>
<li class="help-index-item"><a href="#worstd">Demographic groups with worst RR</a></li>
<li class="help-index-item"><a href="#worste">Environmental indicators with worst RR</a></li>
<li class="help-index-item"><a href="#worstplaces">Places with worst RR</a></li>
<li class="help-index-item"><a href="#write.pctiles">Write csv file lookup table - percentiles, mean, standard deviation</a></li>
<li class="help-index-item"><a href="#write.pctiles.by.zone">create lookup table as file of percentiles, mean, sd by state or region</a></li>
<li class="help-index-item"><a href="#write.RR.tables">Save RR tables to disk, one per zone.</a></li>
<li class="help-index-item"><a href="#write.wtd.pctiles">create lookup table as file of pop-weighted percentiles, mean, std.dev</a></li>
<li class="help-index-item"><a href="#write.wtd.pctiles.by.zone">create lookup table as file of pop-weighted or unwtd percentiles, mean, sd for US or by state or region</a></li>
</ul>
<hr>
<div class="manual-pages-content">
<div class="container manual-page" id="addFIPScomponents">
<a href="#addFIPScomponents" class="help-page-title"><h2>Add col for each component of longer FIPS</h2></a>
<h3>Description</h3>
<p>Given a data.frame with FIPS col that is the full state county tract blockgroup FIPS
returns the data.frame with extra columns up front, with components of FIPS.
</p>
<h3>Usage</h3>
<pre class="language-r"><code class="language-r">addFIPScomponents<span class="token punctuation">(</span>bg<span class="token punctuation">,</span> fipscolname <span class="token operator">=</span> <span class="token string">"FIPS"</span><span class="token punctuation">,</span> clean <span class="token operator">=</span> <span class="token boolean">TRUE</span><span class="token punctuation">)</span></code></pre>
<h3>Arguments</h3>
<table>
<tr style="vertical-align: top;">
<td><code>bg</code></td>
<td>
<p>Data.frame with a character column called FIPS (or specified otherwise)</p>
</td>
</tr>
<tr style="vertical-align: top;">
<td><code>fipscolname</code></td>
<td>
<p>FIPS by default but could specify some other name to be found as col in bg</p>
</td>
</tr>
<tr style="vertical-align: top;">
<td><code>clean</code></td>
<td>
<p>Does not use clean.fips() if FALSE, which helps if the countiesall or other list is not yet updated, for example and lacks some new FIPS code</p>
</td>
</tr>
</table>
<h3>Value</h3>
<p>Returns the whole data.frame with new columns in front:
'FIPS', 'FIPS.TRACT', 'FIPS.COUNTY', 'FIPS.ST', 'ST', 'statename', 'REGION'
</p>
<hr>
</div>
<div class="container manual-page" id="assign.map.bins">
<a href="#assign.map.bins" class="help-page-title"><h2>Assign Each Row (Place) to a Bin Based on Cutpoints</h2></a>
<h3>Description</h3>
<p>Takes a vector (not matrix or df) of values and returns a vector of bin numbers.
For creating color-coded maps (choropleths), assign each place (e.g., each row of a single column) to a bin.
Each bin represents one map color, and is defined by cutoff values.
</p>
<h3>Usage</h3>
<pre class="language-r"><code class="language-r">assign.map.bins<span class="token punctuation">(</span>
pctiles.vector<span class="token punctuation">,</span>
cutpoints <span class="token operator">=</span> c<span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token operator">:</span><span class="token number">9</span><span class="token punctuation">)</span><span class="token operator">/</span><span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">0.95</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
labels <span class="token operator">=</span> <span class="token number">1</span><span class="token operator">:</span><span class="token number">11</span>
<span class="token punctuation">)</span></code></pre>
<h3>Arguments</h3>
<table>
<tr style="vertical-align: top;">
<td><code>pctiles.vector</code></td>
<td>
<p>Vector of percentiles as decimal fractions, 0 to 1, one per place.</p>
</td>
</tr>
<tr style="vertical-align: top;">
<td><code>cutpoints</code></td>
<td>
<p>Optional vector of cutpoints defining edges of bins. Default is every 0.10 from 0 to 1.00, as well as 0.95</p>
</td>
</tr>
<tr style="vertical-align: top;">
<td><code>labels</code></td>
<td>
<p>vector of bin numbers, optional (default is 1 through 11, and NA values are put in bin 0).</p>
</td>
</tr>
</table>
<h3>Details</h3>
<p>The default bins 0-11 are defined as follows: <br>
bin 0: PCTILE=NA <br>
... <br>
bin 9: 0.80<=PCTILE<0.90 <br>
bin 10: 0.90<=PCTILE<0.95 <br>
bin 11: 0.95<=PCTILE<=1.00 <br></p>
<h3>Value</h3>
<p>Returns a vector bin numbers.
</p>
<h3>See Also</h3>
<p><code><a href="#make.bin.pctile.cols">make.bin.pctile.cols</a></code> to call functions below, converting columns of values to percentiles and then bins <br><code><a href="#assign.pctiles">assign.pctiles</a></code> for one vector, assign (weighted) percentile (quantile) to each value within its zone (subset) <br><code><a href="#assign.pctiles.alt2">assign.pctiles.alt2</a></code> as an alternative method, to replicate assign.pctiles, but not by zone <br><code><a href="#get.pctile">get.pctile</a></code> to get (weighted) percentile of just 1+ values within given vector of values <br><code><a href="#make.pctile.cols">make.pctile.cols</a></code> for a data.frame, assign percentiles, return a same-sized df that is wtd.quantile of each value within its column <br><code><a href="#make.pctile.cols.alt2">make.pctile.cols.alt2</a></code> as an alternative method, to replicate make.pctile.cols <br><code><a href="#assign.map.bins">assign.map.bins</a></code> for one vector (or data.frame) of values (e.g. percentiles), return same-sized df that is bin number (map color bin) using preset breaks. <br><code><a href="#make.bin.cols">make.bin.cols</a></code> for a data.frame of values (e.g. percentiles), return same-sized df that is bin number (map color bin) using preset breaks. <br><code><a href="#write.pctiles">write.pctiles</a></code> to save file that is lookup table of percentiles for columns of a data.frame <br><code><a href="#write.pctiles.by.zone">write.pctiles.by.zone</a></code> to save file that is lookup table of percentiles for columns of a data.frame, for each geographic zone (subset of rows) <br><code><a href="#write.wtd.pctiles">write.wtd.pctiles</a></code> to save file that is lookup table of weighted percentiles for columns of a data.frame <br><code><a href="#write.wtd.pctiles.by.zone">write.wtd.pctiles.by.zone</a></code> to save file that is lookup table of weighted percentiles for columns of a data.frame, for each geographic zone (subset of rows) <br><code><a href="#lookup.pctile">lookup.pctile</a></code> to look up current approx weighted percentiles in a lookup table that is already in global memory <br></p>
<h3>Examples</h3>
<pre class="language-r"><code class="language-r">junk<span class="token operator"><-</span>c<span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span><span class="token number">0.799</span><span class="token punctuation">,</span><span class="token number">0.8</span><span class="token punctuation">,</span> <span class="token number">0.8000001</span><span class="token punctuation">,</span> <span class="token number">0.8999999</span><span class="token punctuation">,</span><span class="token number">0.95</span><span class="token punctuation">,</span><span class="token number">0.95001</span><span class="token punctuation">,</span><span class="token number">1</span><span class="token punctuation">)</span>
data.frame<span class="token punctuation">(</span>pctile<span class="token operator">=</span>junk<span class="token punctuation">,</span> bin<span class="token operator">=</span>assign.map.bins<span class="token punctuation">(</span>junk<span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token comment"># How it puts these in bins by default:</span>
<span class="token comment"># pctile bin notes</span>
<span class="token comment">#1 0.0000000 1</span>
<span class="token comment">#2 0.7990000 8</span>
<span class="token comment">#</span>
<span class="token comment">#3 0.8000000 9 (0.80<=PCTILE<0.90 )</span>
<span class="token comment">#4 0.8000001 9 (0.80<=PCTILE<0.90 )</span>
<span class="token comment">#5 0.8999999 9 (0.80<=PCTILE<0.90 )</span>
<span class="token comment">#</span>
<span class="token comment">#6 0.9000000 10 (0.90<=PCTILE<0.95 )</span>
<span class="token comment">#7 0.9001000 10 (0.90<=PCTILE<0.95 )</span>
<span class="token comment">#8 0.9499990 10 (0.90<=PCTILE<0.95 )</span>
<span class="token comment">#</span>
<span class="token comment">#9 0.9500000 11 (0.95<=PCTILE<=1.00 ) I.E. THIS INCLUDES 100th percentile</span>
<span class="token comment">#10 0.9500100 11 (0.95<=PCTILE<=1.00 ) I.E. THIS INCLUDES 100th percentile</span>
<span class="token comment">#11 1.0000000 11 (0.95<=PCTILE<=1.00 ) I.E. THIS INCLUDES 100th percentile</span></code></pre>
<hr>
</div>
<div class="container manual-page" id="assign.pctiles">
<a href="#assign.pctiles" class="help-page-title"><h2>Assign percentiles to vector of values (weighted, by zone)</h2></a>
<h3>Description</h3>
<p>For the vector, look at the distribution of values across all rows in a given zone (e.g., places in zone),
and find what percentile a given value is at.
</p>
<h3>Usage</h3>
<pre class="language-r"><code class="language-r">assign.pctiles<span class="token punctuation">(</span>values<span class="token punctuation">,</span> weights <span class="token operator">=</span> <span class="token keyword">NULL</span><span class="token punctuation">,</span> zone <span class="token operator">=</span> <span class="token keyword">NULL</span><span class="token punctuation">,</span> na.rm <span class="token operator">=</span> <span class="token boolean">TRUE</span><span class="token punctuation">)</span></code></pre>
<h3>Arguments</h3>
<table>
<tr style="vertical-align: top;">
<td><code>values</code></td>
<td>
<p>vector, required, with numeric values. To do this with a matrix, see <code><a href="#make.pctile.cols">make.pctile.cols()</a></code></p>
</td>
</tr>
<tr style="vertical-align: top;">
<td><code>weights</code></td>
<td>
<p>Optional, NULL by default (not fully tested), vector of weights for weighted percentiles (e.g., population weighted).</p>
</td>
</tr>
<tr style="vertical-align: top;">
<td><code>zone</code></td>
<td>
<p>Optional, NULL by default, defines subsets of rows, so a percentile is found among rows that are within a given zone only.</p>
</td>
</tr>
<tr style="vertical-align: top;">
<td><code>na.rm</code></td>
<td>
<p>NOT IMPLEMENTED HERE. Logical, optional, TRUE by default. Should NA values (missing data) be removed first to get percentile of those with valid data.
If FALSE, NA values are treated as being at the high percentiles.</p>
</td>
</tr>
</table>
<h3>Details</h3>
<p>Relies on the <code><a href="https://harrelfe.r-universe.dev/manual/Hmisc.html#wtd.stats">Hmisc::wtd.Ecdf()</a></code> function.
COULD BE RECODED TO BE FASTER USING data.table package *** see notes in <code><a href="#rollup.pct">rollup.pct()</a></code> and <code><a href="#rollup">rollup()</a></code>
Could also add parameter like in rank(), na.last,
defining na.rm but also where to rank NA values if included, etc.
</p>
<p>Default now is like na.last=NA, but like na.last='last' if na.rm=FALSE
</p>
<p>****Could also add parameter like in rank(), ties.method, defining if ties get min, max, or mean of percentiles initially assigned to ties.
Default for ties up to mid2022 was like ties.method=max ?
But EJScreen will redefine percentiles to set tied values at lower end of that group, min
</p>
<h3>Value</h3>
<p>Returns a numeric vector same size as x, but if zone is specified, provides percentile with given zone.
</p>
<h3>See Also</h3>
<p><code><a href="#make.bin.pctile.cols">make.bin.pctile.cols</a></code> to call functions below, converting columns of values to percentiles and then bins <br><code><a href="#assign.pctiles">assign.pctiles</a></code> for one vector, assign (weighted) percentile (quantile) to each value within its zone (subset) <br><code><a href="#assign.pctiles.alt2">assign.pctiles.alt2</a></code> as an alternative method, to replicate assign.pctiles, but not by zone <br><code><a href="#get.pctile">get.pctile</a></code> to get (weighted) percentile of just 1+ values within given vector of values <br><code><a href="#make.pctile.cols">make.pctile.cols</a></code> for a data.frame, assign percentiles, return a same-sized df that is wtd.quantile of each value within its column <br><code><a href="#make.pctile.cols.alt2">make.pctile.cols.alt2</a></code> as an alternative method, to replicate make.pctile.cols <br><code><a href="#assign.map.bins">assign.map.bins</a></code> for one vector (or data.frame) of values (e.g. percentiles), return same-sized df that is bin number (map color bin) using preset breaks. <br><code><a href="#make.bin.cols">make.bin.cols</a></code> for a data.frame of values (e.g. percentiles), return same-sized df that is bin number (map color bin) using preset breaks. <br><code><a href="#write.pctiles">write.pctiles</a></code> to save file that is lookup table of percentiles for columns of a data.frame <br><code><a href="#write.pctiles.by.zone">write.pctiles.by.zone</a></code> to save file that is lookup table of percentiles for columns of a data.frame, for each geographic zone (subset of rows) <br><code><a href="#write.wtd.pctiles">write.wtd.pctiles</a></code> to save file that is lookup table of weighted percentiles for columns of a data.frame <br><code><a href="#write.wtd.pctiles.by.zone">write.wtd.pctiles.by.zone</a></code> to save file that is lookup table of weighted percentiles for columns of a data.frame, for each geographic zone (subset of rows) <br><code><a href="#lookup.pctile">lookup.pctile</a></code> to look up current approx weighted percentiles in a lookup table that is already in global memory <br></p>
<h3>Examples</h3>
<pre class="language-r"><code class="language-r">x <span class="token operator"><-</span> c<span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">,</span><span class="token number">12</span><span class="token punctuation">,</span><span class="token number">5</span><span class="token punctuation">,</span><span class="token number">5</span><span class="token punctuation">,</span><span class="token number">13</span><span class="token punctuation">,</span><span class="token number">13</span><span class="token punctuation">,</span><span class="token number">13</span><span class="token punctuation">,</span><span class="token number">13</span><span class="token punctuation">,</span><span class="token number">13</span><span class="token punctuation">,</span><span class="token number">8</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">10</span><span class="token operator">:</span><span class="token number">20</span><span class="token punctuation">,</span><span class="token number">20</span><span class="token punctuation">,</span><span class="token number">20</span><span class="token punctuation">,</span><span class="token number">20</span><span class="token punctuation">,</span><span class="token number">21</span><span class="token operator">:</span><span class="token number">30</span><span class="token punctuation">)</span>
wts <span class="token operator"><-</span> rep<span class="token punctuation">(</span>c<span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">,</span> length<span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token operator">/</span><span class="token number">2</span><span class="token punctuation">)</span>
cbind<span class="token punctuation">(</span>wts<span class="token punctuation">,</span> x<span class="token punctuation">,</span> PCTILE<span class="token operator">=</span>assign.pctiles<span class="token punctuation">(</span>x<span class="token punctuation">,</span>wts<span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token comment"># PERCENTILE OF ALL, NOT JUST THOSE WITH VALID DATA, IF na.rm=FALSE,</span>
<span class="token comment"># but then NA values preclude high percentiles:</span>
x <span class="token operator"><-</span> c<span class="token punctuation">(</span><span class="token keyword">NA</span><span class="token punctuation">,</span> <span class="token keyword">NA</span><span class="token punctuation">,</span> <span class="token keyword">NA</span><span class="token punctuation">,</span> <span class="token keyword">NA</span><span class="token punctuation">,</span><span class="token keyword">NA</span><span class="token punctuation">,</span><span class="token keyword">NA</span><span class="token punctuation">,</span><span class="token keyword">NA</span><span class="token punctuation">,</span><span class="token keyword">NA</span><span class="token punctuation">,</span><span class="token keyword">NA</span><span class="token punctuation">,</span><span class="token keyword">NA</span><span class="token punctuation">,</span><span class="token number">13</span><span class="token punctuation">,</span><span class="token number">13</span><span class="token punctuation">,</span><span class="token number">8</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">10</span><span class="token operator">:</span><span class="token number">20</span><span class="token punctuation">,</span><span class="token number">20</span><span class="token punctuation">,</span><span class="token number">20</span><span class="token punctuation">,</span><span class="token number">20</span><span class="token punctuation">,</span><span class="token number">21</span><span class="token operator">:</span><span class="token number">30</span><span class="token punctuation">)</span>
wts <span class="token operator"><-</span> rep<span class="token punctuation">(</span>c<span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">,</span> length<span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token operator">/</span><span class="token number">2</span><span class="token punctuation">)</span>
cbind<span class="token punctuation">(</span>wts<span class="token punctuation">,</span> x<span class="token punctuation">,</span> PCTILE.alt2<span class="token operator">=</span>assign.pctiles.alt2<span class="token punctuation">(</span>x<span class="token punctuation">,</span> wts<span class="token punctuation">,</span> na.rm<span class="token operator">=</span><span class="token boolean">FALSE</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
pctile<span class="token operator">=</span>assign.pctiles<span class="token punctuation">(</span>x<span class="token punctuation">,</span>wts<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">[</span>order<span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token punctuation">]</span>
cbind<span class="token punctuation">(</span>wts<span class="token punctuation">,</span> x<span class="token punctuation">,</span> PCTILE.alt2<span class="token operator">=</span>assign.pctiles.alt2<span class="token punctuation">(</span>x<span class="token punctuation">,</span> wts<span class="token punctuation">,</span> na.rm<span class="token operator">=</span><span class="token boolean">TRUE</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
pctile<span class="token operator">=</span>assign.pctiles<span class="token punctuation">(</span>x<span class="token punctuation">,</span>wts<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">[</span>order<span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token punctuation">]</span>
V<span class="token operator">=</span><span class="token number">9</span>
sum<span class="token punctuation">(</span>wts<span class="token punctuation">[</span><span class="token operator">!</span>is.na<span class="token punctuation">(</span>x<span class="token punctuation">)</span> <span class="token operator">&</span> x <span class="token operator"><=</span> V<span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token operator">/</span> sum<span class="token punctuation">(</span>wts<span class="token punctuation">[</span><span class="token operator">!</span>is.na<span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
<span class="token comment">#A value (V) being at this PCTILE% means that (assuming na.rm=TRUE):</span>
<span class="token comment"># V >= x for PCTILE% of wts (for non-NA x), so</span>
<span class="token comment"># V < x for 100% - PCTILE% of wts (for non-NA x), or</span>
<span class="token comment"># PCTILE% of all wts have V >= x (for non-NA x), so</span>
<span class="token comment"># 100% - PCTILE% of all wts have V < x (for non-NA x).</span>
x <span class="token operator"><-</span> c<span class="token punctuation">(</span><span class="token number">32</span><span class="token punctuation">,</span> <span class="token keyword">NA</span><span class="token punctuation">,</span> <span class="token keyword">NA</span><span class="token punctuation">,</span> <span class="token keyword">NA</span><span class="token punctuation">,</span><span class="token keyword">NA</span><span class="token punctuation">,</span><span class="token keyword">NA</span><span class="token punctuation">,</span><span class="token keyword">NA</span><span class="token punctuation">,</span><span class="token keyword">NA</span><span class="token punctuation">,</span><span class="token keyword">NA</span><span class="token punctuation">,</span><span class="token keyword">NA</span><span class="token punctuation">,</span><span class="token number">13</span><span class="token punctuation">,</span><span class="token number">13</span><span class="token punctuation">,</span><span class="token number">8</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">10</span><span class="token operator">:</span><span class="token number">20</span><span class="token punctuation">,</span><span class="token number">20</span><span class="token punctuation">,</span><span class="token keyword">NA</span><span class="token punctuation">,</span><span class="token number">20</span><span class="token punctuation">,</span><span class="token number">21</span><span class="token operator">:</span><span class="token number">30</span><span class="token punctuation">)</span>
wts <span class="token operator"><-</span> rep<span class="token punctuation">(</span>c<span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">,</span> length<span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token operator">/</span><span class="token number">2</span><span class="token punctuation">)</span>
cbind<span class="token punctuation">(</span>wts<span class="token punctuation">,</span> x<span class="token punctuation">,</span> PCTILE.alt2<span class="token operator">=</span>assign.pctiles.alt2<span class="token punctuation">(</span>x<span class="token punctuation">,</span> wts<span class="token punctuation">,</span> na.rm<span class="token operator">=</span><span class="token boolean">FALSE</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
pctile<span class="token operator">=</span>assign.pctiles<span class="token punctuation">(</span>x<span class="token punctuation">,</span>wts<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">[</span>order<span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token punctuation">]</span>
cbind<span class="token punctuation">(</span>wts<span class="token punctuation">,</span> x<span class="token punctuation">,</span> PCTILE.alt2<span class="token operator">=</span>assign.pctiles.alt2<span class="token punctuation">(</span>x<span class="token punctuation">,</span> wts<span class="token punctuation">,</span> na.rm<span class="token operator">=</span><span class="token boolean">TRUE</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
pctile<span class="token operator">=</span>assign.pctiles<span class="token punctuation">(</span>x<span class="token punctuation">,</span>wts<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">[</span>order<span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token punctuation">]</span>
<span class="token comment">## Not run: </span>
What is environmental score at given percentile?
ejanalysis<span class="token operator">::</span>lookup.pctile<span class="token punctuation">(</span><span class="token number">40</span><span class="token punctuation">,</span><span class="token string">'cancer'</span><span class="token punctuation">,</span>lookupUSA<span class="token punctuation">)</span>
<span class="token comment"># [1] 84</span>
ejanalysis<span class="token operator">::</span>lookup.pctile<span class="token punctuation">(</span><span class="token number">40</span><span class="token punctuation">,</span><span class="token string">'cancer'</span><span class="token punctuation">,</span>lookupStates<span class="token punctuation">,</span><span class="token string">'WV'</span><span class="token punctuation">)</span>
<span class="token comment"># [1] 93</span>
<span class="token comment"># What is percentile of given environmental score?</span>
ejscreen<span class="token operator">::</span>lookupUSA<span class="token punctuation">[</span>lookupUSA<span class="token operator">$</span>PCTILE<span class="token operator">==</span><span class="token string">'84'</span> <span class="token punctuation">,</span><span class="token string">'cancer'</span><span class="token punctuation">]</span>
<span class="token comment"># [1] 39.83055</span>
ejscreen<span class="token operator">::</span>lookupStates<span class="token punctuation">[</span>lookupStates<span class="token operator">$</span>PCTILE<span class="token operator">==</span><span class="token string">'84'</span> <span class="token operator">&</span> lookupStates<span class="token operator">$</span>REGION <span class="token operator">==</span><span class="token string">'WV'</span><span class="token punctuation">,</span><span class="token string">'cancer'</span><span class="token punctuation">]</span>
<span class="token comment"># [1] 33.36371</span>
<span class="token comment">## End(Not run)</span></code></pre>
<hr>
</div>
<div class="container manual-page" id="assign.pctiles.alt2">
<a href="#assign.pctiles.alt2" class="help-page-title"><h2>Assign percentiles to values (alternative formula, and not by zone)</h2></a>
<h3>Description</h3>
<p>For each column look at the distribution of values across all rows,
and find what percentile a given value is at.
</p>
<h3>Usage</h3>
<pre class="language-r"><code class="language-r">assign.pctiles.alt2<span class="token punctuation">(</span>x<span class="token punctuation">,</span> weights <span class="token operator">=</span> <span class="token keyword">NULL</span><span class="token punctuation">,</span> na.rm <span class="token operator">=</span> <span class="token boolean">TRUE</span><span class="token punctuation">,</span> zone <span class="token operator">=</span> <span class="token keyword">NULL</span><span class="token punctuation">)</span></code></pre>
<h3>Arguments</h3>
<table>
<tr style="vertical-align: top;">
<td><code>x</code></td>
<td>
<p>vector or data.frame</p>
</td>
</tr>
<tr style="vertical-align: top;">
<td><code>weights</code></td>
<td>
<p>Optional, NULL by default (not fully tested), vector of weights for weighted percentiles (e.g., population weighted).</p>
</td>
</tr>
<tr style="vertical-align: top;">
<td><code>na.rm</code></td>
<td>
<p>Logical, optional, TRUE by default. Should NA values (missing data) be removed first to get percentile of those with valid data.
If FALSE, NA values are treated as being at the high percentiles.</p>
</td>
</tr>
<tr style="vertical-align: top;">
<td><code>zone</code></td>
<td>
<p>Optional, NULL by default, *** not yet implemented here.</p>
</td>
</tr>
</table>
<h3>Details</h3>
<p>Assign percentile as cumulative sum of (the weights ranked by the value x).
Then fixes ties.
# Could also add parameter like in rank(), na.last,
defining na.rm but also where to rank NA values if included, etc.
Default now is like na.last=NA, but like na.last='last' if na.rm=FALSE
Could also add parameter like in rank(), ties.method, defining if ties get min, max, or mean of percentiles initially assigned to ties.
Default for ties right now is like ties.method=max (which might not be what assign.pctiles() does in fact).
</p>
<h3>Value</h3>
<p>Returns a numeric vector or data.frame same size as x.
</p>
<h3>See Also</h3>
<p><code><a href="#make.bin.pctile.cols">make.bin.pctile.cols</a></code> to call functions below, converting columns of values to percentiles and then bins <br><code><a href="#assign.pctiles">assign.pctiles</a></code> for one vector, assign (weighted) percentile (quantile) to each value within its zone (subset) <br><code><a href="#assign.pctiles.alt2">assign.pctiles.alt2</a></code> as an alternative method, to replicate assign.pctiles, but not by zone <br><code><a href="#get.pctile">get.pctile</a></code> to get (weighted) percentile of just 1+ values within given vector of values <br><code><a href="#make.pctile.cols">make.pctile.cols</a></code> for a data.frame, assign percentiles, return a same-sized df that is wtd.quantile of each value within its column <br><code><a href="#make.pctile.cols.alt2">make.pctile.cols.alt2</a></code> as an alternative method, to replicate make.pctile.cols <br><code><a href="#assign.map.bins">assign.map.bins</a></code> for one vector (or data.frame) of values (e.g. percentiles), return same-sized df that is bin number (map color bin) using preset breaks. <br><code><a href="#make.bin.cols">make.bin.cols</a></code> for a data.frame of values (e.g. percentiles), return same-sized df that is bin number (map color bin) using preset breaks. <br><code><a href="#write.pctiles">write.pctiles</a></code> to save file that is lookup table of percentiles for columns of a data.frame <br><code><a href="#write.pctiles.by.zone">write.pctiles.by.zone</a></code> to save file that is lookup table of percentiles for columns of a data.frame, for each geographic zone (subset of rows) <br><code><a href="#write.wtd.pctiles">write.wtd.pctiles</a></code> to save file that is lookup table of weighted percentiles for columns of a data.frame <br><code><a href="#write.wtd.pctiles.by.zone">write.wtd.pctiles.by.zone</a></code> to save file that is lookup table of weighted percentiles for columns of a data.frame, for each geographic zone (subset of rows) <br><code><a href="#lookup.pctile">lookup.pctile</a></code> to look up current approx weighted percentiles in a lookup table that is already in global memory <br></p>
<h3>Examples</h3>
<pre class="language-r"><code class="language-r">x <span class="token operator"><-</span> c<span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">40</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">,</span><span class="token number">12</span><span class="token punctuation">,</span><span class="token number">5</span><span class="token punctuation">,</span><span class="token number">5</span><span class="token punctuation">,</span><span class="token number">13</span><span class="token punctuation">,</span><span class="token number">13</span><span class="token punctuation">,</span><span class="token number">13</span><span class="token punctuation">,</span><span class="token number">13</span><span class="token punctuation">,</span><span class="token number">13</span><span class="token punctuation">,</span><span class="token number">8</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">10</span><span class="token operator">:</span><span class="token number">20</span><span class="token punctuation">,</span><span class="token number">20</span><span class="token punctuation">,</span><span class="token number">20</span><span class="token punctuation">,</span><span class="token number">20</span><span class="token punctuation">,</span><span class="token number">21</span><span class="token operator">:</span><span class="token number">30</span><span class="token punctuation">)</span>
weights <span class="token operator"><-</span> rep<span class="token punctuation">(</span>c<span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">,</span> length<span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token operator">/</span><span class="token number">2</span><span class="token punctuation">)</span>
cbind<span class="token punctuation">(</span>weights<span class="token punctuation">,</span> x<span class="token punctuation">,</span> PCTILE<span class="token operator">=</span>assign.pctiles.alt2<span class="token punctuation">(</span>x<span class="token punctuation">,</span>weights<span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token comment"># PERCENTILE OF ALL, NOT JUST THOSE WITH VALID DATA, IF na.rm=FALSE,</span>
<span class="token comment"># but then NA values preclude high percentiles:</span>
x <span class="token operator"><-</span> c<span class="token punctuation">(</span><span class="token keyword">NA</span><span class="token punctuation">,</span> <span class="token keyword">NA</span><span class="token punctuation">,</span> <span class="token keyword">NA</span><span class="token punctuation">,</span> <span class="token keyword">NA</span><span class="token punctuation">,</span><span class="token keyword">NA</span><span class="token punctuation">,</span><span class="token keyword">NA</span><span class="token punctuation">,</span><span class="token keyword">NA</span><span class="token punctuation">,</span><span class="token keyword">NA</span><span class="token punctuation">,</span><span class="token keyword">NA</span><span class="token punctuation">,</span><span class="token keyword">NA</span><span class="token punctuation">,</span><span class="token number">13</span><span class="token punctuation">,</span><span class="token number">13</span><span class="token punctuation">,</span><span class="token number">8</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">10</span><span class="token operator">:</span><span class="token number">20</span><span class="token punctuation">,</span><span class="token number">20</span><span class="token punctuation">,</span><span class="token number">20</span><span class="token punctuation">,</span><span class="token number">20</span><span class="token punctuation">,</span><span class="token number">21</span><span class="token operator">:</span><span class="token number">30</span><span class="token punctuation">)</span>
weights <span class="token operator"><-</span> rep<span class="token punctuation">(</span>c<span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">,</span> length<span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token operator">/</span><span class="token number">2</span><span class="token punctuation">)</span>
cbind<span class="token punctuation">(</span>weights<span class="token punctuation">,</span> x<span class="token punctuation">,</span> PCTILE.alt2<span class="token operator">=</span>assign.pctiles.alt2<span class="token punctuation">(</span>x<span class="token punctuation">,</span> weights<span class="token punctuation">,</span> na.rm<span class="token operator">=</span><span class="token boolean">FALSE</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
pctile<span class="token operator">=</span>assign.pctiles<span class="token punctuation">(</span>x<span class="token punctuation">,</span>weights<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">[</span>order<span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token punctuation">]</span>
cbind<span class="token punctuation">(</span>weights<span class="token punctuation">,</span> x<span class="token punctuation">,</span> PCTILE.alt2<span class="token operator">=</span>assign.pctiles.alt2<span class="token punctuation">(</span>x<span class="token punctuation">,</span> weights<span class="token punctuation">,</span> na.rm<span class="token operator">=</span><span class="token boolean">TRUE</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
pctile<span class="token operator">=</span>assign.pctiles<span class="token punctuation">(</span>x<span class="token punctuation">,</span>weights<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">[</span>order<span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token punctuation">]</span>
V<span class="token operator">=</span><span class="token number">9</span>
sum<span class="token punctuation">(</span>weights<span class="token punctuation">[</span><span class="token operator">!</span>is.na<span class="token punctuation">(</span>x<span class="token punctuation">)</span> <span class="token operator">&</span> x <span class="token operator"><=</span> V<span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token operator">/</span> sum<span class="token punctuation">(</span>weights<span class="token punctuation">[</span><span class="token operator">!</span>is.na<span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
<span class="token comment">#A value (V) being at this PCTILE% means that (assuming na.rm=TRUE):</span>
<span class="token comment"># V >= x for PCTILE% of weights (for non-NA x), so</span>
<span class="token comment"># V < x for 100% - PCTILE% of weights (for non-NA x), or</span>
<span class="token comment"># PCTILE% of all weights have V >= x (for non-NA x), so</span>
<span class="token comment"># 100% - PCTILE% of all weights have V < x (for non-NA x).</span>
x <span class="token operator"><-</span> c<span class="token punctuation">(</span><span class="token number">32</span><span class="token punctuation">,</span> <span class="token keyword">NA</span><span class="token punctuation">,</span> <span class="token keyword">NA</span><span class="token punctuation">,</span> <span class="token keyword">NA</span><span class="token punctuation">,</span><span class="token keyword">NA</span><span class="token punctuation">,</span><span class="token keyword">NA</span><span class="token punctuation">,</span><span class="token keyword">NA</span><span class="token punctuation">,</span><span class="token keyword">NA</span><span class="token punctuation">,</span><span class="token keyword">NA</span><span class="token punctuation">,</span><span class="token keyword">NA</span><span class="token punctuation">,</span><span class="token number">13</span><span class="token punctuation">,</span><span class="token number">13</span><span class="token punctuation">,</span><span class="token number">8</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">9</span><span class="token punctuation">,</span><span class="token number">10</span><span class="token operator">:</span><span class="token number">20</span><span class="token punctuation">,</span><span class="token number">20</span><span class="token punctuation">,</span><span class="token keyword">NA</span><span class="token punctuation">,</span><span class="token number">20</span><span class="token punctuation">,</span><span class="token number">21</span><span class="token operator">:</span><span class="token number">30</span><span class="token punctuation">)</span>
weights <span class="token operator"><-</span> rep<span class="token punctuation">(</span>c<span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">,</span> length<span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token operator">/</span><span class="token number">2</span><span class="token punctuation">)</span>
cbind<span class="token punctuation">(</span>weights<span class="token punctuation">,</span> x<span class="token punctuation">,</span> PCTILE.alt2<span class="token operator">=</span>assign.pctiles.alt2<span class="token punctuation">(</span>x<span class="token punctuation">,</span> weights<span class="token punctuation">,</span> na.rm<span class="token operator">=</span><span class="token boolean">FALSE</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
pctile<span class="token operator">=</span>assign.pctiles<span class="token punctuation">(</span>x<span class="token punctuation">,</span>weights<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">[</span>order<span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token punctuation">]</span>
cbind<span class="token punctuation">(</span>weights<span class="token punctuation">,</span> x<span class="token punctuation">,</span> PCTILE.alt2<span class="token operator">=</span>assign.pctiles.alt2<span class="token punctuation">(</span>x<span class="token punctuation">,</span> weights<span class="token punctuation">,</span> na.rm<span class="token operator">=</span><span class="token boolean">TRUE</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
pctile<span class="token operator">=</span>assign.pctiles<span class="token punctuation">(</span>x<span class="token punctuation">,</span>weights<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">[</span>order<span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token punctuation">]</span></code></pre>
<hr>
</div>
<div class="container manual-page" id="bgtest">
<a href="#bgtest" class="help-page-title"><h2>Test dataset for ejanalysis</h2></a>
<h3>Description</h3>
<p>This data set provides test data, with
Environmental, Demographic, and EJ Index fields,
one row per block group for about 32,698 blockgroups, covering a few states.
This is roughly a subset of ejscreen data like bg21 (see ejscreen package).
It does not have of the columns in the ejscreen dataset.
Can be used like this: data('bgtest', package = 'ejanalysis')
</p>
<h3>See Also</h3>
<p><a>ejscreen::names.d</a> (http://ejanalysis.github.io/ejscreen/)
</p>
<hr>
</div>
<div class="container manual-page" id="clean.fips">
<a href="#clean.fips" class="help-page-title"><h2>Clean up US Census FIPS (Add Missing Leading Zeroes)</h2></a>
<h3>Description</h3>
<p>Clean up US Census FIPS (add any missing leading zeroes)
</p>
<h3>Usage</h3>
<pre class="language-r"><code class="language-r">clean.fips<span class="token punctuation">(</span>fips<span class="token punctuation">)</span></code></pre>
<h3>Arguments</h3>
<table><tr style="vertical-align: top;">
<td><code>fips</code></td>
<td>
<p>Vector of numeric or character class, required. Can be state FIPs as number or character, for example.</p>
</td>
</tr></table>
<h3>Details</h3>
<p>For information on FIPS codes, see <a href="http://www.census.gov/geo/reference/ansi.html" target="_blank">http://www.census.gov/geo/reference/ansi.html</a>,
and also see <a href="https://www.census.gov/geo/reference/geoidentifiers.html" target="_blank">https://www.census.gov/geo/reference/geoidentifiers.html</a> <br><br>
If FIPS provided is 1-2 digits long assume it is a State.<br>
If FIPS provided is 3 digits long, it is a mistake and return NA.<br>
If FIPS provided is 4-5 digits, assume it is a County.<br>
If FIPS provided is 6-9 digits, it is a mistake and return NA.<br>
If FIPS provided is 10 digits long, assume it is a tract missing a leading zero on the state portion (should have 11 characters).<br>
If FIPS provided is 11 digits long, assume it is a tract (correctly 11 characters), not simply a block group FIPS missing a leading zero (block group FIPS would correctly would have 12 characters).<br>
If FIPS provided is 12 digits long, assume it is a block group (correctly 12 characters).<br>
If FIPS provided is 13 digits long, it is a mistake and return NA.<br>
If FIPS provided is 14 OR 15 digits long, assume it is a block.
</p>
<h3>Value</h3>
<p>Returns vector of FIPS (all characters from 2-digit State code onwards as appropriate) as character with leading zeroes
</p>
<h3>See Also</h3>
<p><code><a href="#clean.fips1215">clean.fips1215</a></code>, <code><a href="#get.fips.bg">get.fips.bg</a></code>, <code><a href="#get.fips.tract">get.fips.tract</a></code>, <code><a href="#get.fips.county">get.fips.county</a></code>, <code><a href="#get.fips.st">get.fips.st</a></code> to get partial FIPS from longer FIPS, or
<code><a href="#get.name.county">get.name.county</a></code>, <code><a href="#get.name.state">get.name.state</a></code> to extract name from longer Census name, or
<code><a href="#get.state.info">get.state.info</a></code>, <code><a href="#get.county.info">get.county.info</a></code>, <code><a href="#get.epa.region">get.epa.region</a></code>
to look up info such as FIPS, state abbreviation, statename, countyname, or region based on FIPS or name.
</p>
<hr>
</div>
<div class="container manual-page" id="clean.fips1215">
<a href="#clean.fips1215" class="help-page-title"><h2>Check and clean Census block group or block FIPS - only check number of characters and if NA, not if valid number otherwise</h2></a>
<h3>Description</h3>
<p>Check if valid Census block group or block FIPS, warn if not, add missing leading zero if inferred.
</p>
<h3>Usage</h3>
<pre class="language-r"><code class="language-r">clean.fips1215<span class="token punctuation">(</span>fips<span class="token punctuation">)</span></code></pre>
<h3>Arguments</h3>
<table><tr style="vertical-align: top;">
<td><code>fips</code></td>
<td>
<p>Vector of one or more elements, ideally character class, ideally 12 or 15 characters long (block group or block), required.</p>
</td>
</tr></table>
<h3>Details</h3>
<p>For information on FIPS codes, see <a href="http://www.census.gov/geo/reference/ansi.html" target="_blank">http://www.census.gov/geo/reference/ansi.html</a>,
and also see <a href="https://www.census.gov/geo/reference/geoidentifiers.html" target="_blank">https://www.census.gov/geo/reference/geoidentifiers.html</a>
</p>
<h3>Value</h3>
<p>Returns a vector of one or more character elements, same lengths as fips, NA if NA input
</p>
<h3>See Also</h3>
<p><code><a href="#clean.fips1215">clean.fips1215</a></code>, <code><a href="#get.fips.bg">get.fips.bg</a></code>, <code><a href="#get.fips.tract">get.fips.tract</a></code>, <code><a href="#get.fips.county">get.fips.county</a></code>, <code><a href="#get.fips.st">get.fips.st</a></code> to get partial FIPS from longer FIPS, or
<code><a href="#get.name.county">get.name.county</a></code>, <code><a href="#get.name.state">get.name.state</a></code> to extract name from longer Census name, or
<code><a href="#get.state.info">get.state.info</a></code>, <code><a href="#get.county.info">get.county.info</a></code>, <code><a href="#get.epa.region">get.epa.region</a></code>
to look up info such as FIPS, state abbreviation, statename, countyname, or region based on FIPS or name.
</p>
<h3>Examples</h3>
<pre class="language-r"><code class="language-r">samplefips <span class="token operator"><-</span> c<span class="token punctuation">(</span><span class="token string">"011030001003"</span><span class="token punctuation">,</span> <span class="token string">"011030001003001"</span><span class="token punctuation">,</span> <span class="token number">11030001003001</span><span class="token punctuation">,</span> <span class="token number">35</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token keyword">NA</span><span class="token punctuation">,</span> <span class="token string">'invalidtext'</span><span class="token punctuation">,</span> <span class="token string">'02'</span><span class="token punctuation">)</span>
clean.fips1215<span class="token punctuation">(</span>samplefips<span class="token punctuation">)</span>
clean.fips1215<span class="token punctuation">(</span><span class="token string">"011030001003001"</span><span class="token punctuation">)</span></code></pre>
<hr>
</div>
<div class="container manual-page" id="ej.added">
<a href="#ej.added" class="help-page-title"><h2>Contribution of each place to net excess people-points in demographic group</h2></a>
<h3>Description</h3>
<p>US total sum of net excess vulnerable * E = net excess people-points
and contribution of one place = what the EJ Index intends to indicate
</p>
<h3>Usage</h3>
<pre class="language-r"><code class="language-r">ej.added<span class="token punctuation">(</span>e<span class="token punctuation">,</span> d<span class="token punctuation">,</span> p<span class="token punctuation">,</span> vs <span class="token operator">=</span> <span class="token string">"nond"</span><span class="token punctuation">,</span> silent <span class="token operator">=</span> <span class="token boolean">TRUE</span><span class="token punctuation">)</span></code></pre>
<h3>Arguments</h3>
<table>
<tr style="vertical-align: top;">
<td><code>e</code></td>
<td>
<p>Environmental indicator</p>
</td>
</tr>
<tr style="vertical-align: top;">
<td><code>d</code></td>
<td>
<p>Demographic indicator</p>
</td>
</tr>
<tr style="vertical-align: top;">
<td><code>p</code></td>
<td>
<p>Population count (universe for d)</p>
</td>
</tr>
<tr style="vertical-align: top;">
<td><code>vs</code></td>
<td>
<p>Reference group, optional, 'nond' by default
which means the reference group is everyone other than the d group (everyone else),
but can also specify 'avg' in which case the overall average value
including the d group is used as the reference value.</p>
</td>
</tr>
<tr style="vertical-align: top;">
<td><code>silent</code></td>
<td>
<p>Optional, TRUE by default, in which case more details are printed.</p>
</td>
</tr>
</table>
<h3>Details</h3>
<p>WORK IN PROGRESS. ! e.g., presumes one setting for vs..... ***
Directly calculate total number of excess people-points in a demographic subgroup,
across all locations
**** here by default defining "excess" as above
what it would be if e in d group were same as e in nond group.**** <br>
where people-points are e * p * d <br>
e = environmental points or individual risk (vector of places) <br>
p = population counts (vector of places) <br>
d = demographic fraction that is in specified demographic group (vector of places) <br><br></p>
<p>For example, if e=cancer risk (individual risk) and p=pop and d=%lowincome,
value returned is number of cases among lowincome individuals in excess of what it
would be if their average risk was the same as that of nonlowincome individuals. <br>
net excess vulnerable * E = net excess people-points <br>
vs can be 'avg' or 'nonD' (default) (not case sensitive), <br>
for, respectively, excess cases relative to risk scenario where <br>
avg d's e is set to that of avg person (all people including d and nonD), <br>
or avg d's e is set to that of avg nonD person.
</p>
<h3>Value</h3>
<p>Returns numeric vector
</p>
<h3>Examples</h3>
<pre class="language-r"><code class="language-r">x<span class="token operator">=</span>data.frame<span class="token punctuation">(</span>pop<span class="token operator">=</span>rep<span class="token punctuation">(</span><span class="token number">1000</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">,</span> pct<span class="token operator">=</span><span class="token number">0.05</span><span class="token operator">+</span><span class="token number">6</span> <span class="token operator">*</span> <span class="token punctuation">(</span><span class="token number">1</span><span class="token operator">:</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token operator">/</span><span class="token number">100</span><span class="token punctuation">,</span> e<span class="token operator">=</span> <span class="token punctuation">(</span><span class="token number">10</span> <span class="token operator">*</span> <span class="token punctuation">(</span><span class="token number">1</span><span class="token operator">:</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token operator">/</span><span class="token number">100</span> <span class="token punctuation">)</span>
y<span class="token operator">=</span>ej.added<span class="token punctuation">(</span>x<span class="token operator">$</span>e<span class="token punctuation">,</span> x<span class="token operator">$</span>pct<span class="token punctuation">,</span> x<span class="token operator">$</span>pop<span class="token punctuation">,</span> silent<span class="token operator">=</span><span class="token boolean">FALSE</span><span class="token punctuation">)</span></code></pre>
<hr>
</div>
<div class="container manual-page" id="ej.indexes">
<a href="#ej.indexes" class="help-page-title"><h2>Calculate environmental justice (EJ) index for each place</h2></a>
<h3>Description</h3>
<p>Create an index that combines environmental and demographic indicators for each Census unit (e.g., block group).
</p>
<h3>Usage</h3>
<pre class="language-r"><code class="language-r">ej.indexes<span class="token punctuation">(</span>
env.df<span class="token punctuation">,</span>
demog<span class="token punctuation">,</span>
weights<span class="token punctuation">,</span>
us.demog<span class="token punctuation">,</span>
universe.us.demog<span class="token punctuation">,</span>
as.df <span class="token operator">=</span> <span class="token boolean">TRUE</span><span class="token punctuation">,</span>
prefix <span class="token operator">=</span> <span class="token string">"EJ.DISPARITY."</span><span class="token punctuation">,</span>
type <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">,</span>
na.rm <span class="token operator">=</span> <span class="token boolean">FALSE</span>
<span class="token punctuation">)</span></code></pre>
<h3>Arguments</h3>
<table>
<tr style="vertical-align: top;">
<td><code>env.df</code></td>
<td>
<p>Environmental indicators vector or numeric data.frame, one column per environmental factor, one row per place (e.g., block group).</p>
</td>
</tr>
<tr style="vertical-align: top;">
<td><code>demog</code></td>
<td>
<p>Demographic indicator(s) vector or data.frame, numeric fractions of population that is in specified demographic group
(e.g., fraction below poverty line), one per place.</p>
</td>
</tr>
<tr style="vertical-align: top;">
<td><code>weights</code></td>
<td>
<p>Optional, and default is equal weighting. If us.demog and universe.us.demog are not specified, weights are used to find
weighted mean of demog to use as area-wide overall average (e.g., population-weighted average percent Hispanic, for all block groups in USA). One weight per place.</p>
</td>
</tr>
<tr style="vertical-align: top;">
<td><code>us.demog</code></td>
<td>
<p>Optional overall area-wide value for demog percentage share of population as fraction 0 to 1
(e.g., US Demographic Indicator).
The correct value to use for EJScreen 2.0, for example, is
with(ejscreen::bg21, ( sum(mins)/sum(pop) + sum(lowinc)/sum(povknownratio) ) / 2)
Default is to approximate it as weighted mean of demog,
where the weights are universe.us.demog if specified, or else just 'weights'.
If the weights are population counts and demog is percent Hispanic, for example, us.demog is the percent of US population that is Hispanic.</p>
</td>
</tr>
<tr style="vertical-align: top;">
<td><code>universe.us.demog</code></td>
<td>
<p>Optional numeric vector. If specified and us.demog not specified, used instead of weights to get weighted mean of demog to find area-wide demog.
This should be the actual denominator, or universe, that was used to create percent demog –
universe.us.demog if specified should be a vector that has the count, for each place, of the denominator for finding the US overall percent
and this may be slightly different than total population.
For example if demog=places$pctlowinc then true universe.us.demog=places$povknownratio which is the count for whom poverty ratio is known in each place, which is <= pop.</p>
</td>
</tr>
<tr style="vertical-align: top;">
<td><code>as.df</code></td>
<td>
<p>Default is TRUE.</p>
</td>
</tr>
<tr style="vertical-align: top;">
<td><code>prefix</code></td>
<td>
<p>Optional character string used as first part of each colname in results. Default is "EJ.DISPARITY."</p>
</td>
</tr>
<tr style="vertical-align: top;">
<td><code>type</code></td>
<td>
<p>Specifies type of EJ Index. Default is type=1. Several formulas are available: <br></p>
<ul>
<li>
<p> For type=1, ej.indexes = weights * env.df * (demog - us.demog) ## This is the EJ Index in EJScreen from 2015-2022. Note: us.demog could also be called d.avg.all, and note that na.rm is currently ignored for type=1
</p>
</li>
<li>
<p> For type=1.5, ej.indexes = weights * env.df * (demog - d.avg.all.elsewhere) # for a place that is one of many this can be almost identical to type 1 <br></p>
</li>
<li>
<p> For type=2.1, ej.indexes = weights * demog * (env.df - e.avg.all) # like type 1 but env and demog roles are swapped <br></p>
</li>
<li>
<p> For type=2, ej.indexes = weights * demog * (env.df - e.avg.nond) <br></p>
</li>
<li>
<p> For type=2.5, ej.indexes = weights * demog * (env.df - e.avg.nond.elsewhere ) <br></p>
</li>
<li>
<p> For type=3, ej.indexes = weights * ((demog * env.df) - (d.avg.all * e.avg.nond ) ) <br></p>
</li>
<li>
<p> For type=3.5, ej.indexes = weights * ((demog * env.df) - (d.avg.all.elsewhere * e.avg.nond.elsewhere) ) <br></p>
</li>
<li>
<p> For type 4 , ej.indexes = weights * ((demog - d.avg.all ) * (env.df - e.avg.nond ) ) <br></p>
</li>
<li>
<p> For type=4.5, ej.indexes = weights * ((demog - d.avg.all.elsewhere) * (env.df - e.avg.nond.elsewhere) ) <br></p>
</li>
<li>
<p> For type=5 , ej.indexes = weights * env.df * demog ## A "Population Risk" or "Burden" index = Number of cases among D group if e is individual risk, or just "people-points among D" if e is "points" <br></p>
</li>
<li>
<p> For type=6, ej.indexes = env.df * demog ## A "unweighted" simple product of Envt x percent_D. A "percent-based" indicator = percent in group D times envt indicator <br></p>
</li>
<li>
<p> For type=7, ej.indexes = env.df * (demog - us.demog) # Like type 1 or EJScreen 2.0, but without the pop count in the formula <br></p>
</li>
</ul>
<p>where
</p>
<ul>
<li>
<p> us.demog = overall demog where avg person lives (pop wtd mean of demog). This may be almost exactly the same as d.avg.all.elsewhere <br></p>
</li>
<li>
<p> d.avg.all = overall value for d as fraction of entire population (including the one place being analyzed). <br></p>
</li>
<li>
<p> d.avg.all.elsewhere = overall value for d as fraction of entire population other than the one place being analyzed. <br></p>
</li>
<li>
<p> e.avg.all = avg environmental indicator value for average person <br></p>
</li>
<li>
<p> e.avg.nond = avg environmental indicator value for average person who is not in the D-group, among all (including the one place being analyzed). This is typically the expected as opposed to observed value of e within group D, in the context of EJ analysis of disparity in e. <br></p>
</li>
<li>
<p> e.avg.nond.elsewhere = avg environmental indicator value for average person who is not in the D-group, among all except in the one place being analyzed. <br></p>
</li>
</ul>
</td>
</tr>
<tr style="vertical-align: top;">
<td><code>na.rm</code></td>
<td>
<p>Default is FALSE. NOTE: This is complicated but important. See notes in source code about handling NA values in various formulas here.</p>
</td>
</tr>
</table>
<h3>Details</h3>
<p>Creates one EJ index column for each environmental indicator column,
or if given a vector or single column of environmental indicators instead of data.frame, returns a vector or column.
Each "place" can be a Census unit such as a State, County, zip code, tract, block group, block, for example (or even by individual if person-level data are available).<br><br>
Note: For 1.5, 3.5, 4.5 need vector d.avg.all.elsewhere. calculated in each of those.<br></p>
<ul>
<li>
<p> But does not properly handle cases where us.demog or universe.us.demog specified because denominator is not same as pop <br></p>
</li>
<li>
<p> and need to fix for when is.na(p) | is.na(demog) <br>
Type 2 however does handle NA values appropriately, meaning a result for a given col of env.df is set to NA for a given row <br>
(assuming na.rm=FALSE) if and only if NA is found in that row, in demog or weights or that one col of env.df.
</p>
</li>
</ul>
<h3>Value</h3>
<p>Returns a numeric data.frame (or matrix if <code>as.df=FALSE</code>) of EJ indexes, one per place per environmental indicator.
</p>
<h3>Examples</h3>
<pre class="language-r"><code class="language-r">statedat <span class="token operator"><-</span> data.frame<span class="token punctuation">(</span>state.x77<span class="token punctuation">)</span>
hist<span class="token punctuation">(</span>myej <span class="token operator"><-</span> ej.indexes<span class="token punctuation">(</span>env.df<span class="token operator">=</span>statedat<span class="token punctuation">[</span> <span class="token punctuation">,</span> c<span class="token punctuation">(</span><span class="token string">'Life.Exp'</span><span class="token punctuation">,</span> <span class="token string">'Frost'</span><span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
demog<span class="token operator">=</span>statedat<span class="token operator">$</span>HS.Grad<span class="token operator">/</span><span class="token number">100</span><span class="token punctuation">,</span> weights<span class="token operator">=</span>statedat<span class="token operator">$</span>Population<span class="token punctuation">,</span> prefix<span class="token operator">=</span><span class="token string">'EJtype1.'</span><span class="token punctuation">,</span> type<span class="token operator">=</span><span class="token number">1</span> <span class="token punctuation">)</span><span class="token punctuation">)</span>
set.seed<span class="token punctuation">(</span><span class="token number">999</span><span class="token punctuation">)</span>
myej <span class="token operator"><-</span> ej.indexes<span class="token punctuation">(</span>env.df<span class="token operator">=</span>rnorm<span class="token punctuation">(</span><span class="token number">1000</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">,</span> demog<span class="token operator">=</span>runif<span class="token punctuation">(</span><span class="token number">1000</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
weights<span class="token operator">=</span>runif<span class="token punctuation">(</span><span class="token number">1000</span><span class="token punctuation">,</span> <span class="token number">500</span><span class="token punctuation">,</span> <span class="token number">5000</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
myej</code></pre>
<hr>
</div>
<div class="container manual-page" id="ejanalysis">
<a href="#ejanalysis" class="help-page-title"><h2>Tools for Environmental Justice (EJ) Analysis</h2></a>
<h3>Description</h3>
<p>This R package provides tools for environmental justice (EJ) analysis,
including metrics characterizing disparities between demographic groups,
such as differences in environmental or other indicators measured for each Census unit
such as Census blocks, block groups, tracts, zip codes, or counties.
</p>
<p>These tools simplify some basic tasks in
exploring and analyzing a dataset in a matrix or data.frame
that contains data on demographics (e.g., counts of residents in poverty)
and local environmental indicators (e.g., an air quality index),
with one row per spatial location (e.g., Census block group).
Key functions help to find relative risk or similar ratios of means in demographic groups,
, etc.
</p>
<h3>Details</h3>
<p>Key functions include
</p>
<ul>
<li> <p><code><a href="#RR">RR()</a></code>
</p>
</li>
<li> <p><code><a href="#pop.ecdf">pop.ecdf()</a></code>
</p>
</li>
<li> <p><code><a href="#ej.indexes">ej.indexes()</a></code>
</p>
</li>
<li> <p><code><a href="#assign.pctiles">assign.pctiles()</a></code>
</p>
</li>
<li> <p><code><a href="#make.bin.pctile.cols">make.bin.pctile.cols()</a></code>
</p>
</li>
<li> <p><code><a href="#get.county.info">get.county.info()</a></code>
</p>
</li>
<li> <p><code><a href="#state.health.url">state.health.url()</a></code>
</p>
</li>
</ul>
<h3>References</h3>
<p><a href="http://ejanalysis.github.io" target="_blank">http://ejanalysis.github.io</a> <br><a href="http://www.ejanalysis.com/" target="_blank">http://www.ejanalysis.com/</a> <br></p>
<hr>
</div>
<div class="container manual-page" id="ejRRadded">
<a href="#ejRRadded" class="help-page-title"><h2>Formulas for local contributions to EJ metrics</h2></a>
<h3>Description</h3>
<p>Formulas for pop counts, pop demog pct, risk, cases, RR,
excess risk, excess cases (like EJ index sum),
and how those are different under 4 alt scenarios like E of D is set to that of dref.
</p>
<h3>Usage</h3>
<pre class="language-r"><code class="language-r">ejRRadded<span class="token punctuation">(</span>E<span class="token punctuation">,</span> D <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">,</span> P <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">,</span> na.rm <span class="token operator">=</span> <span class="token boolean">TRUE</span><span class="token punctuation">,</span> n <span class="token operator">=</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token ellipsis">...</span><span class="token punctuation">)</span></code></pre>
<h3>Arguments</h3>
<table>
<tr style="vertical-align: top;">
<td><code>E</code></td>
<td>
<p>Environmental indicator (e.g., risk, exposure, or any local indicator, but if it is individual risk then number of cases can be calculated rather than just people-points)</p>
</td>
</tr>
<tr style="vertical-align: top;">