Skip to content

Commit

Permalink
Use histmean and histstd to determine parameters of Radiocarbon
Browse files Browse the repository at this point in the history
… distributions
  • Loading branch information
brenhinkeller committed Jun 28, 2024
1 parent 13348ba commit bbf4334
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Distributions = "0.15 - 0.25"
Isoplot = "0.3"
KernelDensity = "0.4 - 0.6"
LsqFit = "0.7 - 0.13"
NaNStatistics = "0.4, 0.5, 0.6"
NaNStatistics = "0.6.38"
Plots = "1"
ProgressMeter = "1"
Reexport = "0.2, 1.0"
Expand Down
10 changes: 7 additions & 3 deletions src/Utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@

dist = exp.(ldist)
dist ./= sum(dist) * calibration.dt # Normalize
samples = draw_from_distribution(dist, 10^6) .* maximum(calibration.Age_Calendar)
μ, σ = nanmean(samples), nanstd(samples)
μ = histmean(dist, calibration.Age_Calendar)
σ = histstd(dist, calibration.Age_Calendar, corrected=false)

return Radiocarbon(μ, σ, ldist)
return Radiocarbon(μ, σ, dist, ldist)
end

## Conversions
Expand All @@ -135,6 +135,10 @@
return linterp_at_index(d.ldist, x, -maxintfloat(T))
end

## Statistics
Distributions.mean(d::Radiocarbon) = d.μ
Distributions.std(d::Radiocarbon) = d.σ

## ---

# Interpolate log likelihood from an array
Expand Down
7 changes: 5 additions & 2 deletions test/testUtilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
@test pdf.(d, [900, 950, 1000]) [3.372067127114498e-7, 0.0036210273644940918, 1.5582187464154278e-12]

@test eltype(d) === partype(d) === Float64
@test location(d) 926.3094740428785 atol=0.1
@test scale(d) 7.411299532288234 atol=0.1
@test location(d) 927.2875322569857
@test scale(d) 7.412902965559571

@test mean(d) 927.2875322569857
@test std(d) 7.412902965559571

## --- Other utility functions for log likelihoods

Expand Down

0 comments on commit bbf4334

Please sign in to comment.