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
Row | t | ersstv5a | HadEN4a | ya |
---|---|---|---|---|
Float64 | Measurem… | Measurem… | Measurem… | |
1 | 1950.12 | 28.43±0.32 | 33.94±0.17 | -5.601±0.051 |
2 | 1950.21 | 28.63±0.27 | 33.92±0.17 | -5.618±0.051 |
3 | 1950.29 | 29.2±0.29 | 33.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₂ |
---|---|---|---|---|
Float64 | Float64 | Float64 | Float64 | |
1 | 0.0001 | -8.37806 | -0.220003 | 0.261988 |
2 | 0.000316228 | -8.38431 | -0.220011 | 0.262178 |
3 | 0.001 | -8.40417 | -0.220035 | 0.262783 |
4 | 0.00316228 | -8.46788 | -0.220113 | 0.264723 |
5 | 0.01 | -8.67455 | -0.22037 | 0.27102 |
6 | 0.0316228 | -9.31106 | -0.221259 | 0.290476 |
7 | 0.1 | -10.9189 | -0.224148 | 0.340145 |
8 | 0.316228 | -13.558 | -0.231787 | 0.424107 |
9 | 1.0 | -15.3836 | -0.248465 | 0.491798 |
10 | 3.16228 | -15.61 | -0.273844 | 0.519853 |
11 | 10.0 | -15.1153 | -0.296346 | 0.5243 |
12 | 31.6228 | -14.7516 | -0.308261 | 0.523664 |
13 | 100.0 | -14.599 | -0.312882 | 0.523077 |