Skip to content

Commit

Permalink
Add simpler constructor for StratAgeModel
Browse files Browse the repository at this point in the history
  • Loading branch information
brenhinkeller committed May 7, 2024
1 parent affaeab commit 0f615d2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 61 deletions.
12 changes: 12 additions & 0 deletions src/Objects.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,16 @@
Age_975CI::Vector{Float64}
end

function StratAgeModel(heights, agedist)
agedistₜ = copy(agedist)
StratAgeModel(
heights, # Model heights
vmean(agedistₜ,dim=2), # Mean age
vstd(agedistₜ,dim=2), # Standard deviation
vmedian!(agedistₜ,dim=2), # Median age
vpercentile!(agedistₜ,2.5,dim=2), # 2.5th percentile
vpercentile!(agedistₜ,97.5,dim=2) # 97.5th percentile
)
end

Base.NamedTuple(mdl::StratAgeModel) = NamedTuple{fieldnames(typeof(mdl))}(ntuple(i->getfield(mdl, i), nfields(mdl)))
74 changes: 13 additions & 61 deletions src/StratMetropolis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,8 @@

# Crop the result
agedist = agedist[active_height_t,:]
agedistₜ = copy(agedist)

mdl = StratAgeModel(
model_heights[active_height_t], # Model heights
vmean(agedist,dim=2), # Mean age
vstd(agedist,dim=2), # Standard deviation
vmedian!(agedistₜ,dim=2), # Median age
vpercentile!(agedistₜ,2.5,dim=2), # 2.5th percentile
vpercentile!(agedistₜ,97.5,dim=2) # 97.5th percentile
)
model_heights = model_heights[active_height_t]
mdl = StratAgeModel(model_heights, agedist)

return mdl, agedist, lldist
end
Expand Down Expand Up @@ -130,16 +122,8 @@

# Crop the result
agedist = agedist[active_height_t,:]
agedistₜ = copy(agedist)

mdl = StratAgeModel(
model_heights[active_height_t], # Model heights
vmean(agedist,dim=2), # Mean age
vstd(agedist,dim=2), # Standard deviation
vmedian!(agedistₜ,dim=2), # Median age
vpercentile!(agedistₜ,2.5,dim=2), # 2.5th percentile
vpercentile!(agedistₜ,97.5,dim=2) # 97.5th percentile
)
model_heights = model_heights[active_height_t]
mdl = StratAgeModel(model_heights, agedist)

return mdl, agedist, lldist, hiatusdist
end
Expand Down Expand Up @@ -221,16 +205,8 @@

# Crop the result
agedist = agedist[active_height_t,:]
agedistₜ = copy(agedist)

mdl = StratAgeModel(
model_heights[active_height_t], # Model heights
vmean(agedist,dim=2), # Mean age
vstd(agedist,dim=2), # Standard deviation
vmedian!(agedistₜ,dim=2), # Median age
vpercentile!(agedistₜ,2.5,dim=2), # 2.5th percentile
vpercentile!(agedistₜ,97.5,dim=2) # 97.5th percentile
)
model_heights = model_heights[active_height_t]
mdl = StratAgeModel(model_heights, agedist)

return mdl, agedist, lldist
end
Expand Down Expand Up @@ -285,17 +261,9 @@

# Crop the result
agedist = agedist[active_height_t,:]
agedistₜ = copy(agedist)

mdl = StratAgeModel(
model_heights[active_height_t], # Model heights
vmean(agedist,dim=2), # Mean age
vstd(agedist,dim=2), # Standard deviation
vmedian!(agedistₜ,dim=2), # Median age
vpercentile!(agedistₜ,2.5,dim=2), # 2.5th percentile
vpercentile!(agedistₜ,97.5,dim=2) # 97.5th percentile
)

model_heights = model_heights[active_height_t]
mdl = StratAgeModel(model_heights, agedist)

return mdl, agedist, lldist, hiatusdist
end

Expand Down Expand Up @@ -374,16 +342,8 @@

# Crop the result
agedist = agedist[active_height_t,:]
agedistₜ = copy(agedist)

mdl = StratAgeModel(
model_heights[active_height_t], # Model heights
vmean(agedist,dim=2), # Mean age
vstd(agedist,dim=2), # Standard deviation
vmedian!(agedistₜ,dim=2), # Median age
vpercentile!(agedistₜ,2.5,dim=2), # 2.5th percentile
vpercentile!(agedistₜ,97.5,dim=2) # 97.5th percentile
)
model_heights = model_heights[active_height_t]
mdl = StratAgeModel(model_heights, agedist)

return mdl, agedist, lldist
end
Expand Down Expand Up @@ -442,16 +402,8 @@

# Crop the result
agedist = agedist[active_height_t,:]
agedistₜ = copy(agedist)

mdl = StratAgeModel(
model_heights[active_height_t], # Model heights
vmean(agedist,dim=2), # Mean age
vstd(agedist,dim=2), # Standard deviation
vmedian!(agedistₜ,dim=2), # Median age
vpercentile!(agedistₜ,2.5,dim=2), # 2.5th percentile
vpercentile!(agedistₜ,97.5,dim=2) # 97.5th percentile
)
model_heights = model_heights[active_height_t]
mdl = StratAgeModel(model_heights, agedist)

return mdl, agedist, lldist, hiatusdist
end
Expand Down

2 comments on commit 0f615d2

@brenhinkeller
Copy link
Owner 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:

  • Simpler constructor for StratAgeModel
  • NamedTuple conversion method for StratAgeModels

@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/106359

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.4.18 -m "<description of version>" 0f615d228149b65f57f9972852c70e5bbf7fe965
git push origin v0.4.18

Please sign in to comment.