dshapebivr: Bivariate Kernel density estimation for data classified in...

Description Usage Arguments Value Examples

View source: R/functions.R

Description

Bivariate Kernel density estimation for data classified in polygons or shapes

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
## 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)
## End(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)
## End(Not run)

Kernelheaping documentation built on Jan. 27, 2022, 1:09 a.m.