0
グリッドから不規則点のセットへの双線形補間をしようとしています。How can I get the value of a kernel density estimate at specific points?と同じです。ただし、受け入れられた回答を試してみると、ディメンションの不一致エラーが発生します。`fields :: interp.surface`を使用してグリッドから不規則点に補間します
n <- 100
x <- rnorm(n)
y <- 3 + 2* x * rexp(n) + rnorm(n)
# add some outliers
y[sample(1:n,20)] <- rnorm(20,20,20)
DF <- data.frame(x,y)
# Calculate 2d density over a grid
library(MASS)
dens <- kde2d(x,y)
# create a new data frame of that 2d density grid
# (needs checking that I haven't stuffed up the order here of z?)
gr <- data.frame(with(dens, expand.grid(x,y)), as.vector(dens$z))
names(gr) <- c("x", "y", "z")
newdata=data.frame(xgr=x, ygr=y)
dens <- fields::interp.surface(gr, newdata)
# the interp.surface output is 2x as long as dim(newdata)[1]
length(dens)
dim(newdata)[1]
これは簡単なことですが、謝意を表します。