0

I failed to convert a spatialpoint dataframe to polygon and then spatialpolygon after days of trial n online search.

The data (a typical geographic data from DHS) has a total of 400 clusters. Here is the url to the data page:

enter image description here

I need to create this polygon and spatial polygon to create an sp.object in SpatialEpi r package in order to run the "Bayes_cluster" program. How to implement a province-level(for Zimbabwe Admin_level 1) estimate for the clusters? My goal is to estimate significant HIV hotspots at individual cluster and provincial level.

My code:

library(sp)
library(SpatialEpi)
library(spatstat)
library(rgdal)
library(maptools)
library(Matrix)
library(spdep)
library(raster)

dat<- read.csv("hiv_data_R.csv")
summary(dat)
population<-dat$pop
cases<-dat$obs
#Estimate expected number of cases
exp<-expected(dat$pop, dat$obs, 1)
dat$exp<-exp

#To convert latlong to centroid
dat<- read.csv("hiv_data_R1.csv")
centroids <- latlong2grid(dat[,1:2])

#To convert ZWGE72FL.shp to polygon and then spatial polygon
#ZWGE72FL is the shape file that comes with the Zimbabwe DHS data 
#with coordinates for 400clusters in the data frame(hiv_data_R1)

Zmb_shp<-readOGR(dsn=".", layer="ZWGE72FL")
coordinate.system <-'+proj=latlong'
poly<-polygon(Zmb_shp)
spa_poly<-polygon2spatial_polygon(poly, coordinate.system, dat$ID_1)

#To convert ZWE_adm1 polygon then spatial polygon
#ZWE_adm1 is the adminstrative level 1 for the 10 regions in Zimbabwe
Zim_map<-readOGR(dsn=".", layer="ZWE_adm1")
coordinate.system <-'+proj=latlong'
poly<-polygon(Zim_map)
sp_poly<-polygon2spatial_polygon(poly, coordinate.system, dat$ID_1)

#Goal: My goal is to generate the spatial polygon of both shape files 
#then use either of the two as "sp.object" in Bayes_clusters as defined bel


## Set parameters
y <- dat$obs
E <- dat$exp
population<-dat$pop
max.prop <- 0.15
shape <- c(2976.3, 2.31)
rate <- c(2977.3, 1.31)
J <- 7
pi0 <- 0.95
n.sim.lambda <- 10^4
n.sim.prior <- 10^5
n.sim.post <- 10^5
centroids <- latlong2grid(dat[,1:2])
sp.obj<- Zim_map/Zim_shp


#Implent Bayes_cluster
output <- bayes_cluster(y, E, population, sp.obj, centroids, max.prop,
               shape, rate, J, pi0, n.sim.lambda, n.sim.prior,  n.sim.post)
James Z
  • 12,209
  • 10
  • 24
  • 44
  • Please provide us with enough information to reproduce the issue you're having. This link has some guidelines that may help in that regard. https://stackoverflow.com/help/mcve. If you take the time to find the minimal, complete, and verifiable example, you'll definitely improve your odds of getting a helpful answer. You may end up finding the answer to your question too! :) – Seth Difley Aug 05 '17 at 12:57
  • Many thanks. I just posted the code I have been working on. Kindly help me double check the parameter settings as well. – ATILOLA Glory Aug 05 '17 at 14:15

0 Answers0