Skip to contents

*** DRAFT - May change but works as currently drafted. e.g., change output formats of results_bytype vs results_overall

Usage

ejamit_compare_types_of_places(
  sitepoints,
  typeofsite = NULL,
  shapefile = NULL,
  fips = NULL,
  silentinteractive = TRUE,
  ...
)

Arguments

sitepoints

see ejamit()

typeofsite

vector of length same as NROW(sitepoints), where each unique value defines a group of sites

shapefile

see ejamit()

fips

see ejamit()

silentinteractive

passed to ejamit()

...

see ejamit()

Value

similar to ejamit output but results_overall has one row per unique typeofsite

Examples

  out <- ejamit_compare_types_of_places(testpoints_10[1:4, ], 
    typeofsite = c("A", "B", "B", "C"))
#> Type 1 of 3 = A  -- Analyzing 1 points, radius of 3 miles around each.
#> Finished 1 of 1 sites. Rate of 1,692 buffers per hour: 1 lat/long pairs took 2 seconds
#> Type 2 of 3 = B  -- 
#> Note that ejam_uniq_id was already in sitepoints, and might not be 1:NROW(sitepoints), which might cause issues
#> Analyzing 2 points, radius of 3 miles around each.
#> Finished 3 of 3 sites. Rate of 2,416 buffers per hour: 3 lat/long pairs took 4 seconds
#> Type 3 of 3 = C  -- 
#> Note that ejam_uniq_id was already in sitepoints, and might not be 1:NROW(sitepoints), which might cause issues
#> Analyzing 1 points, radius of 3 miles around each.
#> Finished 4 of 4 sites. Rate of 2,477 buffers per hour: 4 lat/long pairs took 6 seconds
#> 
#> 
#>   type valid sitecount pctvalid     pop pop_persite pctofallpop
#> 1    A     1         1      100  124566      124566           9
#> 2    B     2         2      100 1176931      588466          89
#> 3    C     1         1      100   19637       19637           1
#>   pctofallsitecount
#> 1                25
#> 2                50
#> 3                25
#>   ratio.to.state.avg.Demog.Index ratio.to.state.avg.Demog.Index.Supp
#> 1                            0.9                                 0.8
#> 2                            1.2                                 1.0
#> 3                            0.7                                 0.9
#>   ratio.to.state.avg.pctlowinc ratio.to.state.avg.pctlingiso
#> 1                          0.5                           1.2
#> 2                          1.1                           1.0
#> 3                          0.8                           0.7
#>   ratio.to.state.avg.pctunemployed ratio.to.state.avg.pctlths
#> 1                              0.6                        0.7
#> 2                              1.1                        1.0
#> 3                              1.0                        1.0
#>   ratio.to.state.avg.pctunder5 ratio.to.state.avg.pctover64
#> 1                          0.9                          1.1
#> 2                          1.2                          0.7
#> 3                          1.2                          0.8
#>   ratio.to.state.avg.pctmin
#> 1                       1.2
#> 2                       1.2
#> 3                       0.6
#> Use  ejam2excel(out)  to view results, and see the types of sites compared, one row each, in the Overall tab
#> Use ejam2barplot_sitegroups() to plot results.
#> 
#> 
#>  4 sites in 3 groups (types of sites).
#> Rate of 2,473 buffers per hour: 4 lat/long pairs took 6 seconds
  cbind(Rows_or_length = sapply(out, NROW))
#>                  Rows_or_length
#> types                         3
#> sitecount_bytype              3
#> results_bytype                3
#> results_overall               3
#> ejam_uniq_id                  4
#> typeofsite                    4
#> results_bysite                4
#> longnames                   417
#> validstats                    3
#> ratiostats                    3
  
  ejam2barplot_sitegroups(out, names_these_ratio_to_avg[1], topn = 3)

  
  ejam2barplot_sitegroups(out, "sitecount_unique", topn=3, sortby = F)

  
  ejam2barplot_sitegroups(out, "pop", topn = 3, sortby = F)

  
  # use calculated variable not in original table
  df <- out$results_bytype
  df$share <- df$pop / sum(df$pop)
  df$pop_per_site <- df$pop / df$sitecount_unique
  
  plot_barplot_sites(df,
    "share", ylab = "Share of Total Population",
    topn = 3, names.arg = out$types , sortby = F)

    
  plot_barplot_sites(df,
    "pop_per_site", ylab = "Pop. at Avg. Site in Group",
    topn = 3, main = "Nearby Residents per Site, by Site Type",
    names.arg = out$types , sortby = F)

  
  if (FALSE) { # \dontrun{
    
  # Analyze by EPA Region
  
  pts <- data.frame(testpoints_1000)
  
  # Get State and EPA Region of each point from lat/lon
  
   x <- state_from_latlon(lat = pts$lat, lon = pts$lon)
   pts <- data.frame(pts, x)
   
   out_byregion <- ejamit_compare_types_of_places(
     pts, typeofsite = pts$REGION)
   
   dvarname <- names_d[3]
   ejam2barplot_sitegroups(out_byregion, dvarname)
   abline(h = usastats_means(dvarname))
   
   ejam2barplot_sitegroups(out_byregion, "ratio.to.avg.pctmin",
      main = "By EPA Region", ylim = c(0, 2))
   abline(h = 1)
     
   # Analyze by State (slow)
   
   out_bystate <- ejamit_compare_types_of_places(pts, typeofsite = pts$ST)
   
   ejam2barplot_sitegroups(out_bystate, "sitecount_unique", 
     names.arg = out_bystate$types, topn = 52, cex.names = 0.5,
     main = "Sites by State")

  } # }