Skip to content

Commit

Permalink
Also change method for MSWD
Browse files Browse the repository at this point in the history
  • Loading branch information
brenhinkeller committed Jun 12, 2024
1 parent 723c73c commit 055c457
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
17 changes: 3 additions & 14 deletions src/regression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -198,27 +198,16 @@ function mswd(μ::Collection{T}, σ::Collection; chauvenet=false) where {T}
return χ² / (length(μ)-1)
end

function mswd(x::Collection{Measurement{T}}; chauvenet=false) where {T}
function mswd(x::AbstractVector{Measurement{T}}; chauvenet=false) where {T}

if chauvenet
not_outliers = chauvenet_func(val.(x), err.(x))
x = x[not_outliers]
end

sum_of_values = sum_of_weights = χ² = zero(float(T))

@inbounds for i in eachindex(x)
w = 1 / err(x[i])^2
sum_of_values += w * val(x[i])
sum_of_weights += w
end
wx = sum_of_values / sum_of_weights

@inbounds for i in eachindex(x)
χ² += (val(x[i]) - wx)^2 / err(x[i])^2
end
wμ, wσ, mswd = wmean(val.(x), Measurements.cov(x))

return χ² / (length(x)-1)
return mswd
end

## --- Simple linear regression
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ module BaseTests
@test wm.val 752.2453179272093
@test wm.err 1.4781473739306696
@test m 13.15644886325888

m = mswd(age68.(analyses[1:10]))
@test m 13.15644886325888
end

@testset "Concordia Metropolis" begin
Expand Down

2 comments on commit 055c457

@brenhinkeller
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register
Release notes:

  • Use full covariance matrix when calculating wmean or mswd on a vector of Measurements

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/108833

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.5 -m "<description of version>" 055c457922ccfaebd754b94d332e6c62a5529bd2
git push origin v0.3.5

Please sign in to comment.