if (FALSE) { # rlang::is_installed("ks")
# load libraries for models and data
library(ks)
# generate data
dat <- replicate(2, rnorm(100))
k <- kde(dat)
# summarize model fit with tidiers + visualization
td <- tidy(k)
td
library(ggplot2)
library(dplyr)
library(tidyr)
td %>%
pivot_wider(c(obs, estimate),
names_from = variable,
values_from = value
) %>%
ggplot(aes(x1, x2, fill = estimate)) +
geom_tile() +
theme_void()
# also works with 3 dimensions
dat3 <- replicate(3, rnorm(100))
k3 <- kde(dat3)
td3 <- tidy(k3)
td3
}
Run the code above in your browser using DataLab