Skip to content

Commit

Permalink
Release 0.2.0 cleanup (#52)
Browse files Browse the repository at this point in the history
* migrate to top-level test project and add compats

* CI config

* docs update

* add YAS enforcer

* README update

* s/hide_progress/progress and remove threads in nonparametricbootstrap

* s/hide_progress/progress and remove threads in permutation

* fix deprecation warning for Cholesky

* YAS

* update author list
  • Loading branch information
palday authored Apr 3, 2024
1 parent c36ed6e commit 86d26da
Show file tree
Hide file tree
Showing 22 changed files with 540 additions and 483 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/FormatCheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
name: YAS Enforcer
on:
push:
branches:
- main
- /^release-.*$/
tags: ["*"]
paths:
- "**/*.jl"
- ".github/workflows/FormatCheck.yml"
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths:
- "**/*.jl"
- ".github/workflows/FormatCheck.yml"
jobs:
format-check:
name: YASStyle
# These permissions are needed to:
# - Delete old caches: https://github.com/julia-actions/cache#usage
# - Post formatting suggestions: https://github.com/reviewdog/action-suggester#required-permissions
permissions:
actions: write
contents: read
pull-requests: write
runs-on: ubuntu-latest
continue-on-error: true
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
with:
version: "1"
- uses: julia-actions/cache@v1
- name: Install JuliaFormatter
shell: julia --project=@format --color=yes {0}
run: |
using Pkg
Pkg.add(PackageSpec(; name="JuliaFormatter", version="1"))
- name: Check formatting
shell: julia --project=@format --color=yes {0}
run: |
using JuliaFormatter
format(["src", "test", "docs"], YASStyle(); verbose=true)
# Add formatting suggestions to non-draft PRs when "Check formatting" fails
- uses: reviewdog/action-suggester@v1
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.draft == false }}
with:
tool_name: JuliaFormatter
fail_on_error: true
9 changes: 4 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,19 @@ on:
- 'README.md'
jobs:
ci:
name: CI - ${{ matrix.os }} - Julia ${{ matrix.julia }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
version: [1.6] # add 1 later
arch: [x64]
os: [ubuntu-20.04] # macos-10.15, windows-2019
julia: [1.9]
os: [ubuntu-latest] # macos-10.15, windows-2019, macOS-14
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Julia Setup
uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
version: ${{ matrix.julia }}
- name: Cache
uses: julia-actions/cache@v1
with:
Expand Down
24 changes: 19 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MixedModelsPermutations"
uuid = "647c4018-d7ef-4d03-a0cc-8889a722319e"
authors = ["Phillip Alday <[email protected]> and contributors"]
version = "0.2.1"
authors = ["Phillip Alday <[email protected]>", "Benedikt Ehinger <[email protected]>", "Jaromil Frossard <[email protected]>"]
version = "0.2.0"

[deps]
BlockDiagonals = "0a1fb500-61f7-11e9-3c65-f5ef3456f9f0"
Expand All @@ -16,11 +16,25 @@ StatsModels = "3eaba693-59b7-5ba5-a881-562e759f1c8d"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

[compat]
Aqua = "0.8"
DataFrames = "1"
BlockDiagonals = "0.1.18"
MixedModels = "4.2.1"
MixedModels = "4.22"
MixedModelsSim = "0.2.9"
StableRNGs = "1"
StaticArrays = "1.0"
Statistics = "1"
StatsBase = "0.33, 0.34"
StatsModels = "0.6, 0.7"
Tables = "1.0"
julia = "1.6"
Tables = "1"
julia = "1.9"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
MixedModelsSim = "d5ae56c5-23ca-4a1f-b505-9fc4796fc1fe"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Aqua", "Test", "DataFrames", "MixedModelsSim", "StableRNGs"]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[![Dev Docs][docs-dev-img]][docs-dev-url]
[![Codecov](https://codecov.io/gh/palday/MixedModelsPermutations.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/palday/MixedModelsPermutations.jl)
[![DOI](https://zenodo.org/badge/337080334.svg)](https://zenodo.org/badge/latestdoi/337080334)
[![Code Style: YAS](https://img.shields.io/badge/code%20style-yas-1fdcb3.svg)](https://github.com/jrevels/YASGuide)

[docs-dev-img]: https://img.shields.io/badge/docs-dev-blue.svg
[docs-dev-url]: https://palday.github.io/MixedModelsPermutations.jl/dev
Expand Down
4 changes: 2 additions & 2 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ MixedModels = "ff71e718-51f3-5ec2-a782-8ffcbfa3c316"
MixedModelsPermutations = "647c4018-d7ef-4d03-a0cc-8889a722319e"

[compat]
Documenter = "0.27"
julia = "1.6"
Documenter = "1.3"
julia = "1.9"
13 changes: 5 additions & 8 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using Documenter
using MixedModelsPermutations

makedocs(
sitename = "MixedModelsPermutations",
doctest = true,
pages = [
"index.md",
],
)
makedocs(; sitename="MixedModelsPermutations",
doctest=true,
pages=["index.md"])

deploydocs(repo = "github.com/palday/MixedModelsPermutations.jl.git", push_preview=true, devbranch="main")
deploydocs(; repo="github.com/palday/MixedModelsPermutations.jl.git", push_preview=true,
devbranch="main")
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
CurrentModule = MixedModelsPermutations
```

*MixedModelsPermutations.jl* is a Julia package providing extra capabilities for models fit with [MixedModels.jl](https://juliastats.org/MixedModels.jl/stable/).
*MixedModelsPermutations.jl* is a Julia package providing nonparametric testing capabilities for models fit with [MixedModels.jl](https://juliastats.org/MixedModels.jl/stable/).

```@contents
Pages = [
Expand Down
135 changes: 76 additions & 59 deletions sim/nb_mwe-unshrunken.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ using InteractiveUtils
# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
macro bind(def, element)
quote
local iv = try Base.loaded_modules[Base.PkgId(Base.UUID("6e696c72-6542-2067-7265-42206c756150"), "AbstractPlutoDingetjes")].Bonds.initial_value catch; b -> missing; end
local iv = try
Base.loaded_modules[Base.PkgId(
Base.UUID("6e696c72-6542-2067-7265-42206c756150"),
"AbstractPlutoDingetjes",
)].Bonds.initial_value
catch
b -> missing
end
local el = $(esc(element))
global $(esc(def)) = Core.applicable(Base.get, el) ? Base.get(el) : iv(el)
el
Expand All @@ -16,20 +23,20 @@ end

# ╔═╡ f92470d8-c28e-4057-87bd-12383b43c158
begin
using Pkg
Pkg.activate(; temp=true)
Pkg.add("Revise")
using Revise
Pkg.add(path="..")
Pkg.add(["PlutoUI", "MixedModelsSim", "MixedModels", "DataFrames","StableRNGs"])
using PlutoUI
using MixedModelsSim
using MixedModelsPermutations
using MixedModels
using DataFrames
using StableRNGs
using LinearAlgebra
using Statistics
using Pkg
Pkg.activate(; temp = true)
Pkg.add("Revise")
using Revise
Pkg.add(path = "..")
Pkg.add(["PlutoUI", "MixedModelsSim", "MixedModels", "DataFrames", "StableRNGs"])
using PlutoUI
using MixedModelsSim
using MixedModelsPermutations
using MixedModels
using DataFrames
using StableRNGs
using LinearAlgebra
using Statistics
end

# ╔═╡ f5830c4e-a8d0-47f2-baca-bc734720b1e0
Expand All @@ -48,14 +55,21 @@ md"seed $(@bind seed_val Slider(1:100; default=1., show_value=true))"
rng = StableRNG(Int(seed_val))

# ╔═╡ 2141edd4-c8ed-4d1b-a5ec-9913b19a2d4a
md"Subjects: $(@bind nsub Slider(2:2:50; default=30, show_value=true))"
md"Subjects: $(@bind nsub Slider(2:2:50; default=30, show_value=true))"


# ╔═╡ bac32d2f-fb1f-4f02-b2f5-49df029b7b92
md"Items per Subject: $(@bind nitem Slider(2:2:50; default=30, show_value=true))"

# ╔═╡ 461f6470-359e-406a-b32d-5455647e36b8
@bind inflate Radio(["ols" => "inflation_factor from OLS blups", "yes" => "inflation_factor from original blups/residuals", "no" => "identity"],"ols")
@bind inflate Radio(
[
"ols" => "inflation_factor from OLS blups",
"yes" => "inflation_factor from original blups/residuals",
"no" => "identity",
],
"ols",
)

# ╔═╡ a44e5f9f-5a23-46b6-adbd-228b893ac81f
md"### Calculate 50 permutations"
Expand All @@ -64,19 +78,20 @@ md"### Calculate 50 permutations"
md"### How the saussage is simulated"

# ╔═╡ 0cbf776c-8e56-4d32-8a55-da22f8bf1940
f = @formula(dv ~ 1 + condition + (1 + condition | subj));
f = @formula(dv ~ 1 + condition + (1 + condition | subj));

# ╔═╡ 72f5e910-e40d-11eb-3725-f19a95c9b3c1
begin
subj_btwn = Dict("age" => ["O", "Y"])
subj_btwn = Dict("age" => ["O", "Y"])
# there are no between-item factors in this design so you can omit it or set it to nothing
item_btwn = Dict("stimType" => ["I", "II"])

# put within-subject/item factors in a Dict
both_win = Dict("condition" => ["A", "B"])

# simulate data
dat = simdat_crossed(rng,
dat = simdat_crossed(
rng,
nsub,
nitem,
subj_btwn = subj_btwn,
Expand All @@ -88,59 +103,61 @@ end
# ╔═╡ cd9b3fb7-06c7-4c44-81ac-d8a4a3e0c22e
# generate simulated "y" vector
begin
β = [1., 1.];
σs = [1, 1, 0.2];
simMod = fit(MixedModel, f, dat)
simMod = MixedModelsSim.update!(simMod,[create_re(x...) for x in σs]...)
simMod = simulate!(rng, simMod; β, σ = 1.)
β = [1.0, 1.0]
σs = [1, 1, 0.2]
simMod = fit(MixedModel, f, dat)
simMod = MixedModelsSim.update!(simMod, [create_re(x...) for x in σs]...)
simMod = simulate!(rng, simMod; β, σ = 1.0)
end;

# ╔═╡ cfd225bb-1eec-41b1-b6c1-ebc036b7e1d2
begin
# fit a LMM mod to the y (separate models to maybe have separate formulas later
datSim = DataFrame(dat)
datSim[!, :dv] .= response(simMod)
morig = fit(MixedModel, f, datSim; REML=false)
# fit a LMM mod to the y (separate models to maybe have separate formulas later
datSim = DataFrame(dat)
datSim[!, :dv] .= response(simMod)
morig = fit(MixedModel, f, datSim; REML = false)
end;

# ╔═╡ a26a8327-8342-472e-841f-a9a68e5b15a8
MixedModelsPermutations.inflation_factor(morig)

# ╔═╡ 58fa0d39-65e0-4ec7-aeb0-e8bde381379a
begin
samps = DataFrame()
seed = Int(seed_val)
for p = 1:50
local m_new = deepcopy(morig)

sample_func = MixedModelsPermutations.permute!


sample_rng = StableRNG(seed+p)
blups = olsranef(m_new)
resids = residuals(m_new, blups)
if inflate == "ols"
scalings = MixedModelsPermutations.inflation_factor(m_new, blups, resids)
elseif inflate == "yes"
scalings = MixedModelsPermutations.inflation_factor(m_new)
else
# assumes that we have exactly 2 blocking vars
scalings = [I, I, 1]
end
sample_func(sample_rng, m_new; β, blups, resids, scalings)
refit!(m_new)
push!(samps, (; σ=m_new.σ, β=m_new.β ))
end
samps = DataFrame()
seed = Int(seed_val)

for p = 1:50
local m_new = deepcopy(morig)

sample_func = MixedModelsPermutations.permute!


sample_rng = StableRNG(seed + p)
blups = olsranef(m_new)
resids = residuals(m_new, blups)
if inflate == "ols"
scalings = MixedModelsPermutations.inflation_factor(m_new, blups, resids)
elseif inflate == "yes"
scalings = MixedModelsPermutations.inflation_factor(m_new)
else
# assumes that we have exactly 2 blocking vars
scalings = [I, I, 1]
end
sample_func(sample_rng, m_new; β, blups, resids, scalings)

refit!(m_new)
push!(samps, (; σ = m_new.σ, β = m_new.β))

end
end

# ╔═╡ 64d2509b-d94e-4e48-8f81-fa13d5f9e9be
let # convenience tuple :-)
("non parametric resampling"=>samps.σ,
"emprical σ"=>morig.σ,
"mean of resampled σ" => mean(samps.σ))
let# convenience tuple :-)
(
"non parametric resampling" => samps.σ,
"emprical σ" => morig.σ,
"mean of resampled σ" => mean(samps.σ),
)
end

# ╔═╡ Cell order:
Expand Down
Loading

4 comments on commit 86d26da

@palday
Copy link
Owner Author

@palday palday commented on 86d26da Apr 3, 2024

Choose a reason for hiding this comment

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

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

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

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.2.0 -m "<description of version>" 86d26da36f58fdcb9178ecbdd413b03b1d6207e9
git push origin v0.2.0

@palday
Copy link
Owner Author

@palday palday commented on 86d26da Apr 3, 2024

Choose a reason for hiding this comment

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

@JuliaRegistrator register

Release notes:

  • fix permutationtest (thanks @behinger!)
  • bump Julia and MixedModels lower compat bounds
  • use progress instead of hide_progress
  • drop problematic use_threads
  • improved CI
  • officially enforce YAS

@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 updated: JuliaRegistries/General/104211

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.2.0 -m "<description of version>" 86d26da36f58fdcb9178ecbdd413b03b1d6207e9
git push origin v0.2.0

Please sign in to comment.