Learn R Programming

Kernelheaping (version 2.3.0)

dshapebivr: Bivariate Kernel density estimation for data classified in polygons or shapes

Description

Bivariate Kernel density estimation for data classified in polygons or shapes

Usage

dshapebivr(
  data,
  burnin = 2,
  samples = 5,
  adaptive = FALSE,
  shapefile,
  gridsize = 200,
  boundary = FALSE,
  deleteShapes = NULL,
  fastWeights = TRUE,
  numChains = 1,
  numThreads = 1
)

Arguments

data

data.frame with 3 columns: x-coordinate, y-coordinate (i.e. center of polygon) and number of observations in area.

burnin

burn-in sample size

samples

sampling iteration size

adaptive

TRUE for adaptive kernel density estimation

shapefile

shapefile with number of polygons equal to nrow(data)

gridsize

number of evaluation grid points

boundary

boundary corrected kernel density estimate?

deleteShapes

shapefile containing areas without observations

fastWeights

if TRUE weigths for boundary estimation are only computed for first 10 percent of samples to speed up computation

numChains

number of chains of SEM algorithm

numThreads

number of threads to be used (only applicable if more than one chains)

Value

The function returns a list object with the following objects (besides all input objects):

Mestimates

kde object containing the corrected density estimate

gridx

Vector Grid of x-coordinates on which density is evaluated

gridy

Vector Grid of y-coordinates on which density is evaluated

resultDensity

Matrix with Estimated Density for each iteration

resultX

Matrix of true latent values X estimates

Examples

Run this code
# NOT RUN {
library(maptools)

# Read Shapefile of Berlin Urban Planning Areas (download available from:
# https://www.statistik-berlin-brandenburg.de/opendata/RBS_OD_LOR_2015_12.zip)
Berlin <- rgdal::readOGR("X:/SomeDir/RBS_OD_LOR_2015_12.shp") #(von daten.berlin.de)

# Get Dataset of Berlin Population (download available from:
# https://www.statistik-berlin-brandenburg.de/opendata/EWR201512E_Matrix.csv)
data <- read.csv2("X:/SomeDir/EWR201512E_Matrix.csv")

# Form Dataset for Estimation Process
dataIn <- cbind(t(sapply(1:length(Berlin@polygons),
 function(x) Berlin@polygons[[x]]@labpt)), data$E_E65U80)

#Estimate Bivariate Density
Est <- dshapebivr(data = dataIn, burnin = 5, samples = 10, adaptive = FALSE,
                 shapefile = Berlin, gridsize = 325, boundary = TRUE)
# }
# NOT RUN {
# Plot Density over Area:
# }
# NOT RUN {
breaks <- seq(1E-16,max(Est$Mestimates$estimate),length.out = 20)
image.plot(x=Est$Mestimates$eval.points[[1]],y=Est$Mestimates$eval.points[[2]],
          z=Est$Mestimates$estimate, asp=1, breaks = breaks,
          col =  colorRampPalette(brewer.pal(9,"YlOrRd"))(length(breaks)-1))
plot(Berlin, add=TRUE)
# }

Run the code above in your browser using DataLab