如何在R中使用INLA映射预测?

时间:2015-10-14 00:01:49

标签: r maps prediction shapefile

我遇到两个问题:

  1. 根据INLA回归创建预测。
  2. 使用shapefile映射这些预测。
  3. DATASET :(从excel复制)

    ID_1    NAME_1  x   y
    1   Aceh    0.32    2.89
    2   Bali    0.53    2.66
    3   Bangka-Belitung 0.98    2.93
    4   Banten  0.11    2.81
    5   Bengkulu    0.73    3.06
    

    问题1:获得预测。我的代码如下(从各种在线资源和印度尼西亚的shapefile拼凑而成)。

    rm(list=ls())
    
    library(maptools)
    library(spdep)
    library(INLA)
    library(lattice)
    
    idn.gen <- readShapePoly("C:/Users/swulf/Desktop/IDN/maps/StatPlanet_Plus/Shapefile_map_(ESRI)/map/IDN province/IDN_adm1.shp", IDvar="ID_1")
    idn.nb <- poly2nb(idn.gen)
    nb2INLA("idn.graph", idn.nb)
    #This create a file called ``LDN-INLA.adj'' with the graph for INLA
    idn.adj <- paste(getwd(),"/idn.graph",sep="")
    
    
    data <- read.csv("test for map.csv", header=TRUE)
    
    
    g = system.file("demodata/idn.graph", package="INLA")
    formula = y ~ f(ID_1,model="bym", graph.file=g) + x
    # formula = y ~ f(ID_1,model="bym", graph=idn.adj) + x 
    # (i'm not sure which formula syntax of graph file is preferred)
    result = inla(formula, family="normal", data=data)
    
    pred <- result$summary.random$ID$mean
    

    shapefile从http://www.gadm.org/country下载到印度尼西亚,等级为adm1。出于某种原因,“pred”长度为66行,但我希望5行与我的原始数据集相对应。基本上我想要每个ID_1的预测。

    映射对我来说也很困难。我找到了不同的代码来映​​射,但还没有让它们中的任何一个工作。关于哪个包最好的建议会有所帮助(maptools vs lattice vs else)。

0 个答案:

没有答案