Skip to content

Commit

Permalink
improve beta
Browse files Browse the repository at this point in the history
  • Loading branch information
DominiqueMakowski committed Jul 29, 2024
1 parent 4aeffd2 commit 17a6e06
Show file tree
Hide file tree
Showing 20 changed files with 1,667 additions and 121 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,4 @@ Assets/scraps.cs.meta

content/_book
Manifest.toml
activate.jl
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
QuartoNotebookRunner = "4c0109c6-14e9-4c88-93f0-2b974d3468f4"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Turing = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"
SequentialSamplingModels = "0e71a2a6-2b30-4447-8742-d083a85e82d1"
SubjectiveScalesModels = "da3460ee-0a2f-4d2a-8d76-316f36bde5da"
Turing = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Binary file modified content/.jupyter_cache/global.db
Binary file not shown.
2 changes: 1 addition & 1 deletion content/.quarto/cites/index.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"3a_scales.qmd":["makowski2023novel"],"5_individual.qmd":[],"references.qmd":[],"3b_choices.qmd":["wagenmakers2008diffusion","heathcote2012linear","theriault2024check"],"4_rt.qmd":["wagenmakers2008diffusion","heathcote2012linear","theriault2024check","lo2015transform","schramm2019reaction","balota2011moving","matzke2009psychological","hohle1965inferred","kieffaber2006switch","matzke2009psychological","schwarz2001ex","heathcote2004fitting","anders2016shifted"],"2_predictors.qmd":[],"4a_rt_descriptive.qmd":["wagenmakers2008diffusion","heathcote2012linear","theriault2024check","wiemann2023using","lo2015transform","schramm2019reaction","wagenmakers2005relation","limpert2001log","balota2011moving","matzke2009psychological","hohle1965inferred","kieffaber2006switch","matzke2009psychological","schwarz2001ex","heathcote2004fitting","anders2016shifted"],"1_introduction.qmd":[],"3_scales.qmd":["makowski2023novel"],"4b_rt_generative.qmd":[],"index.qmd":[],"4_1_Normal.qmd":["wagenmakers2008diffusion","theriault2024check","lo2015transform","schramm2019reaction"]}
{"2_predictors.qmd":[],"4_rt.qmd":["wagenmakers2008diffusion","heathcote2012linear","theriault2024check","lo2015transform","schramm2019reaction","balota2011moving","matzke2009psychological","hohle1965inferred","kieffaber2006switch","matzke2009psychological","schwarz2001ex","heathcote2004fitting","anders2016shifted"],"3_scales.qmd":["makowski2023novel"],"references.qmd":[],"index.qmd":[],"5_individual.qmd":[],"3b_choices.qmd":["wagenmakers2008diffusion","heathcote2012linear","theriault2024check"],"4_1_Normal.qmd":["wagenmakers2008diffusion","theriault2024check","lo2015transform","schramm2019reaction"],"4b_rt_generative.qmd":[],"3a_scales.qmd":["makowski2023novel"],"1_introduction.qmd":[],"4a_rt_descriptive.qmd":["wagenmakers2008diffusion","heathcote2012linear","theriault2024check","wiemann2023using","lo2015transform","schramm2019reaction","wagenmakers2005relation","limpert2001log","balota2011moving","matzke2009psychological","hohle1965inferred","kieffaber2006switch","matzke2009psychological","schwarz2001ex","heathcote2004fitting","anders2016shifted"]}
2 changes: 1 addition & 1 deletion content/.quarto/idx/2_predictors.qmd.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion content/.quarto/xref/15f266d2
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"options":{"chapters":true},"headings":["brief-intro-to-julia-and-turing","installing-julia-and-packages","julia-basics","generate-data-from-normal-distribution","recover-distribution-parameters-with-turing","bayesian-linear-models","hierarchical-models"],"entries":[]}
{"headings":["brief-intro-to-julia-and-turing","installing-julia-and-packages","julia-basics","generate-data-from-normal-distribution","recover-distribution-parameters-with-turing","bayesian-linear-models","hierarchical-models"],"options":{"chapters":true},"entries":[]}
2 changes: 1 addition & 1 deletion content/.quarto/xref/1a47137c
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"entries":[],"options":{"chapters":true},"headings":["extracting-individual-parameters-from-mixed-models","population-informed-individual-bayesian-models","task-reliability"]}
{"entries":[],"headings":["extracting-individual-parameters-from-mixed-models","population-informed-individual-bayesian-models","task-reliability"],"options":{"chapters":true}}
2 changes: 1 addition & 1 deletion content/.quarto/xref/26afb962
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"headings":["categorical-predictors-condition-group","interactions","ordered-predictors-likert-scales","non-linear-relationships","polynomials","generalized-additive-models-gams"],"options":{"chapters":true},"entries":[]}
{"options":{"chapters":true},"entries":[],"headings":["categorical-predictors-condition-group","interactions","ordered-predictors-likert-scales","monotonic-effects","non-linear-relationships","polynomials","generalized-additive-models-gams"]}
2 changes: 1 addition & 1 deletion content/.quarto/xref/26e6880e
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"headings":["the-data","gaussian-aka-linear-model","model-specification","posterior-predictive-check","scaled-gaussian-model","solution-1-directional-effect-of-condition","solution-2-avoid-exploring-negative-variance-values","solution-3-use-a-softplus-function","exponential-transformation","softplus-function","the-model","conclusion","the-problem-with-linear-models","shifted-lognormal-model","prior-on-minimum-rt","model-specification-1","interpretation","exgaussian-model","conditional-tau-tau-parameter","interpretation-1","shifted-wald-model","model-specification-2","model-comparison","shifted-lognormal-mixed-model"],"entries":[],"options":{"chapters":true}}
{"headings":["the-data","gaussian-aka-linear-model","model-specification","posterior-predictive-check","scaled-gaussian-model","solution-1-directional-effect-of-condition","solution-2-avoid-exploring-negative-variance-values","solution-3-use-a-softplus-function","exponential-transformation","softplus-function","the-model","conclusion","the-problem-with-linear-models","shifted-lognormal-model","prior-on-minimum-rt","model-specification-1","interpretation","exgaussian-model","conditional-tau-tau-parameter","interpretation-1","shifted-wald-model","model-specification-2","model-comparison","shifted-lognormal-mixed-model"],"options":{"chapters":true},"entries":[]}
2 changes: 1 addition & 1 deletion content/.quarto/xref/6cbe9151
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"entries":[],"options":{"chapters":true},"headings":["preface","why-julia","why-bayesian","looking-for-coauthors"]}
{"headings":["preface","why-julia","why-bayesian","looking-for-coauthors"],"entries":[],"options":{"chapters":true}}
2 changes: 1 addition & 1 deletion content/.quarto/xref/a408ff3e
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"options":{"chapters":true},"entries":[],"headings":["evidence-accumulation","wald-distribution-revisited","drift-diffusion-model-ddm","linear-ballistic-accumulator-lba","other-models-lnr-rdm","including-random-effects","random-intercept","random-slopes","performance-tips","additional-resources"]}
{"entries":[],"headings":["evidence-accumulation","wald-distribution-revisited","drift-diffusion-model-ddm","linear-ballistic-accumulator-lba","other-models-lnr-rdm","including-random-effects","random-intercept","random-slopes","performance-tips","additional-resources"],"options":{"chapters":true}}
105 changes: 105 additions & 0 deletions content/2_predictors.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,119 @@ Likert scales, i.e., ordered multiple *discrete* choices are often used in surve

> The probabilities assigned to discrete probability descriptors are not necessarily equidistant (https://github.com/zonination/perceptions)
### Monotonic Effects

What can we do to better reflect the cognitive process underlying a Likert scale responses? [Monotonic effects](https://cran.r-project.org/web/packages/brms/vignettes/brms_monotonic.html).

- How to do Monotonic effects in Turing?

```
library(brms)
m <- brm(mpg ~ mo(gear), data = mtcars, refresh=0)
# stancode(m)
m
```
```
Family: gaussian
Links: mu = identity; sigma = identity
Formula: mpg ~ mo(gear)
Data: mtcars (Number of observations: 32)
Draws: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
total post-warmup draws = 4000
Regression Coefficients:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
Intercept 16.51 1.31 14.01 19.19 1.00 2106 2213
mogear 3.88 1.02 1.81 5.86 1.00 2160 2315
Monotonic Simplex Parameters:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
mogear1[1] 0.84 0.13 0.52 0.99 1.00 2698 1862
mogear1[2] 0.16 0.13 0.01 0.48 1.00 2698 1862
Further Distributional Parameters:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sigma 5.02 0.68 3.90 6.58 1.00 2850 2485
Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
and Tail_ESS are effective sample size measures, and Rhat is the potential
scale reduction factor on split chains (at convergence, Rhat = 1).
```


```{julia}
#| code-fold: false
# using Downloads, CSV, DataFrames, Random
# using Turing, Distributions
# using GLMakie
# using LinearAlgebra
# # Define the monotonic function
# function monotonic(scale::Vector{Float64}, i::Int)
# if i == 0
# return 0.0
# else
# return length(scale) * sum(scale[1:i])
# end
# end
# # Test
# using RDatasets
# data = dataset("datasets", "mtcars")
# # Response variable
# y = data[!, :MPG]
# x = data[!, :Gear]
# # Number of observations
# N = length(y)
# # Length of simplex
# Jmo = maximum(x)
# # Prior concentration for the simplex (using a uniform prior for simplicity)
# con_simo_1 = ones(Jmo)
# # Turing Model Specification
# @model function monotonic_model(y, x, N, Jmo, con_simo_1)
# # Parameters
# Intercept ~ Normal(19.2, 5.4)
# simo_1 ~ Dirichlet(con_simo_1)
# sigma ~ truncated(Normal(0, 5.4), 0, Inf)
# bsp ~ Normal(0, 1)
# # Linear predictor
# mu = Vector{Float64}(undef, N)
# for n in 1:N
# mu[n] = Intercept + bsp * monotonic(simo_1, x[n])
# end
# # Likelihood
# y ~ MvNormal(mu, sigma)
# end
# # Run the model
# model = monotonic_model(y, x, N, Jmo, con_simo_1)
# chain = sample(model, NUTS(), 1000)
# # Display the results
# display(chain)
```



## Non-linear Relationships

![](https://img.shields.io/badge/status-good_for_contributing-blue)

It is a common misconception that "linear models" can only model straight relationships between variables.
In fact, the "linear" part refers to the relationship between the parameters (between the outcome varialbe and the predictors).



```{julia}
#| code-fold: false
Expand Down
Loading

0 comments on commit 17a6e06

Please sign in to comment.