Advertisement · 728 × 90
#
Hashtag
#RStast
Advertisement · 728 × 90
Screenshot of a plot digitiser digitising the outline of a photo of Hallgrimskirkja.

Screenshot of a plot digitiser digitising the outline of a photo of Hallgrimskirkja.

laplace <- function(mu, b) {
    force(mu)
    force(b)
    function(x) {
        l <- 1/(2 * b) * exp(-abs(x - mu)/b)
        l/max(l)
    }
}

hallgrimskirkja <- "~/Downloads/hallgrimskirkja.csv" |> 
    read.csv() 

lap_error <- function(b) {
    mean(laplace(0, b)(hallgrimskirkja$x) - hallgrimskirkja$y)^2
}

op <- optimise(lap_error, interval = c(1/10, 1))
fit <- laplace(0, op$minimum)

library(ggplot2)
g <- jpeg::readJPEG("~/Downloads/hallgrimskirkja.jpg") |> 
    grid::rasterGrob(interpolate=TRUE, width = 1.32, height = 0.95)

hallgrimskirkja |> 
    rbind(transform(hallgrimskirkja, x = -x)) |> 
    ggplot(aes(x, y)) +
    annotation_custom(g, xmin=-0.8, xmax=0.8, ymin=-0.1, ymax=1.08) +
    geom_line(aes(color = "Kirkja")) +
    stat_function(fun = fit, aes(color = "Laplacian fit")) +
    theme(legend.position = "bottom")

laplace <- function(mu, b) { force(mu) force(b) function(x) { l <- 1/(2 * b) * exp(-abs(x - mu)/b) l/max(l) } } hallgrimskirkja <- "~/Downloads/hallgrimskirkja.csv" |> read.csv() lap_error <- function(b) { mean(laplace(0, b)(hallgrimskirkja$x) - hallgrimskirkja$y)^2 } op <- optimise(lap_error, interval = c(1/10, 1)) fit <- laplace(0, op$minimum) library(ggplot2) g <- jpeg::readJPEG("~/Downloads/hallgrimskirkja.jpg") |> grid::rasterGrob(interpolate=TRUE, width = 1.32, height = 0.95) hallgrimskirkja |> rbind(transform(hallgrimskirkja, x = -x)) |> ggplot(aes(x, y)) + annotation_custom(g, xmin=-0.8, xmax=0.8, ymin=-0.1, ymax=1.08) + geom_line(aes(color = "Kirkja")) + stat_function(fun = fit, aes(color = "Laplacian fit")) + theme(legend.position = "bottom")

Plot with Hallgrimskirkja in the background and two lines showing the outline and the Laplace distribution fit. The fit is not great. It's too steep and the tails too short.

Plot with Hallgrimskirkja in the background and two lines showing the outline and the Laplace distribution fit. The fit is not great. It's too steep and the tails too short.

More than one reply suggesting Laplace distribution. I digitised the church's outline and then tried to fit a Laplace distribution. Here's the fit.

#RStast #Iceland

2 0 0 0
Preview
LatinR 2025 - Conferencia en vivo día 1 YouTube video by LatinR

Now at @latinrconf.bsky.social @heathrturnr.fosstodon.org.ap.brid.gy is giving a keynote on Lowering Barriers to Contributing to R

You can follow here: www.youtube.com/live/xbCT4v5...

#LatinR2025 #RStast

2 1 0 0