CAR model how to run the code

setwd('C:\Users\zaatour\Desktop\SVI')
SVI = read.csv("pasco2.csv")

library(sf)
library(ggplot2)
library(tmap)
library(tmaptools)
library(leaflet)
library(dplyr)
options(scipen = 999 )
map <- st_read("pasco.shp", stringsAsFactors = FALSE)
packages <- c("CARBayes", "sf", "tidycensus", "janitor", "tidyverse", "spData", "spdep")

miss_pkgs <- packages[!packages %in% installed.packages()[,1]]

if(length(miss_pkgs) > 0){
install.packages(miss_pkgs)
}

invisible(lapply(packages, library, character.only = TRUE))

rm(miss_pkgs, packages)
list.nb <- poly2nb(map, row.names = rownames(SVI)) #list of neighbours of each city
?nb2mat
list.nb
A <- nb2mat(list.nb,style="B")
A
w <- poly2nb(col_sp) # queen neighborhood
w
model.hoval <- CARBayes::S.CARleroux(Cumulative.cases ~ SVI, data = SVI, W = W, family = "gaussian", burnin = 20000, n.sample = 100000, thin = 10)

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.