knitr::opts_chunk$set(
  collapse = TRUE,
  cache = TRUE,
  message = FALSE, 
  warning = FALSE)

gbdcd

Travis Build Status AppVeyor Build Status Coverage Status DOI

Overview

An R package implementing the Bayesian Detection of Clusters and Discontinuities.

Installation

library(devtools)

devtools::install_github("leandromineti/gbdcd")

If you are a Windows user, make sure you have Rtools installed.

Usage

library(gbdcd)

data("aneeldata", package = "gbdcd")
data("aneelshape", package = "gbdcd")

target_variable <- aneelshape$z_Precipitation
neighbors <- aneeldata$connections

out <- gaussianBDCD(y = target_variable, 
                    neigh = neighbors, 
                    c = 0.35, 
                    n_iterations = 100000, 
                    burn_in = 50000, 
                    mu0 = 0, 
                    sigma0 = sqrt(2))

Results

From the results obtained in the previous function we can look at many variables like: posterior distribution, proximity dendogram and the map regionalization.

Posterior distribution

barplot(table(out$k.MCMC)/sum(table(out$k.MCMC)), col="light blue",
        xlab="number of groups", ylab="estimated probability")
grid()
barplot(table(out$k.MCMC)/sum(table(out$k.MCMC)), add=T, col="light blue")

Proximity dendogram

n_cluster <- as.numeric(names(which.max(table(out$k.MCMC))))

plot(out$cluster.info, ylab="d(i~j)", main="Proximity Dendrogram", xlab="", 
     labels=aneelshape$DMU, cex=0.6)

groups <- cutree(out$cluster.info, k = n_cluster)
rect.hclust(out$cluster.info, k=n_cluster, border="red")

Map regionalization

library(RColorBrewer)
library(spdep)

colrs <- brewer.pal(n_cluster, "Set3")

par(mfrow = c(1,2))
plot(aneelshape, col=colrs[groups])
boxplot(aneelshape$z_Precipitation ~ groups, col=colrs,
        ylab="Precipitation", xlab="Geographical clusters")

Todo list



leandromineti/gbdcd documentation built on Sept. 24, 2020, 12:43 p.m.