-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use TidierPlots for some of the graphics #55
Draft
dmbates
wants to merge
10
commits into
main
Choose a base branch
from
db/TidierPlots
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ce915d8
Use TidierPlots on some plots. Add -tauto to exeflags.
dmbates 960ebc9
Add -tauto to exeflags here too
dmbates a90a2b3
Merge branch 'main' into db/TidierPlots
dmbates 3654bc1
Reformat code; use Chairmarks for benchmarking.
dmbates 166d15b
Merge branch 'main' into db/TidierPlots
dmbates 5968b3c
More TidierPlots and cleanup
dmbates 87d1a4c
Add MatrixTables description
dmbates 4481696
Merge branch 'db/TidierPlots' of https://github.com/JuliaMixedModels/…
dmbates 139376a
Merge branch 'main' into db/TidierPlots
palday 6adaa32
Merge branch 'main' of github.com:JuliaMixedModels/EmbraceUncertainty…
palday File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -5,7 +5,7 @@ fig-dpi: 150 | |||||||||||||||
fig-format: png | ||||||||||||||||
engine: julia | ||||||||||||||||
julia: | ||||||||||||||||
exeflags: ["--project"] | ||||||||||||||||
exeflags: ["-tauto", "--project"] | ||||||||||||||||
--- | ||||||||||||||||
|
||||||||||||||||
# GLMM log-likelihood {#sec-GLMMdeviance} | ||||||||||||||||
|
@@ -136,8 +136,9 @@ Load the packages to be used | |||||||||||||||
#| output: false | ||||||||||||||||
#| label: packagesA03 | ||||||||||||||||
using AlgebraOfGraphics | ||||||||||||||||
using BenchmarkTools | ||||||||||||||||
using CairoMakie | ||||||||||||||||
using Chairmarks # a more modern BenchmarkTools | ||||||||||||||||
using DataFrames | ||||||||||||||||
using EmbraceUncertainty: dataset | ||||||||||||||||
using FreqTables | ||||||||||||||||
using LinearAlgebra | ||||||||||||||||
|
@@ -146,6 +147,7 @@ using MixedModelsMakie | |||||||||||||||
using NLopt | ||||||||||||||||
using PooledArrays | ||||||||||||||||
using StatsAPI | ||||||||||||||||
using TidierPlots | ||||||||||||||||
``` | ||||||||||||||||
|
||||||||||||||||
and define some constants | ||||||||||||||||
|
@@ -156,6 +158,8 @@ and define some constants | |||||||||||||||
#| label: constantsA03 | ||||||||||||||||
@isdefined(contrasts) || const contrasts = Dict{Symbol,Any}() | ||||||||||||||||
@isdefined(progress) || const progress = false | ||||||||||||||||
TidierPlots_set("plot_show", false) | ||||||||||||||||
TidierPlots_set("plot_log", false) | ||||||||||||||||
``` | ||||||||||||||||
|
||||||||||||||||
## Generalized linear models for binary data {#sec-BernoulliGLM} | ||||||||||||||||
|
@@ -402,8 +406,7 @@ Each evaluation of the deviance is fast, requiring only a fraction of a millisec | |||||||||||||||
|
||||||||||||||||
```{julia} | ||||||||||||||||
βopt = copy(com05fe.β) | ||||||||||||||||
@benchmark deviance(setβ!(m, β)) seconds = 1 setup = | ||||||||||||||||
(m = com05fe; β = βopt) | ||||||||||||||||
@be deviance(setβ!($com05fe, $βopt)) | ||||||||||||||||
``` | ||||||||||||||||
|
||||||||||||||||
but the already large number of evaluations for these six coefficients would not scale well as this dimension increases. | ||||||||||||||||
|
@@ -635,7 +638,7 @@ The IRLS algorithm has converged in 4 iterations to essentially the same devianc | |||||||||||||||
Each iteration of the IRLS algorithm takes more time than a deviance evaluation, but still only a fraction of a millisecond on a laptop computer. | ||||||||||||||||
|
||||||||||||||||
```{julia} | ||||||||||||||||
@benchmark deviance(updateβ!(m)) seconds = 1 setup = (m = com05fe) | ||||||||||||||||
@be deviance(updateβ!($com05fe)) | ||||||||||||||||
``` | ||||||||||||||||
|
||||||||||||||||
## GLMMs and the PIRLS algorithm {#sec-PIRLS} | ||||||||||||||||
|
@@ -866,7 +869,7 @@ pirls!(m; verbose=true); | |||||||||||||||
As with IRLS, PIRLS is a fast and stable algorithm for determining the mode of the conditional distribution $(\mcU|\mcY=\bby)$ with $\bbtheta$ and $\bbbeta$ held fixed. | ||||||||||||||||
|
||||||||||||||||
```{julia} | ||||||||||||||||
@benchmark pirls!(mm) seconds = 1 setup = (mm = m) | ||||||||||||||||
@be pirls!($m) | ||||||||||||||||
``` | ||||||||||||||||
|
||||||||||||||||
The time taken for the four iterations to determine the conditional mode of $\bbu$ is comparable to the time taken for a single call to `updateβ!`. | ||||||||||||||||
|
@@ -1127,28 +1130,34 @@ The weights and positions for the 9th order rule are shown in @fig-ghnine. | |||||||||||||||
#| code-fold: true | ||||||||||||||||
#| fig-cap: Weights and positions for the 9th order normalized Gauss-Hermite quadrature rule | ||||||||||||||||
#| label: fig-ghnine | ||||||||||||||||
#| warning: false | ||||||||||||||||
draw( | ||||||||||||||||
data(gausshermitenorm(9)) * | ||||||||||||||||
mapping(:abscissae => "Positions", :weights); | ||||||||||||||||
figure=(; size=(600, 450)), | ||||||||||||||||
) | ||||||||||||||||
df9 = DataFrame(gausshermitenorm(9)) | ||||||||||||||||
ggplot(df9, aes(; x=:abscissae, y=:weights)) + | ||||||||||||||||
geom_point() + | ||||||||||||||||
labs(; x="Positions", y="Weights") | ||||||||||||||||
# draw( | ||||||||||||||||
# data(gausshermitenorm(9)) * | ||||||||||||||||
# mapping(:abscissae => "Positions", :weights); | ||||||||||||||||
# figure=(; size=(600,450)), | ||||||||||||||||
# ) | ||||||||||||||||
``` | ||||||||||||||||
|
||||||||||||||||
Notice that the magnitudes of the weights drop quite dramatically away from zero, even on a logarithmic scale (@fig-ghninelog) | ||||||||||||||||
Notice that the magnitudes of the weights drop quite dramatically as the position moves away from zero, even on a logarithmic scale (@fig-ghninelog) | ||||||||||||||||
|
||||||||||||||||
```{julia} | ||||||||||||||||
#| code-fold: true | ||||||||||||||||
#| fig-cap: Weights (logarithm base 2) and positions for the 9th order normalized Gauss-Hermite quadrature rule | ||||||||||||||||
#| fig-cap: Weights (logarithm base 10) and positions for the 9th order normalized Gauss-Hermite quadrature rule | ||||||||||||||||
#| label: fig-ghninelog | ||||||||||||||||
#| warning: false | ||||||||||||||||
draw( | ||||||||||||||||
data(gausshermitenorm(9)) * mapping( | ||||||||||||||||
:abscissae => "Positions", | ||||||||||||||||
:weights => log2 => "log₂(weight)", | ||||||||||||||||
); | ||||||||||||||||
figure=(; size=(600, 450)), | ||||||||||||||||
) | ||||||||||||||||
ggplot(df9, aes(; x=:abscissae, y=:weights)) + | ||||||||||||||||
geom_point() + | ||||||||||||||||
labs(; x="Positions", y="Weights") + | ||||||||||||||||
scale_y_log10() | ||||||||||||||||
# draw( | ||||||||||||||||
# data(gausshermitenorm(9)) * mapping( | ||||||||||||||||
# :abscissae => "Positions", | ||||||||||||||||
# :weights => log2 => "log₂(weight)", | ||||||||||||||||
# ); | ||||||||||||||||
# figure=(; size=(600,450)), | ||||||||||||||||
# ) | ||||||||||||||||
Comment on lines
+1154
to
+1160
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
``` | ||||||||||||||||
|
||||||||||||||||
The definition of `MixedModels.GHnorm` is similar to the `gausshermitenorm` function with some extra provisions for ensuring symmetry of the abscissae and of the weights and for caching values once they have been calculated. | ||||||||||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.