Identify 4 best locations where client (leading cardiac hospital in Kochi) can place bill boards with hospital’s emergency numbers and Ambulance service details for promoting the hospital
Decision problem: Where should the hospital place the Bill boards in city.
Research Objectives: Explore the types/categories who are prospect consumers for the hospital and Idetify the locations where there is high proximity of such consumers
We selected Cochin as City for the analysis because of following reasons:
Source: Saffola Survey - Times of India
There are 2 Major consumers for Hospitals:
These are 2 main categories of patients who would be target audience for bill boards
Before Identify the entity list for searching the places / consumers, we need to identify the causes and extract Etities.
Main reasons for cardiac diseases are:
Based on above reasons the potential etities which would be suitable are selected as below:
location of KochiThe location of Kochi is 9.9700° N, 76.2800° E (We assumed this is the Location of hospital) and the total area of Kochi is 94.88 Square KM. Inorder to get optional locations we picked 10 Miles (~15 Kilometers) as Radius for analysis. As this is Cardiac hospital it may not be advisable to promote beyond 10 miles distance from Hospital.
Include the necessary libraries
options(warn=-1)
library("RCurl")
library("jsonlite")
library("plotGoogleMaps")
library("geosphere")
Search using Google API for Malls, Hospitals, Meal_takeaways ad Restaurants in 10 Miles radius around the hospital.
key = "AIzaSyAUVDc3LzW6pVgcAkP2k4EoH_JX5noq-m8"
# malls search
url = paste0("https://maps.googleapis.com/maps/api/place/radarsearch/json?&query=malls+in+cochin&types=shopping_mall&minprice=4andmaxprice=4,ma&location=9.9700,76.2800&radius=10000&key=",key)
doc <- getURL(url)
x <- jsonlite::fromJSON(doc)
malls = x$results$geometry$location
# hospitals
url = paste0("https://maps.googleapis.com/maps/api/place/radarsearch/json?&query=hospitals+in+kochi&types=hospital&minprice=4andmaxprice=4&location=9.9700,76.2800&radius=10000&key=",key)
doc <- getURL(url)
x <- jsonlite::fromJSON(doc)
hospitals = x$results$geometry$location
#meal_takeaway
url = paste0("https://maps.googleapis.com/maps/api/place/radarsearch/json?&query=meals+take+away+in+kochi&types=meal_takeaway&minprice=4andmaxprice=4&location=9.9700,76.2800&radius=10000&key=",key)
doc <- getURL(url)
x <- jsonlite::fromJSON(doc)
meal_takeaway = x$results$geometry$location
#Restauraunt
url = paste0("https://maps.googleapis.com/maps/api/place/radarsearch/json?&query=restauraunts+in+kochi+malls&types=restraraunts&minprice=4andmaxprice=4&location=9.9700,76.2800&radius=10000&key=",key)
doc <- getURL(url)
x <- jsonlite::fromJSON(doc)
restaurants = x$results$geometry$location
Aggregate all the results and write the results into one csv file, the file will be placed in your default mydocuments folder
malls$type = "Mall"
hospitals$type = "Hospital"
meal_takeaway$type = "meal_takeaway"
restaurants$type = "restaurants"
data = rbind(malls,hospitals,meal_takeaway,restaurants)
write.csv(data,"kochi_places.csv", row.names = F)
dim(data)
## [1] 711 3
As you can see total of 711 locations in Cochin are Identified with above criteria
Plot the all 711 locations on Google Maps to explore the areas with highest Density
#sample = all aggregated data
sample = data
coordinates(sample) <-~ lng +lat # Create cordinates
proj4string(sample) = CRS('+proj=longlat +datum=WGS84') # Add Projections
m<-mcGoogleMaps(sample,zcol = "type", mapTypeId='ROADMAP') # Plot on Google maps
Need to zoom the map by 2 notches to see the exact map as image
As you ca see the areas with highest density of ay of the entities would be potential areas for advertising.
Below mapshows the areas with top highest density
Use R Leaftlet Library to plot the selected Bill board areas on Map
library("leaflet")
m = leaflet() %>%
addTiles() %>%
addMarkers(lat=9.9700, lng=-76.2800, popup="Billboard Areas")
cities <- read.csv(textConnection("
City,Lat,Long,Pop
SelectedArea1,9.97715,76.27732,20
SelectedArea2,9.96541,76.28420,20
SelectedArea3,9.96781,76.30490,20
SelectedArea4,9.96578,76.24211,20
Hospital,9.9700,76.2800,20
"))
leaflet(cities) %>% addTiles() %>%
addCircles(lng = ~Long, lat = ~Lat, weight = 1,
radius = ~sqrt(Pop) * 30, popup = ~City)
Caluclate the distance between each bill board area selected to ensure they are far enough
area1 <- c(9.97715,76.27732)
area2 <- c(9.96541,76.28420)
area3 <- c(9.96781,76.30490)
area4 <- c(9.96578,76.24211)
hospital <- c(9.9700,76.2800)
splaces = rbind(area1,area2,area3,area4,hospital)
# calculate distances
dist_mat = matrix(0,nrow(splaces),nrow(splaces))
for (i in 1:nrow(splaces)){
for (j in 1:nrow(splaces)){
dist_mat[i,j] = distCosine(splaces[i,],splaces[j,], r=6378173)/1000
}
}
dist_mat
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0.0000000 0.8262232 3.080081 3.931094 0.3530577
## [2,] 0.8262232 0.0000000 2.305196 4.685474 0.4829907
## [3,] 3.0800808 2.3051957 0.000000 6.989996 2.7724729
## [4,] 3.9310938 4.6854740 6.989996 0.000000 4.2193946
## [5,] 0.3530577 0.4829907 2.772473 4.219395 0.0000000
As shown in the results, the Bill board areas selected are far from each other at a distace of 0.3 miles to 7 miles
Caluclate the distance between each all the 711 etity points selected and create a clustering Dendogram
Including the entire distance calculations for all 711 entities is slowing the markdown drastically. hence we excluded it from the markdown and shared it in R Code.
….