Skip to content

Instantly share code, notes, and snippets.

View dlakelan's full-sized avatar

Daniel Lakeland dlakelan

View GitHub Profile
@dlakelan
dlakelan / logpdist.jl
Last active May 26, 2024 23:31
Showing high Dimensional log(p) distribution
using Distributions,Random,StatsPlots,LinearAlgebra
dist = MvNormal(zeros(20),I(20))
samp = rand(dist,200)
lps = [logpdf(dist,c) for c in eachcol(samp)]
histogram(lps; label="lp of 200 draws")
@dlakelan
dlakelan / gist:5940c8c8b849b5b16d5f88147e8b5f55
Created March 8, 2024 19:31
Confidence Interval Size Simulation
## from https://statmodeling.stat.columbia.edu/2024/03/07/relating-t-statistics-and-the-relative-width-of-confidence-intervals/#comment-2335932
# but fixed up due to blog damage
nsim = 10000
lengthOfCI = rep(NaN, nsim)
containsPM = rep(NaN, nsim)
for(i in 1:nsim){
y = rnorm(10, 0, 1)
@dlakelan
dlakelan / gist:d3722e621495666803dc9aafd60a956a
Last active November 9, 2023 00:31
Galactic rotation curve Newton's calc
using HCubature, LinearAlgebra, StatsPlots, QuadGK, StaticArrays
# Define a function that describes the density
# as a function of the radial distance from the center of the galaxy. This is a
# dimensionless quantity (mass/area) / (mass/area at zero distance)
# r is a dimensionless distance, radius as a fraction of the galactic scale radius
function rho(x)
exp(-sqrt(x[1]^2+x[2]^2)-5.0*abs(x[3]))
@dlakelan
dlakelan / MOpenExample.jl
Created January 4, 2023 04:54
When the "true" distribution isn't in the model space, does Bayes give a reasonable answer?
using Distributions, Random, StatsPlots, Turing
# We have a pallet of 100 jugs of Orange Juice, each is a 2L jug.
# they are filled by a machine which may have a flaw. we would like to find
# the avg amount of OJ in a jug by taking a sample of 20
# this is a finite population, and the actual distribution of volumes is just given
# by 100 numbers. we'll say they are something like this:
Random.set_global_seed!(1234)
@dlakelan
dlakelan / PriorOnFuncs.jl
Created January 2, 2023 03:29
Path Integral Approach For Functional Priors
using Pkg
Pkg.activate(".")
Pkg.add(["Turing","Distributions","ApproxFun","QuadGK","StatsPlots","LinearAlgebra","DataFrames"])
using Turing, Distributions, ApproxFun, QuadGK, StatsPlots, LinearAlgebra, DataFrames
# a prior over functions that go up then come down... First let's see how ApproxFun works
Random.set_global_seed!(123456)
f = Fun(Chebyshev(Interval(0..100)),randn(12))
@dlakelan
dlakelan / testingforreal.jl
Created December 30, 2022 22:53
Effect size when you first "check if it's real"
using Distributions, HypothesisTests, DataFrames, DataFramesMeta, StatsPlots
function dowork(effsizes,reps)
res = typeof((effsize=1.0,meanval=1.0,pval=0.1))[]
for s in effsizes
for r in 1:reps
sam = rand(Normal(s,1.0),15)
tt = OneSampleTTest(sam)
push!(res,(effsize=s,meanval=mean(sam),pval=pvalue(tt)))
end
@dlakelan
dlakelan / samplingexample.jl
Last active February 4, 2022 18:08
Sampling from non-normal distributions yields
# julia code to show that the mean of 14 samples from a 50/50 mixture
# of normal and uniform has extremely close to "normal" distribution
using Distributions, StatsPlots
meanvals = [mean([rand(Normal(0,1),7); rand(Uniform(-1,1),7)]) for i in 1:100000]
histogram(meanvals)
pop = [rand(Normal(0,1),10000); rand(Uniform(-1,1),10000)];
@dlakelan
dlakelan / nftables.conf
Created November 15, 2021 20:25
An OpenWrt firewall and DSCP tagging script example
# A simple stateful firewall with some packet tagging,
# based originally on nftables archlinux wiki
# https://wiki.archlinux.org/index.php/nftables
## this assumes eth0 is LAN and eth1 is WAN, modify as needed
flush ruleset
## change these