Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
library(colorspace)
library(rayshader)
library(tidyverse)
mse <- function(x, y, a, b) {
pred <- a + b*x
resid2 <- (y - pred)^2
1/length(y)*sum(resid2)
}
set.seed(8675309)
n <- 1000
x <- rnorm(n)
a <- 5
b <- 1.3
e <- 4
y <- a + b*x + rnorm(n, sd = e)
sim_d <- tibble(x = x, y = y)
grid <- expand.grid(a = seq(-5, 10, 0.1), b = seq(-5, 5, 0.1))
surface <- grid %>%
mutate(cost = map2_dbl(a, b, ~mse(x, y, .x, .y))) %>%
ggplot(aes(a, b)) +
geom_raster(aes(fill = cost)) +
scale_fill_continuous_sequential(palette = "Terrain")
plot_gg(surface, multicore = TRUE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.