Możesz rozważyć użycie jądra szczególnie odpowiedniego dla kuli, takiego jak gęstość von Misesa-Fishera
f(x;κ,μ)∝exp(κμ′x)
μx
κxμω(μ)
ω(μ)f(x;κ,μ).
xμi
R
μiω(μi)κ6
μiω(μi)(100,60)
#
# von Mises-Fisher density.
# mu is the location and x the point of evaluation, *each in lon-lat* coordinates.
# Optionally, x is a two-column array.
#
dvonMises <- function(x, mu, kappa, inDegrees=TRUE) {
lambda <- ifelse(inDegrees, pi/180, 1)
SphereToCartesian <- function(x) {
x <- matrix(x, ncol=2)
t(apply(x, 1, function(y) c(cos(y[2])*c(cos(y[1]), sin(y[1])), sin(y[2]))))
}
x <- SphereToCartesian(x * lambda)
mu <- matrix(SphereToCartesian(mu * lambda), ncol=1)
c.kappa <- kappa / (2*pi*(exp(kappa) - exp(-kappa)))
c.kappa * exp(kappa * x %*% mu)
}
#
# Define a grid on which to compute the kernel density estimate.
#
x.coord <- seq(-180, 180, by=2)
y.coord <- seq(-90, 90, by=1)
x <- as.matrix(expand.grid(lon=x.coord, lat=y.coord))
#
# Give the locations.
#
n <- 12
set.seed(17)
mu <- cbind(runif(n, -180, 180), asin(runif(n, -1, 1))*180/pi)
#
# Weight them.
#
weights <- rexp(n)
#
# Compute the kernel density.
#
kappa <- 6
z <- numeric(nrow(x))
for (i in 1:nrow(mu)) {
z <- z + weights[i] * dvonMises(x, mu[i, ], kappa)
}
z <- matrix(z, nrow=length(x.coord))
#
# Plot the result.
#
image(x.coord, y.coord, z, xlab="Longitude", ylab="Latitude")
points(mu[, 1], mu[, 2], pch=16, cex=sqrt(weights))