0

经过几天的试用 n 在线搜索,我未能将空间点数据框转换为多边形,然后转换为空间多边形。

数据(来自 DHS 的典型地理数据)共有 400 个集群。这是数据页面的网址:

在此处输入图像描述

为了运行“Bayes_cluster”程序,我需要创建这个多边形和空间多边形以在 SpatialEpi r 包中创建一个 sp.object。如何为集群实施省级(津巴布韦 Admin_level 1)估计?我的目标是估计单个集群和省级的重要 HIV 热点。

我的代码:

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)
4

0 回答 0