##### GRAPHICS ######################################################################## #### need to get polygon objects into R and in a form usable by INLA #### shapefiles can be imported to R #### GeoBUGS format map files can b exported from WInbUGS and converted for INLA #### getting polygons into R ####################################################### ### from shapefiles ################################################################## library(maptools) polys<-readShapePoly("filename.shp") plot(polys) #example: setwd("C:/A_NEWER_FOLDER/A_NEW_FOLDER/A_courses/A_courses/Spatial Statistics _workshop (2013)/participant files/co45_d00_shp") polySC<-readShapePoly("co45_d00.shp") plot(polySC) ### from GeoBUGS map files ########################################################## Export a map file in SPlus format into a text file. (adjacency tool: adj matrix). I have done this already: SCgeobugsSPlus.txt setwd("C:/A_NEWER_FOLDER/A_NEW_FOLDER/A_courses/A_courses/Spatial Statistics _workshop (2013)/participant files") polySC<-readSplus("SC_geobugsSPlus.txt") plot(polySC) polySC is a polygon object and can be used for mapping on R. However INLA requires that a special format is used when fitting models with spatial components. This format can be obtained via two routes: 1) if adj and num vectors are available (already read into R) then the command geobugs2inla(adj,num, graph.file="SC.poly.txt") will create a valid spatial graph file for inla models 2) using library spdep library(spdep) adjpoly<-poly2nb(polySC) nb2INLA("SC.poly.txt",adjpoly) will create the graph file "SC.poly.txt" ### General purpose polygon mapping tool:fillmap.R ################################# #### fillmap creates thematic maps based on data in vectors and polygons which have been #### created on R or imported ######################################################## setwd(.....working directory.....) source("fillmap.R") polySC is a polygon object that can be used for mapping a model fit is obtained in 'result1' then we can map result1$summary.random[,2] by the following: rand<-result1$summary.random[,2] fillmap(polySC,"random effect",rand,n.col=6)