Weighted KDE dengan spatialEco
library(spatialEco)
library(sp)
library(raster)data(meuse)
str(meuse)## 'data.frame': 155 obs. of 14 variables:
## $ x : num 181072 181025 181165 181298 181307 ...
## $ y : num 333611 333558 333537 333484 333330 ...
## $ cadmium: num 11.7 8.6 6.5 2.6 2.8 3 3.2 2.8 2.4 1.6 ...
## $ copper : num 85 81 68 81 48 61 31 29 37 24 ...
## $ lead : num 299 277 199 116 117 137 132 150 133 80 ...
## $ zinc : num 1022 1141 640 257 269 ...
## $ elev : num 7.91 6.98 7.8 7.66 7.48 ...
## $ dist : num 0.00136 0.01222 0.10303 0.19009 0.27709 ...
## $ om : num 13.6 14 13 8 8.7 7.8 9.2 9.5 10.6 6.3 ...
## $ ffreq : Factor w/ 3 levels "1","2","3": 1 1 1 1 1 1 1 1 1 1 ...
## $ soil : Factor w/ 3 levels "1","2","3": 1 1 1 2 2 2 2 1 1 2 ...
## $ lime : Factor w/ 2 levels "0","1": 2 2 2 1 1 1 1 1 1 1 ...
## $ landuse: Factor w/ 15 levels "Aa","Ab","Ag",..: 4 4 4 11 4 11 4 2 2 15 ...
## $ dist.m : num 50 30 150 270 380 470 240 120 240 420 ...
coordinates(meuse) <- ~x+y# Unweighted KDE (spatial locations only)
pt.kde <- sp.kde(x = meuse, bw = 1000, standardize = TRUE,
nr=104, nc=78, scale.factor = 10000)
# Plot results
plot(pt.kde, main="Unweighted KDE")
points(meuse, pch=20, col="red")Using existing raster(s) to define grid
# Weighted KDE using zinc and raster object to define grid
r <- raster::raster(raster::extent(c(178605, 181390, 329714, 333611)),
nrow=104, ncol=78)
r[] <- rep(1,ncell(r))
zinc.kde2 <- sp.kde(x = meuse, y = meuse$zinc, bw = 1000,
newdata = r, standardize = TRUE,
scale.factor = 10000 )
# Plot results
plot(zinc.kde2, main="Weighted KDE using Zinc and Raster Object")
points(meuse, pch=20)# Weighted KDE using zinc and SpatialPixelsDataFrame object to define grid
data(meuse.grid)
coordinates(meuse.grid) = ~x+y
proj4string(meuse.grid) <- CRS("+init=epsg:28992")
gridded(meuse.grid) = TRUE
zinc.kde3 <- sp.kde(x = meuse, y = meuse$zinc, bw = 1000,
newdata = meuse.grid, standardize = TRUE,
scale.factor = 10000 )
# Plot results
plot(zinc.kde3, main="Weighted KDE using Zinc and SpatialPixelsDataFrame Object")
points(meuse, pch=20)Reference: https://rdrr.io/cran/spatialEco/man/sp.kde.html#heading-5