From 7a5979d7f0ecdc2785e3307a29c3fb1fa4ecdb44 Mon Sep 17 00:00:00 2001 From: Douglas Bates Date: Fri, 26 Jan 2024 18:03:24 -0600 Subject: [PATCH] Use inline evaluation for results in text (requires Quarto v1.4) (#42) --- Project.toml | 9 ++++----- intro.qmd | 39 ++++----------------------------------- 2 files changed, 8 insertions(+), 40 deletions(-) diff --git a/Project.toml b/Project.toml index 7e65bcc..976ef87 100644 --- a/Project.toml +++ b/Project.toml @@ -26,8 +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" RectangularFullPacked = "27983f2f-6524-42ba-a408-2b5a31c238e4" @@ -55,17 +53,18 @@ 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,0.14" +Random = "1" Scratch = "1" StandardizedPredictors = "1" StatsAPI = "1" StatsBase = "0.33, 0.34" StatsModels = "0.7" -Tables = "1.7" -TypedTables = "1.4" +Tables = "1" +TypedTables = "1" ZipFile = "0.10" julia = "1.8" diff --git a/intro.qmd b/intro.qmd index afc90f1..1f1bc6b 100644 --- a/intro.qmd +++ b/intro.qmd @@ -107,10 +107,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 Random # random number generation using StatsBase # basic statistical summaries @@ -626,23 +624,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. @@ -666,15 +650,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). @@ -775,14 +751,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}