Skip to content
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 inline evaluation for results in text (requires Quarto v1.4) #42

Merged
merged 5 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ MixedModelsMakie = "b12ae82c-6730-437f-aff9-d2c38332a376"
NLopt = "76087f3c-5699-56af-9a33-bf431cd00edd"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
PooledArrays = "2dfb63ee-cc39-5dd5-95bd-886bf059d720"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
RCall = "6f49c342-dc21-5d91-9882-a32aef131414"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand Down Expand Up @@ -55,11 +54,13 @@ Downloads = "1"
Effects = "1"
FreqTables = "0.4"
GLM = "1"
LinearAlgebra = "1"
MixedModels = "4,5"
MixedModelsMakie = "0.3.13"
NLopt = "1"
ProgressMeter = "1.7"
RCall = "0.13"
Random = "1"
Scratch = "1"
StandardizedPredictors = "1"
StatsAPI = "1"
Expand Down
39 changes: 4 additions & 35 deletions intro.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,8 @@ using AlgebraOfGraphics # high-level graphics
using CairoMakie # graphics back-end
using DataFrameMacros # elegant DataFrame manipulation
using DataFrames # DataFrame implementation
using Markdown # utilities for generating markdown text
using MixedModels # fit and examine mixed-effects models
using MixedModelsMakie # graphics for mixed-effects models
using Printf # formatted printing
using ProgressMeter # progress of optimizer iterations
using Random # random number generation
using StatsBase # basic statistical summaries
Expand Down Expand Up @@ -606,23 +604,9 @@ draw(
)
```

:::{.callout-note collapse="true"}

### Use :compact=true when interpolating numeric values

Find a way to use `:compact=true` when interpolating numeric values into the text
:::
The distribution of the estimates of `β₁` is more-or-less a Gaussian (or "normal") shape, with a mean value of `{julia} repr(mean(βdf.value), context=:compact=>true)` which is close to the estimated `β₁` of `{julia} repr(only(dsm01.β), context=:compact=>true)`.

```{julia}
#| echo: false
Markdown.parse(
"""
The distribution of the estimates of `β₁` is more-or-less a Gaussian (or "normal") shape, with a mean value of $(@sprintf("%f", mean(βdf.value))) which is close to the estimated `β₁` of $(@sprintf("%f", only(dsm01.β))).

Similarly the standard deviation of the simulated β values, $(std(βdf.value)) is close to the standard error of the parameter, $(only(stderror(dsm01))).
""",
)
```
Similarly the standard deviation of the simulated β values, `{julia} repr(std(βdf.value), context=:compact=>true)` is close to the standard error of the parameter, `{julia} repr(only(stderror(dsm01)), context=:compact=>true)`.

In other words, the estimator of the fixed-effects parameter in this case behaves as we would expect.
The estimates are approximately normally distributed centered about the "true" parameter value with a standard deviation given by the standard error of the parameter.
Expand All @@ -645,15 +629,7 @@ draw(
```

The estimator for the residual standard deviation, $\sigma$, is approximately normally distributed but the estimator for $\sigma_1$, the standard deviation of the `batch` random effects is bimodal (i.e. has two "modes" or local maxima).

```{julia}
#| echo: false
Markdown.parse(
"""
There is one peak around the "true" value for the simulation, $(only(dsm01.σs.batch)), and another peak at zero.
""",
)
```
There is one peak around the "true" value for the simulation, `{julia} repr(only(dsm01.σs.batch), context=:compact=>true), and another peak at zero.

The apparent distribution of the estimates of $\sigma_1$ in @fig-dsm01_bs_sigma_density is being distorted by the method of approximating the density.
A [kernel density estimate](https://en.wikipedia.org/wiki/Kernel_density_estimation) approximates a probability density from a finite sample by blurring or smearing the positions of the sample values according to a *kernel* such as a narrow Gaussian distribution (see the linked article for details).
Expand Down Expand Up @@ -748,14 +724,7 @@ dsm01trace = fit(
DataFrame(dsm01trace.optsum.fitlog)
```

```{julia}
#| echo: false
Markdown.parse(
"""
Here the algorithm converges after 18 function evaluations to a profiled deviance of $(dsm01trace.objective) at θ = $(only(dsm01trace.theta)).
""",
)
```
Here the algorithm converges after 18 function evaluations to a profiled deviance of `{julia} repr(dsm01trace.objective, context=:compact=>true)` at θ = `{julia} repr(only(dsm01trace.theta), context=:compact=>true)`.

## Assessing the random effects {#sec-assessRE}

Expand Down