Skip to content

Instantly share code, notes, and snippets.

@mschauer
Created May 18, 2023 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mschauer/a159628d635996c1abb938936ad431b2 to your computer and use it in GitHub Desktop.
Save mschauer/a159628d635996c1abb938936ad431b2 to your computer and use it in GitHub Desktop.
Hidden correlation
using GLMakie
using Random
# mixture distribution
X(c) = rand() < c ? sqrt(rand()) : 1 - sqrt(rand())
# sample
Random.seed!(1);
A = [0:0.01:1;; X.(0:0.01:1)];
# correlation
cor(A)
# 2×2 Matrix{Float64}:
# 1.0 0.284633
# 0.284633 1.0
# plot
fig = Figure()
ax = Axis(fig[1,1])
scatter!(ax, A)
ax = Axis(fig[1,2])
image!(ax, [x*y + (1-x)*(1-y) for x in 0:0.1:1, y in 0:0.01:1], colormap=:viridis )
save("density.png", fig)
@mschauer
Copy link
Author

density

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment