CAR Models from R

using Zimbabwe DHS data

KM Wambui/E Musenge/Zvifadzo Matsena-Zingoni

Shape {file} files

most of the programatic ways of manipulating spatial data depend on the GDAL (Geospatial Data Analysis Library) and GEOS (Geometry Engine- Open Source) libraries

Why CAR or SAR?

1 Non-spatial model

My House Value is a function of my home Gardening Investment.

SAR model

My House Value is a function of the House Values of my neighbours.

is more suitable where there are second order dependency or a more global spatial autocorrelation

CAR model

My House Value is a function of the Gardening Investment of my neighbours

first order dependency or relatively local spatial autocorrelation

Install BUGS software

Packages for this session

## load the packages needed for this module
library(R2OpenBUGS) ## Help in connecting R to OpenBugs
library(tidyverse) ## package for data manipulation
library(rgeos) ## Geomegry Engine- Open Source (GEOS)
library(maptools) ##  R package with useful map tools
library(broom) ## for converting a map to a data frame
library(rgdal) ## Geospatial Data Analysis Library (GDAL)"
library(rgeos) # # "Geomegry Engine- Open Source (GEOS)" -- check your shape file
library(mcmc)
library(spdep)
library(data.table)
library(haven) ## read in stata files
library("PerformanceAnalytics") ## EDA
library(INLA) ## inla
library("coda")
## install many packages at a go
packagesLoad <- c("R2OpenBUGS", "tidyverse", "rgeos", "maptools", "broom", "rgdal", 
    "rgeos", "mcmc", "spdep", "data.table", "haven", "PerformanceAnalytics")
for (i in 1:length(packagesLoad)) {
    if (require(packagesLoad[i], character.only = TRUE) == FALSE) {
        install.packages(packagesLoad[i])
    }
}


## install INLA for later
install.packages("INLA", repos = c(getOption("repos"), INLA = "https://inla.r-inla-download.org/R/stable"), 
    dep = TRUE)

https://bit.ly/2Z7VSor

https://bit.ly/2PepAV4

remove the data in the environment

rm(list = ls())

  1. https://stats.stackexchange.com/questions/277/spatial-statistics-models-car-vs-sar

  2. http://www.openbugs.net/w/Downloads