Hello all. Thank you in advance for any additional suggestions.
I have with, Jim's help, found some traction in my pursuit of this problem.
"determine the largest concentration of members in the smallest
radius"
However, I need guidance in efficiencies as I will explain below.
1. I have used Jim's routine to map ALL Member density -- Very helpful
visualization
geomat<-makeDensityMatrix(geo1[,c("latitude","longitude")],
xlim=range(geo1$longitude),ylim=range(geo1$latitude))
# Range of density (>0) - 1.119816 3.922018
latlim<-range(geo1$latitude)
lonlim<-range(geo1$longitude)
#library(maps) Now in pkgs
map("world",xlim=lonlim,ylim=latlim)
axis(1)
axis(2)
densityGrid(geomat,range.cex=c(1,5),xlim=lonlim,ylim=latlim,
red=c(0.5,1),green=0,blue=0,pch=15)
title("All Member Geo Density Plot")
2. Then using this reference -->
https://stackoverflow.com/questions/60141556/how-to-calculate-distance-between-points-from-a-reference-point-using-r
and the sf pkg functions
3. And identifying and using a single point in my data located in the most dense
city "Brooklyn" I have created a distance column in miles with
Brooklyn as reference point
str(geo1)
individual_dets_sf <- st_as_sf(geo1, coords = c("longitude",
"latitude"),
crs = 4326) %>%
ungroup()
brooklyn <- data.frame("longitude" = -73.973516,
"latitude" = 40.57672)
brooklyn_sf <- st_as_sf(brooklyn,
coords = c("longitude", "latitude"),
crs = 4326,
remove = FALSE)
individual_dets_sf_2 <- individual_dets_sf %>%
mutate(distances = st_distance(., brooklyn_sf, by_element = TRUE))
individual_dets_sf_2$distances
View(individual_dets_sf_2)
individual_dets_sf_3 <- as.data.frame(individual_dets_sf_2)
4. Then I did the following;
I arbitrarily created 8 Radius routines 100 Mi through 2000k Mi
Example:
#Radius1----
individual_dets_sf_3X %>%
dplyr::select(MBR_SUBSCRIBERID,distances_Mi) %>%
group_by(distances_Mi, MBR_SUBSCRIBERID) %>%
filter(distances_Mi <= 2000) %>%
tally()
Then I used the tibble info from the console to manually calculate the percent
of members covered and missed
# A tibble: 2226 x 3
#2226/2352 = 0.9464286-1 =-0.0535714 missed
My optimal Radius by the way is 1200k Mi. which I mapped like I did for All
members above
My new question is:
Is there a more elegant way to output something like this that I created
manually and entered into excel
Radius Distance Members Covered Percent Covered
Percent Missed
R1 2000Mi 2226
0.9464286 0.0535714
Missed Diff From Radius2
R2 1500Mi 2126
0.9039116 0.0960884
R3 1200Mi 1990
0.8460884 0.1539116 Optimal
0.0578232
R4 1000Mi 1644
0.6989796 0.3010204
0.204932
R5 900Mi 1573
0.6687925 0.3312075
R6 700Mi 1198
0.5093537 0.4906463 Break Even point
R7 500Mi 972
0.4132653 0.4132653
R8 100Mi 356
0.1513605 0.1513605
Isn't there a better way to do all this below rather than manually? See
sample data below please?
Here is where I would like to create some efficiencies please.
#Radius1----
individual_dets_sf_3X %>%
dplyr::select(MBR_SUBSCRIBERID,distances_Mi) %>%
group_by(distances_Mi,MBR_SUBSCRIBERID) %>%
filter(distances_Mi <= 2000) %>%
tally()
#summarize(mean_size = mean(Prov_ActiveMonths))
## A tibble: 2226 x 3 2226/2352 = 0.9464286-1 =-0.0535714 missed
#Radius2----
individual_dets_sf_3X %>%
dplyr::select(MBR_SUBSCRIBERID,distances_Mi) %>%
group_by(distances_Mi,MBR_SUBSCRIBERID) %>%
filter(distances_Mi <= 1500) %>%
tally()
#summarize(mean_size = mean(Prov_ActiveMonths))
## A tibble: 2126 x 3 2126/2352 = 0.9039116-1 =-0.0960884 missed
#Radius3----
individual_dets_sf_3X %>%
dplyr::select(MBR_SUBSCRIBERID,distances_Mi) %>%
group_by(distances_Mi,MBR_SUBSCRIBERID) %>%
filter(distances_Mi <= 1200) %>%
tally()
#summarize(mean_size = mean(Prov_ActiveMonths))
## A tibble: 1990 x 3 1990/2352 = 0.8460884-1 =-0.1539116 missed
#Radius4----
individual_dets_sf_3X %>%
dplyr::select(MBR_SUBSCRIBERID,distances_Mi) %>%
group_by(distances_Mi,MBR_SUBSCRIBERID) %>%
filter(distances_Mi <= 1000) %>%
tally()
#summarize(mean_size = mean(Prov_ActiveMonths))
## A tibble: 1644 x 3 1644/2352 = 0.6989796-1 =--0.3010204 missed
#Radius5----
individual_dets_sf_3X %>%
dplyr::select(MBR_SUBSCRIBERID,distances_Mi) %>%
group_by(distances_Mi,MBR_SUBSCRIBERID) %>%
filter(distances_Mi <= 900) %>%
tally()
#summarize(mean_size = mean(Prov_ActiveMonths))
## A tibble: 1573 x 3 1573/2352 = 0.6687925-1 =--0.3312075 missed
#Radius6----
individual_dets_sf_3X %>%
dplyr::select(MBR_SUBSCRIBERID,distances_Mi) %>%
group_by(distances_Mi,MBR_SUBSCRIBERID) %>%
filter(distances_Mi <= 700) %>%
tally()
#summarize(mean_size = mean(Prov_ActiveMonths))
## A tibble: 1198 x 3 1198/2352 = 0.5093537-1 =-0.4906463 missed ~ 50/50 at 700
mile radius
#Radius7----
individual_dets_sf_3X %>%
dplyr::select(MBR_SUBSCRIBERID,distances_Mi) %>%
group_by(distances_Mi,MBR_SUBSCRIBERID) %>%
filter(distances_Mi <= 500) %>%
tally()
#summarize(mean_size = mean(Prov_ActiveMonths))
## A tibble: 972 x 3 972/2352 = 0.4132653-1 =-0.5867347 missed
#Radius8----
individual_dets_sf_3X %>%
dplyr::select(MBR_SUBSCRIBERID,distances_Mi) %>%
group_by(distances_Mi,MBR_SUBSCRIBERID) %>%
filter(distances_Mi <= 100) %>%
tally()
#summarize(mean_size = mean(Prov_ActiveMonths))
## A tibble: 356 x 2 356/2352 = 0.1513605-1 =-0.8486395 missed
dput(sample)
structure(list(state = structure(c(2L, 22L, 10L, 12L, 6L, 22L,
11L, 22L, 22L, 32L, 19L, 29L, 9L, 9L, 10L, 30L, 33L, 35L, 41L,
12L, 12L, 36L, 4L, 9L, 8L, 39L, 36L, 36L, 41L, 28L, 12L, 28L,
28L, 12L, 11L, 2L, 12L, 22L, 32L, 22L, 12L, 10L, 10L, 22L, 10L
), .Label = c("AL", "AR", "AZ", "CA",
"CO", "CT", "DC", "DE",
"FL", "GA", "IA", "IL", "IN",
"KS", "KY", "LA", "MA", "MD",
"ME",
"MI", "MN", "MO", "NC", "NE",
"NJ", "NM", "NV", "NY", "OH",
"OK",
"OR", "PA", "SC", "SD", "TN",
"TX", "UT", "VA", "WA", "WI",
"WV"
), class = "factor"), city = structure(c(838L, 1030L, 262L, 218L,
166L, 973L, 339L, 451L, 660L, 358L, 281L, 1280L, 129L, 223L,
989L, 721L, 550L, 731L, 1325L, 688L, 1184L, 281L, 759L, 1171L,
1305L, 587L, 272L, 581L, 263L, 152L, 217L, 152L, 390L, 5L, 571L,
1006L, 1162L, 939L, 170L, 1033L, 1002L, 586L, 586L, 192L, 586L
), .Label = c("ABBOTTSTOWN", "ABILENE", "ACWORTH",
"ADAMS", "ADDISON",
"ADKINS", "ALBANY", "ALBIA",
"ALBUQUERQUE", "ALEXANDRIA", "ALFRED",
"ALIQUIPPA", "ALISO VIEJO", "ALLEN PARK",
"ALLENTOWN", "ALPHA",
"ALPHARETTA", "ALPINE", "ALTOONA",
"AMARILLO", "AMBLER", "AMBRIDGE",
"AMHERST", "AMITYVILLE", "ANAHIEM",
"ANDERSON", "ANDOVER", "ANGIER",
"ANGLETON", "ANKENY", "ANN ARBOR",
"ANZA", "APEX", "APOLLO",
"ARCADIA", "ARCHDALE", "ARDMORE",
"ARGYLE", "ARKANSAS CITY",
"ARLINGTON", "ARNOLD", "ARTHUR",
"ASHEBORO", "ASHEVILLE", "ASHLAND",
"ASHLAND CITY", "ASHTON", "ASTON",
"ATHENS", "ATLANTA", "ATLANTIC BCH",
"AUBORN", "AUGUSTA", "AURORA",
"AUSTELL", "AUSTIN", "AVENTURA",
"AVONDALE ESTATES", "BAKERSFIELD", "BALDWIN CITY",
"BALDWIN PLACE",
"BALLWIN", "BANGOR", "BARBOURSVILLE",
"BARNEGAT", "BARTLETT",
"BARTON", "BARTONVILLE", "BASSETT",
"BATAVIA", "BATESBURG", "BATON ROUGE",
"BAXTER SPRINGS", "BAY CITY", "BAYONNE",
"BAYSIDE", "BAYTOWN",
"BEAR", "BEAUMONT", "BEECH CREEK", "BEECHER
CITY", "BELFAIR",
"BELLE VERNON", "BELLEAIR", "BELLEVUE",
"BELLMAWR", "BELLMORE",
"BELLWOOD", "BELMAR", "BELMONT",
"BELVIDERE", "BENNET", "BENTON",
"BENTONVILLE", "BERLIN", "BESSEMER CITY",
"BETHANY", "BETHEL",
"BETHEL PARK", "BETHESDA", "BETHLEHEM",
"BETTENDORF", "BIGLERVILLE",
"BINGHAMTON", "BIRDSBORO", "BIWABIK", "BLACK
MOUNTAIN", "BLACKSBURG",
"BLAINE", "BLAIRSVILLE", "BLAKESLEE",
"BLOOMFIELD", "BLUE BELL",
"BLUE GRASS", "BLUE POINT", "BLUE SPRINGS",
"BOCA RATON", "BODFISH",
"BOILING SPRINGS", "BOLIVAR", "BON AQUA",
"BONNER SPRINGS", "BONNEY LAKE",
"BOONEVILLE", "BOSSIER CITY", "BOUNTIFUL",
"BOWLING GREEN", "BOYERTOWN",
"BOYNTON BEACH", "BRADENTON", "BRADENVILLE",
"BRANDAMORE", "BRANDON",
"BRANFORD", "BRANSON", "BRASELTON",
"BREEZEWOOD", "BRENTON",
"BRENTWOOD", "BREWSTER", "BRICK",
"BRIDGEPORT", "BRIDGETON",
"BRIGHAM CITY", "BROADDUS", "BROCKPORT",
"BROGUE", "BROKEN ARROW",
"BRONX", "BROOKFIELD", "BROOKHAVEN",
"BROOKLYN", "BROWNS MILLS",
"BROWNSBURG", "BROWNSVILLE", "BRUNSWICK",
"BRYAN", "BUCKSPORT",
"BUDD LAKE", "BUFFALO", "BULVERDE",
"BUNKERVILLE", "BURBANK",
"BURFORD", "BURIEN", "BURLINGTON", "BURR
RIDGE", "BURTON", "BUSKIRK",
"BUTLER", "BUXTON", "BYRON", "CALERA",
"CAMBRIDGE", "CAMP HILL",
"CAMPBELL", "CANAAN", "CANAL WINCHESTER",
"CANASTOTA", "CANTON",
"CARDIFF BY THE SEA", "CARL JUNCTION", "CARLISLE",
"CARLTON",
"CAROL STREAM", "CARROLLTON", "CARSON CITY",
"CARTERSVILLE",
"CARTHAGE", "CARY", "CASEYVILLE",
"CASSVILLE", "CASWELL", "CATO",
"CEDAR RAPIDS", "CEDARBURG", "CEDARVILLE",
"CENTER POINT", "CENTERTON",
"CENTRAL ISLIP", "CENTRAL POINT", "CHAGRIN FALLS",
"CHALFONT",
"CHAPEL HILL", "CHAPIN", "CHARDON",
"CHARITON", "CHARLESTON",
"CHARLOTTE", "CHEROKEE", "CHERRY HILL",
"CHERRY VALLEY", "CHESHIRE",
"CHEST SPRINGS", "CHESTER", "CHESTERTON",
"CHICAGO", "CHILLICOTHE",
"CHOCTAW", "CICERO", "CINCINNATI",
"CLAY", "CLEARWATER", "CLEARWATER BEACH",
"CLEMMONS", "CLENDENIN", "CLEVELAND",
"CLEVELAND HTS", "CLEVES",
"CLIFFSIDE PARK", "CLIFTON", "CLIFTON PARK",
"CLIFTON SPGS",
"CLINTON", "COACHELLA", "COAL TOWNSHIP",
"COATESVILLE", "COLLEGE STATION",
"COLLINSVILLE", "COLONIA", "COLUMBIA",
"COLUMBUS", "COMMERCE",
"CONCORD", "CONCORD TOWNSHIP", "CONNELLSVILLE",
"CONROE", "CONWAY",
"CONYERS", "COOKEVILLE", "COON RAPIDS",
"CORAOPOLIS", "CORDOVA",
"CORNELIUS", "CORNWALL", "CORONADO", "CORPUS
CHRISTI", "CORRY",
"COTTAGE HILLS", "COTTLEVILLE", "COTTONWOOD",
"COVINGTON", "COWEN",
"CRANBERRY TOWNSHIP", "CROWN POINT", "CUBA",
"CUMBERLAND CENTER",
"CUMBERLAND FORESIDE", "CUMMING", "CUYAHOGA FLS",
"CYPRESS",
"DALLAS", "DALLASTOWN", "DANBURY", "DANIA
BCH", "DANVILLE", "DAVENPORT",
"DAVIE", "DAVIS JUNCTION", "DAWSON",
"DAYTON", "DE SOTO", "DECATUR",
"DEFIANCE", "DEFOREST", "DELAVAN",
"DELMAR", "DELRAY BEACH",
"DEMOTTE", "DENISON", "DENVER",
"DEPTFORD", "DERBY", "DERRY",
"DES MOINES", "DETROIT", "DICKINSON",
"DILLSBURG", "DITTMER",
"DIXON", "DONNA", "DOTHAN", "DOUGLAS",
"DOUGLASVILLE", "DOVER",
"DOYLESTOWN", "DREXEL HILL", "DUBLIN",
"DUCHESNE", "DULUTH",
"DUNCAN", "DUNCANNON", "DUNCANSVILLE",
"DUNEDIN", "DUNNSVILLE",
"DURHAM", "DUTTON", "EAGLE GROVE", "EAST
AURORA", "EAST CHICAGO",
"EAST EARL", "EAST HANOVER", "EAST HARTFORD",
"EAST HARTLAND",
"EAST LEROY", "EAST LIVERPOOL", "EAST MEADOW",
"EAST NORTHPORT",
"EAST ORANGE", "EAST PEORIA", "EAST SAINT LOUIS",
"EASTON", "EDGERTON",
"EDISON", "EDMOND", "EGG HBR TWP", "EL
DORADO", "EL PASO", "ELDRIDGE",
"ELGIN", "ELIZABETHVILLE", "ELLISVILLE",
"ELLSWORTH", "ELLWOOD CITY",
"ELMHURST", "ELMWOOD PARK", "ELOY",
"ELY", "EMERSON", "EMORY",
"ENDICOTT", "ENGLEWOOD", "ENID",
"ENNICE", "ENOLA", "ENUMCLAW",
"EPHRATA", "ERIE", "ESTERO", "EUREKA
SPRINGS", "EVANSVILLE",
"EVERETT", "EXCELSIOR SPRINGS", "EXTON",
"FAIRFAX", "FAIRFIELD",
"FAIRHAVEN", "FAIRVIEW", "FAIRVIEW PARK",
"FALMOUTH", "FAR HILLS",
"FAR ROCKAWAY", "FARMINGDALE", "FARMINGTON",
"FAYETTE", "FAYETTEVILLE",
"FELTON", "FENTON", "FERGUSON",
"FIELDALE", "FINDLAY", "FINGERVILLE",
"FLEMINGTON", "FLINT", "FLORENCE",
"FLORESVILLE", "FLORISSANT",
"FLOVILLA", "FLOWER MOUND", "FLUSHING",
"FOGELSVILLE", "FOLSOM",
"FONTANELLE", "FOREST HILLS", "FOREST PARK",
"FORT DODGE", "FORT FAIRFIELD",
"FORT GAY", "FORT LAUDERDALE", "FORT LEE",
"FORT MILL", "FORT MOHAVE",
"FORT PAYNE", "FORT PIERCE", "FORT SMITH",
"FORT WAYNE", "FORT WORTH",
"FOSTORIA", "FOUNTAIN INN", "FRANKFORT",
"FRANKLIN", "FREEDOM",
"FREEHOLD", "FREEPORT", "FREMONT",
"FULLERTON", "FULSHEAR", "FULTON",
"GADSDEN", "GAFFNEY", "GAINESVILLE",
"GALLOWAY", "GARDEN PRAIRIE",
"GARDNERS", "GARNETT VALLEY", "GARY",
"GASTON", "GASTONIA", "GENEVA",
"GETTYSBURG", "GIBSONIA", "GILBERT",
"GIRARD", "GLEN BURNIE",
"GLEN CARBON", "GLEN COVE", "GLEN MILLS",
"GLENSHAW", "GLENVIEW",
"GLENWOOD", "GOLDEN CITY", "GOLIAD",
"GOODSON", "GOODYEAR", "GORHAM",
"GOSHEN", "GRANBURY", "GRANBY", "GRAND
PRAIRIE", "GRAND RAPIDS",
"GRANDVIEW", "GRANITE CITY", "GRANITE FALLS",
"GRANTS PASS",
"GRASS VALLEY", "GRAVETTE", "GRAYSVILLE",
"GREEN LANE", "GREENBRIER",
"GREENLAWN", "GREENSBORO", "GREENSBURG",
"GREENUP", "GREENVILLE",
"GREER", "GRIFFIN", "GRIFFITH",
"GROTON", "GUADALUPE", "GUILFORD",
"HADLEY", "HAGAN", "HALF WAY", "HALLANDALE
BEACH", "HAMBLETON",
"HAMBURG", "HAMDEN", "HAMILTON",
"HAMMOND", "HAMMONTON", "HAMPSHIRE",
"HAPEVILLE", "HARBORCREEK", "HARLAN",
"HARRISBURG", "HARRISON",
"HARRISONVILLE", "HARTWELL", "HASTINGS",
"HATFIELD", "HAVERHILL",
"HAWK POINT", "HAYESVILLE", "HELEN",
"HENDERSON", "HENDERSONVILLE",
"HENRICO", "HENRIETTA", "HERMITAGE",
"HERNDON", "HERSHEY", "HIALEAH",
"HIAWATHA", "HIBBING", "HICKORY", "HICKORY
GROVE", "HIDDENITE",
"HIGH HILL", "HIGH POINT", "HIGH RIDGE",
"HIGHLAND", "HIGHLAND MILLS",
"HINCKLEY", "HIRAM", "HOBART",
"HOLBROOK", "HOLDEN", "HOLDENVILLE",
"HOLLADAY", "HOLLIS", "HOLLY SPRINGS",
"HOLLYWOOD", "HOLTWOOD",
"HOMER", "HOMESTEAD", "HONEYVILLE", "HOPE
MILLS", "HOT SPRINGS",
"HOT SPRINGS NATIONAL PARK", "HOUSTON", "HUBBARD",
"HUDSON",
"HUFFMAN", "HULL", "HUMANSVILLE",
"HUNTERSVILLE", "HUNTINGDON",
"HUNTINGTON BEACH", "HUNTS POINT", "HURDLE MILLS",
"HURRICANE",
"HURST", "IMPERIAL", "INDEPENDENCE", "INDIAN
SHORES", "INDIAN TRAIL",
"INDIANA", "INDIANAPOLIS", "INDIANOLA",
"INMAN", "IOWA CITY",
"IRMO", "IRVINGTON", "IRWIN", "ISANTI",
"ISLESBORO", "ISLIP",
"ISSAQUAH", "ITHACA", "JACKSBORO",
"JACKSON", "JACKSON HTS",
"JACKSONVILLE", "JAMAICA", "JAMESTOWN",
"JASPER", "JEANNETTE",
"JEFFERSON", "JEFFERSON CITY", "JEWELL",
"JOHNSTON", "JOHNSTOWN",
"JONESBORO", "JONESPORT", "JONESTOWN",
"JOPLIN", "JUPITER", "KANKAKEE",
"KANNAPOLIS", "KANSAS CITY", "KATY",
"KEARNEY", "KELLERTON",
"KEMAH", "KENMORE", "KENNESAW", "KENT",
"KINGMAN", "KINGS MOUNTAIN",
"KINGSLAND", "KINGSTON", "KINGWOOD",
"KIRKLAND", "KUTZTOWN",
"LA QUINTA", "LA RUE", "LA VERNE",
"LAFAYETTE", "LAKE BLUFF",
"LAKE IN THE HILL", "LAKE ISABELLA", "LAKE
PLACID", "LAKE SAINT LOUIS",
"LAKE TAPPS", "LAKE VILLAGE", "LAKE WAUKOMIS",
"LAKE WORTH",
"LAKEBAY", "LAKELAND", "LAKEWOOD", "LAKEWOOD
RCH", "LAMBERTVILLE",
"LANCASTER", "LANDISVILLE", "LANSDALE",
"LAREDO", "LARGO", "LAS VEGAS",
"LATROBE", "LAUDERHILL", "LAWNDALE",
"LAWRENCE", "LAWRENCEVILLE",
"LE MARS", "LE ROY", "LEAGUE CITY",
"LEAVENWORTH", "LEAWOOD",
"LEBANON", "LECOMPTON", "LEECHBURG", "LEES
SUMMIT", "LEESBURG",
"LEESVILLE", "LEETONIA", "LENEXA",
"LENOIR", "LEVITTOWN", "LEWES",
"LEWISTOWN", "LEXINGTON", "LIBERTY TWP",
"LILLINGTON", "LINCOLN",
"LINDENHURST", "LINTON", "LISBON",
"LITCHFIELD PK", "LITHIA",
"LITITZ", "LITTLE EGG HARBOR TO", "LK FOREST PK",
"LK PEEKSKILL",
"LOCKHART", "LOCKWOOD", "LOGAN", "LOMA
LINDA", "LONE JACK", "LONG BEACH",
"LONG LANE", "LONGVIEW", "LORAIN",
"LORTON", "LOS ANGELES", "LOUISBURG",
"LOVES PARK", "LOWER BURRELL", "LOWRY CITY",
"LUBBOCK", "LUGOFF",
"LUMBERTON", "LYNBROOK", "LYNNWOOD",
"MACHESNEY PARK", "MACON",
"MAGNOLIA", "MAHOPAC", "MAHWAH",
"MAINEVILLE", "MALVERN", "MALVERNE",
"MANASSAS", "MANCHACA", "MANCHESTER",
"MANCHESTER TOWNSHIP",
"MANCHESTER TW", "MANHEIM", "MANITO",
"MANLIUS", "MANNINGTON",
"MANSFIELD", "MANSURA", "MAPLE PARK", "MARBLE
FALLS", "MARCELLUS",
"MARICOPA", "MARIETTA", "MARION",
"MARKLEYSBURG", "MARS HILL",
"MARSHALLTOWN", "MARSHFIELD", "MARSHVILLE",
"MARTINSVILLE", "MARYSVILLE",
"MASON CITY", "MASSEY", "MASSILLON",
"MASURY", "MATAWAN", "MATEWAN",
"MATTAPOISETT", "MATTHEWS", "MAYFIELD HTS",
"MAYSEL", "MC CLELLAND",
"MC DONALD", "MC KEES ROCKS", "MC SHERRYSTOWN",
"MC VEYTOWN",
"MCALESTER", "MCDONOUGH", "MCKEESPORT",
"MCKINNEY", "MECHANICSBURG",
"MECHANICSVILLE", "MEDFORD", "MEDIA",
"MEDWAY", "MELVILLE", "MEMPHIS",
"MERIDEN", "MERRIAM", "MERRICK",
"MERRILL", "MERRILLVILLE", "MESA",
"MESQUITE", "MIAMI", "MIAMI GARDENS",
"MICHIGAN CITY", "MIDDLETOWN",
"MIDLAND", "MIFFLINTOWN", "MILFORD", "MILL
CREEK", "MILLBROOK",
"MILLEDGEVILLE", "MILLINOCKET", "MILNER",
"MILTON", "MILWAUKEE",
"MINEOLA", "MINERAL SPGS", "MINERAL WELLS",
"MINNEAPOLIS", "MISSION",
"MISSION HILLS", "MISSION VIEJO", "MISSOURI CITY",
"MISSOURI VALLEY",
"MOLINE", "MONESSEN", "MONROE", "MONROE
TOWNSHIP", "MONROEVILLE",
"MONTCLAIR", "MONTEREY", "MONTICELLO",
"MOORESVILLE", "MORGANTON",
"MORGANTOWN", "MORRIS PLAINS", "MOUND",
"MOUND CITY", "MOUNT HOPE",
"MOUNT JOY", "MOUNT LAUREL", "MOUNT PLEASANT",
"MOUNT POCONO",
"MOUNT UNION", "MOUNT WOLF", "MOUNTVILLE",
"MT HOLLY", "MT PLEASANT",
"MULVANE", "MUNCIE", "MUNSTER",
"MURFREESBORO", "MURRAY", "MURRELLS INLT",
"MUSTANG", "MYERSTOWN", "MYSTIC", "N
BRANFORD", "N FT MYERS",
"NAPERVILLE", "NAPLES", "NAPOLEON",
"NASHVILLE", "NATCHITOCHES",
"NAUGATUCK", "NEOSHO", "NEPTUNE BEACH",
"NESCONSET", "NETCONG",
"NEW BLOOMFIELD", "NEW BRAUNFELS", "NEW BRITAIN",
"NEW BRUNSWICK",
"NEW CASTLE", "NEW CUMBERLAND", "NEW HAVEN",
"NEW KENSINGTON",
"NEW LONDON", "NEW ORLEANS", "NEW PRESTON",
"NEW PROVIDENCE",
"NEW ROCHELLE", "NEW TRIPOLI", "NEW ULM",
"NEW WINDSOR", "NEW YORK",
"NEWARK", "NEWBURGH HEIGHTS", "NEWINGTON",
"NEWNAN", "NEWPORT",
"NEWPORT BEACH", "NEWTON", "NEWTONVILLE",
"NIAGARA FALLS", "NIXA",
"NOANK", "NOKOMIS", "NORCROSS",
"NORFOLK", "NORMAN", "NORMANDY PARK",
"NORTH BABYLON", "NORTH HAVEN", "NORTH
HUNTINGDON", "NORTH JACKSON",
"NORTH LITTLE ROCK", "NORTH MIAMI", "NORTH PORT",
"NORTH RICHLAND HILLS",
"NORTH WALES", "NORTH WATERBORO", "NORTHFIELD",
"NORTHRIDGE",
"NORTON", "NORWALK", "NOTTINGHAM",
"NUTLEY", "NYACK", "O FALLON",
"OAK RIDGE", "OAKDALE", "OCALA",
"OCEANSIDE", "OCILLA", "OLATHE",
"OMAHA", "OMRO", "ONA", "ONALASKA",
"OPA LOCKA", "ORADLL", "ORION",
"ORONO", "ORRINGTON", "OSCEOLA",
"OSKALOOSA", "OSSINING", "OSWEGO",
"OTTAWA", "OVALO", "OVERLAND PARK",
"OWASSO", "OWEGO", "OXFORD",
"OYSTER BAY", "OZARK", "PALERMO", "PALM
CITY", "PALM HARBOR",
"PALMDALE", "PALMYRA", "PALOS HEIGHTS",
"PANA", "PAOLA", "PARK RIDGE",
"PARLIN", "PARMA", "PARRISH", "PARROTT",
"PATASKALA", "PAULS VALLEY",
"PAXTON", "PEA RIDGE", "PEARLAND",
"PECULIAR", "PEEKSKILL", "PEKIN",
"PELION", "PEMBROKE", "PEMBROKE PINES", "PENN
YAN", "PENNELLVILLE",
"PENNSBURG", "PENNSVILLE", "PEORIA",
"PERRY", "PERRYOPOLIS",
"PERRYSBURG", "PERRYVILLE", "PHARR",
"PHILADELPHIA", "PHILIPPI",
"PHOENIX", "PICKENS", "PICKERINGTON",
"PIERSON", "PILOT MOUNTAIN",
"PINE BLUFF", "PINE HILL", "PINEVILLE",
"PINNELLAS PARK", "PISCATAWAY",
"PITMAN", "PITTSBURGH", "PLACIDA",
"PLAINFIELD", "PLANO", "PLANT CITY",
"PLATTEKILL", "PLEASANT HILL", "PLEASANT HOPE",
"PLYMOUTH", "POCONO LAKE",
"POMFRET CENTER", "POMPANO BEACH", "POOLER",
"PORT CARBON", "PORT CHARLOTTE",
"PORT NORRIS", "PORT ORANGE", "PORT SAINT LUCIE",
"PORT WASHINGTON",
"PORTAGE", "PORTER", "PORTERSVILLE",
"PORTLAND", "POTTSVILLE",
"POUGHKEEPSIE", "POWDER SPRINGS", "POWELL",
"PRAIRIE VILLAGE",
"PRESCOTT", "PRESCOTT VALLEY", "PRINCETON",
"PROSPECT", "PT PLEASANT",
"PUNTA GORDA", "PURCHASE", "QUAKERTOWN",
"QUEENS VLG", "QUINCY",
"RALEIGH", "RANDLEMAN", "RANDOLPH",
"RAYTOWN", "READING", "READLYN",
"RED BANK", "RED HOUSE", "RED LION",
"REEDERS", "REGO PARK",
"REHOBOTH BCH", "REIDSVILLE", "RENO",
"RENTON", "REPUBLIC", "RICH HILL",
"RICHARDS", "RICHMOND", "RICHMOND HILL",
"RIDGEWOOD", "RINCON",
"RIO GRANDE CITY", "RIO RANCHO", "RIVERDALE",
"RIVERHEAD", "RIVERSIDE",
"ROANOKE", "ROCHELLE", "ROCHESTER", "ROCK
HILL", "ROCKAWAY BCH",
"ROCKFORD", "ROCKMART", "ROCKY HILL", "ROCKY
MOUNT", "ROGERS",
"ROGERSVILLE", "ROMULUS", "ROOSEVELT",
"ROSAMOND", "ROSCOE",
"ROSENBERG", "ROSENDALE", "ROSWELL", "ROTONDA
WEST", "ROUGEMONT",
"ROXBORO", "ROY", "RUNNELLS", "RURAL
HALL", "RUSH VALLEY", "RUSKIN",
"RUSTBURG", "RUTHER GLEN", "RUTHERFORDTON",
"S DEERFIELD", "SACO",
"SAGINAW", "SAINT AUGUSTINE", "SAINT CHARLES",
"SAINT CLAIR",
"SAINT CLAIRSVILLE", "SAINT LOUIS", "SAINT MARYS",
"SAINT MATTHEWS",
"SAINT PAULS", "SAINT PETERS", "SAINT PETERSBURG",
"SALEM", "SALISBURY",
"SALT LAKE CITY", "SALTSBURG", "SALUNGA",
"SAMMAMISH", "SAN ANTONIO",
"SAN BENITO", "SAN CLEMENTE", "SAN DIEGO",
"SAN ELIZARIO", "SAN JUAN",
"SANDUSKY", "SANDY", "SANFORD",
"SANGERVILLE", "SANTA ANA", "SARASOTA",
"SARATOGA SPRINGS", "SARCOXIE", "SAUGUS",
"SAVANNAH", "SAYVILLE",
"SCALY MOUNTAIN", "SCHAEFFERSTOWN", "SCHULENBURG",
"SCOTT", "SCOTTSDALE",
"SEAFORD", "SEALE", "SEATTLE", "SEDONA",
"SEGUIN", "SELDEN",
"SENECA", "SENOIA", "SEVEN VALLEYS",
"SEYMOUR", "SHARON", "SHARPSBURG",
"SHARPSVILLE", "SHAVANO PARK", "SHAWNEE",
"SHELLSBURG", "SHELTON",
"SHENANDOAH", "SHORELINE", "SHOREWOOD",
"SHREVEPORT", "SICKLERVILLE",
"SILER CITY", "SILOAM SPRINGS", "SIMON",
"SIMPSONVILLE", "SIMSBURY",
"SIOUX CITY", "SIOUX FALLS", "SKOKIE",
"SKOWHEGAN", "SLATINGTON",
"SLIDELL", "SMITHFIELD", "SN BERNRDNO",
"SNELLVILLE", "SOCORRO",
"SOMERS", "SOPHIA", "SOUTH AMBOY", "SOUTH
BELOIT", "SOUTH BEND",
"SOUTH DARTMOUTH", "SOUTH HOUSTON", "SOUTH PARK",
"SOUTH PLAINFIELD",
"SOUTH SIOUX CITY", "SOUTHAMPTON", "SOUTHBURY",
"SOUTHGATE",
"SPARKS", "SPARROW BUSH", "SPENCER",
"SPRING", "SPRING BRANCH",
"SPRING GROVE", "SPRING HILL", "SPRING HOPE",
"SPRING VALLEY",
"SPRINGDALE", "SPRINGFIELD", "SPRINGFIELD
GARDENS", "SPRINGHILL",
"SPRINGTOWN", "SPRNGFLD GDNS", "SPRUCE PINE",
"ST PETERSBURG",
"ST. GEORGE", "STAFFORD", "STAMFORD",
"STANDISH", "STANLEY",
"STANTON", "STATEN ISLAND", "STATESVILLE",
"STERLING", "STILLMAN VALLEY",
"STILWELL", "STOCKBRIDGE", "STOCKTON", "STONE
MTN", "STRAFFORD",
"STRATFORD", "STRONGSVILLE", "STROUDSBURG",
"STRUTHERS", "SUFFIELD",
"SUGAR HILL", "SUGAR LAND", "SULPHUR",
"SUMMERVILLE", "SUMMIT",
"SUN CITY", "SUNBURY", "SUWANEE",
"SWANSEA", "SWANTON", "SWEENY",
"SWISSVALE", "SYCAMORE", "SYLVANIA",
"SYRACUSE", "TACOMA", "TAFTVILLE",
"TAMPA", "TAPPAHANNOCK", "TAR HEEL",
"TAUNTON", "TAYLORVILLE",
"TECUMSEH", "THE WOODLANDS", "THEODOSIA",
"THOMASTON", "THOMASVILLE",
"TIERRA VERDE", "TIFTON", "TILLSON",
"TILTON", "TINLEY PARK",
"TOCCOA", "TOLEDO", "TOLLAND",
"TOMBALL", "TOMS RIVER", "TOPEKA",
"TOPSHAM", "TORRINGTON", "TOVEY",
"TOWNSEND", "TRAVELERS RST",
"TRENT", "TRINITY", "TROUTMAN", "TROY",
"TRUMBULL", "TUCKER",
"TULALIP", "TURNER", "TUSCUMBIA",
"TYRONE", "UNION", "UNION CITY",
"UNIVERSAL CTY", "UNIVERSITY HTS", "UPPR
CHICHSTR", "URBANA",
"URBANDALE", "UTICA", "VAIL", "VALE",
"VALENCIA", "VALPARAISO",
"VAN BUREN", "VAN METER", "VAN WERT",
"VANDERGRIFT", "VASSALBORO",
"VAUGHN", "VENICE", "VERNAL", "VERNON",
"VERONA", "VICTOR", "VIDALIA",
"VIENNA", "VILLA GROVE", "VILLA RIDGE",
"VOLANT", "W HAMPTON BCH",
"W TERRE HAUTE", "WADSWORTH", "WAHOO", "WAKE
FOREST", "WALDEN",
"WALLINGFORD", "WALLINGTON", "WALNUT COVE",
"WANAQUE", "WARFORDSBURG",
"WARMINSTER", "WARREN", "WARSAW",
"WARTHEN", "WASHINGTON", "WASOLA",
"WATAUGA", "WATERBURY", "WATERFORD",
"WATERLOO", "WATERVILLE",
"WATKINS GLEN", "WAXAHACHIE", "WAYCROSS",
"WAYNESBORO", "WEBSTER",
"WEIRTON", "WELLSBORO", "WELLSVILLE",
"WENTZVILLE", "WESLACO",
"WEST CHESTER", "WEST DEPTFORD", "WEST DES
MOINES", "WEST HAVEN",
"WEST HICKORY", "WEST LIBERTY", "WEST MIFFLIN",
"WEST PALM BEACH",
"WEST POINT", "WEST READING", "WEST SENECA",
"WEST SUFFIELD",
"WEST VALLEY CITY", "WESTERVILLE", "WESTHAMPTON",
"WESTMINSTER",
"WESTMORELAND CITY", "WESTPORT", "WESTVILLE",
"WETHERSFIELD",
"WHARTON", "WHEELING", "WHITE PLAINS",
"WHITEHALL", "WHITESTONE",
"WHITESTOWN", "WHITING", "WHITMAN",
"WHITTIER", "WICHITA", "WILDWOOD",
"WILLARD", "WILLIAMSBURG", "WILLIAMSPORT",
"WILLOW GROVE", "WILLOWBROOK",
"WILLOWICK", "WILMETTE", "WILMINGTON",
"WILSON", "WILTON MANORS",
"WIMBERLEY", "WINDCREST", "WINDER",
"WINNEBAGO", "WINSIDE", "WINSTON",
"WINSTON SALEM", "WINTERSET", "WINTHROP",
"WOLCOTT", "WOODBRIDGE",
"WOODBURY HEIGHTS", "WOODLAND PARK", "WOODLAWN",
"WOODS CROSS",
"WOODSIDE", "WOODSTOCK", "WORTHINGTON",
"WYOMISSING", "YARMOUTH",
"YOE", "YONKERS", "YORK", "YORKTOWN",
"YORKTOWN HEIGHTS", "YOUNG HARRIS",
"YOUNGSTOWN", "YPSILANTI", "ZELIENOPLE",
"ZEPHYRHILLS"), class = "factor"),
clusters = c(6L, 10L, 3L, 10L, 5L, 6L, 10L, 6L, 6L, 7L, 5L,
7L, 8L, 8L, 3L, 6L, 3L, 10L, 7L, 10L, 10L, 4L, 2L, 8L, 9L,
1L, 4L, 4L, 7L, 5L, 10L, 5L, 5L, 10L, 6L, 6L, 10L, 6L, 7L,
10L, 10L, 3L, 3L, 6L, 3L), Longitude = c(-93.883554, -90.582058,
-83.868923, -89.544083, -72.902467, -94.458904, -90.588533,
-94.527843, -92.93769, -80.029456, -70.58809, -82.888789,
-80.113071, -82.6661, -81.372992, -95.840964, -82.016013,
-89.92625, -80.276676, -89.778385, -87.641063, -94.888036,
-117.663119, -82.530568, -75.574437, -122.209047, -96.799309,
-95.746255, -80.553953, -73.923314, -87.713482, -73.9731,
-73.8187, -87.987023, -93.759478, -94.110903, -90.00597,
-93.257109, -79.932483, -90.201858, -89.100233, -84.625923,
-84.567614, -93.912921, -84.612564), Latitude = c(34.503045,
38.752515, 33.406527, 40.893588, 41.733088, 38.999032, 41.657674,
38.890929, 37.639766, 42.099693, 43.53462, 40.142492, 26.538149,
27.9062, 31.90104, 34.833083, 35.118836, 35.136047, 39.425712,
40.519207, 40.101126, 30.044457, 33.62287, 27.910276, 39.752254,
47.403778, 32.961929, 29.820199, 38.408649, 40.668828, 41.983948,
40.58116, 40.7253, 41.921667, 41.669921, 36.442552, 38.564663,
37.455315, 40.867774, 38.783554, 42.244381, 34.024332, 34.001644,
36.622704, 34.017832), distances_Me = c(1879089.079, 1437296.523,
1185638.742, 1313997.97, 156759.9125, 1759443.351, 1398398.997,
1767861.917, 1668917.322, 534234.2576, 431749.2965, 758508.4701,
1657031.938, 1615575.668, 1169085.702, 2024642.021, 930944.4681,
1525322.746, 553069.7532, 1337002.822, 1161367.37, 2223496.376,
3918520.212, 1609088.602, 164252.5146, 3878581.001, 2197910.688,
2304526.789, 614908.3151, 11075.24597, 1160375.454, 494.2997496,
21063.72622, 1182681.434, 1662351.873, 1810881.911, 1393581.436,
1701982.013, 504395.772, 1404348.991, 1276505.454, 1190457.718,
1188029.899, 1787261.336, 1189994.055), distances_Mi = c(1167.607468,
893.0913246, 736.719012, 816.477441, 97.40573055, 1093.263337,
868.9216123, 1098.494372, 1037.01328, 331.9565399, 268.2755749,
471.3135552, 1029.628072, 1003.868436, 726.4334682, 1258.049536,
578.4599174, 947.7880794, 343.6603307, 830.7719404, 721.6375366,
1381.611443, 2434.846498, 999.8375755, 102.0614003, 2410.029515,
1365.713293, 1431.96122, 382.0848884, 6.881813138, 721.0211909,
0.30714248, 13.08834388, 734.8814328, 1032.933715, 1125.225657,
865.9281298, 1057.55865, 313.4158337, 872.6187534, 793.1807589,
739.7133739, 738.2048023, 1110.548567, 739.4252678), ID = 2308:2352),
row.names = c(NA,
-45L), class = "data.frame")
Proprietary
-----Original Message-----
From: Jim Lemon <drjimlemon at gmail.com>
Sent: Wednesday, May 13, 2020 1:39 AM
To: Poling, William <PolingW at aetna.com>
Cc: r-help at r-project.org
Subject: [EXTERNAL] Re: [R] Help with Radius problem
**** External Email - Use Caution ****
Hi Bill,
A while ago I devised a couple of functions to accumulate millions of geographic
locations of events and then display the resulting matrix of values on an
existing plot. This may be of use to you, at least in the visualization of the
density of the locations. As your example data only included a few points, the
resulting plot looks pretty chunky as I had to use a large symbol to make the
cells with non-zero counts obvious.
# read in your sample data
source("wp_data.R")
library(plotrix)
geomat<-makeDensityMatrix(geodat[,c("latitude","longitude")],
xlim=range(geodat$longitude),ylim=range(geodat$latitude))
# Range of density (>0) - 1.119816 3.922018
latlim<-range(geodat$latitude)
lonlim<-range(geodat$longitude)
library(maps)
map("world",xlim=lonlim,ylim=latlim)
axis(1)
axis(2)
densityGrid(geomat,range.cex=c(1,5),xlim=lonlim,ylim=latlim,
red=c(0.5,1),green=0,blue=0,pch=15)
Jim
On Wed, May 13, 2020 at 10:57 AM Poling, William via R-help <r-help at
r-project.org> wrote:>
> #RStudio Version Version 1.2.1335
> sessionInfo()
> # R version 4.0.0 Patched (2020-05-03 r78349)
> #Platform: x86_64-w64-mingw32/x64 (64-bit) #Running under: Windows 10
> x64 (build 17763)
>
> Hello I am trying to figure out how to create concentration of ID's in
> the following data, based on determining the highest concentration in
> the smallest radius area based on Longitude and Latitude (geo
> location)
>
> I have reviewed many websites looking for a function or tutorial, (if
> you are aware of either please let me know)
>
NOTICE TO RECIPIENT OF INFORMATION:
This e-mail may contain confidential or privileged information. If you think you
have received this e-mail in error, please advise the sender by reply e-mail and
then delete this e-mail immediately.
This e-mail may also contain protected health information (PHI) with information
about sensitive medical conditions, including, but not limited to, treatment for
substance use disorders, behavioral health, HIV/AIDS, or pregnancy. This type of
information may be protected by various federal and/or state laws which prohibit
any further disclosure without the express written consent of the person to whom
it pertains or as otherwise permitted by law. Any unauthorized further
disclosure may be considered a violation of federal and/or state law. A general
authorization for the release of medical or other information may NOT be
sufficient consent for release of this type of information.
Thank you. Aetna