Example 1

In this example, the final posterior is calculated for a range of $λ$ values. The solution for $λ=1.0$ is the same as Bpost2 in Example 2.

using CSV, DataFrames, Distributions, LinearAlgebra
import Measurements as Mm
using MeasurementErrorModels

Munit =  Mm.Measurement{Float64}
f1 = joinpath(dirname(pathof(MeasurementErrorModels)), "../docs/src/assets/")
D2 = CSV.read(f1*"Palaui.csv", DataFrame, types=Dict([2,3,4].=>Munit))
first(D2,3)
3×4 DataFrame
Rowtersstv5aHadEN4aya
Float64Measurem…Measurem…Measurem…
11950.1228.43±0.3233.94±0.17-5.601±0.051
21950.2128.63±0.2733.92±0.17-5.618±0.051
31950.2929.2±0.2933.9±0.17-5.842±0.051
function makeprior2(p=-4; μ=[-8.38, -0.22, 0.97*0.27], ip=1.0)
   Σ = Diagonal([ip*1.37, (10.0^p)*0.02^2, (10.0^p)*0.15^2])
   return MvNormal(μ, Σ)
end

function lsf(p::Float64, D::DataFrame; lags=0:25)
    Bprior = makeprior2(p, ip=1000.0)
    μ = mean(Bout(D, Bprior=Bprior, lags=lags).value[3])
    return (λ=10.0^p, b₀=μ[1], b₁=μ[2], b₂=μ[3])
end

Dbpar = DataFrame(p=[-4:0.5:2;])
Db = select(Dbpar, :p=>ByRow(p->lsf(p, D2[:, 2:end], lags=0:100))=>AsTable)
Db
13×4 DataFrame
Rowλb₀b₁b₂
Float64Float64Float64Float64
10.0001-8.37806-0.2200030.261988
20.000316228-8.38431-0.2200110.262178
30.001-8.40417-0.2200350.262783
40.00316228-8.46788-0.2201130.264723
50.01-8.67455-0.220370.27102
60.0316228-9.31106-0.2212590.290476
70.1-10.9189-0.2241480.340145
80.316228-13.558-0.2317870.424107
91.0-15.3836-0.2484650.491798
103.16228-15.61-0.2738440.519853
1110.0-15.1153-0.2963460.5243
1231.6228-14.7516-0.3082610.523664
13100.0-14.599-0.3128820.523077