Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
venpopov committed Mar 26, 2024
2 parents 18bbd6f + 48adf14 commit ca3abe4
Show file tree
Hide file tree
Showing 129 changed files with 5,967 additions and 4,018 deletions.
32 changes: 16 additions & 16 deletions .dev/bmm_default_priors.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ First, we can see what happens by default in `brms`. Let's look at a simple line
It puts a default prior on all parameters that have only an intercept

```{r}
dat <- OberauerLin_2017
dat <- oberauer_lin_2017
dat$cond <- factor(rep(1:4, each=nrow(dat)/4)) # fake condition for testing formulas
get_prior(bf(dev_rad ~ 1, sigma ~ 1), dat)
```
Expand Down Expand Up @@ -63,7 +63,7 @@ get_prior(bf(dev_rad ~ 1, sigma ~ set_size + (set_size|ID)), dat)

## How should we do it in `bmm`

Currently we put a default prior on all parameters, assuming naively that they are specified with a suppressed intercept (except for the sdmSimple, for which we have no default priors yet). We don't want to follow `brms` approach, because these measurement models need meaningful default priors to help with sampling.
Currently we put a default prior on all parameters, assuming naively that they are specified with a suppressed intercept (except for the sdm, for which we have no default priors yet). We don't want to follow `brms` approach, because these measurement models need meaningful default priors to help with sampling.

Options: 1) we do it like `brms` and let the user specify priors for all parameters 2) we put reasonable priors on intercepts and on all effects when an intercept is suprresed, but leave flat priors for effects when an intercept is present 3) we put reasonable priors on all parameters, regardless of the formula

Expand All @@ -87,9 +87,9 @@ options(list(bmm.default_priors = FALSE))
All model parameters are `nlpar` so they get class `b` with coef `Intercept`

```{r}
model <- mixture3p('dev_rad', nt_features = paste0('col_nt',1:7), setsize='set_size')
model <- mixture3p('dev_rad', nt_features = paste0('col_nt',1:7), set_size='set_size')
formula <- bmf(kappa ~ 1, thetat ~ 1, thetant ~ 1)
get_model_prior(formula, dat, model)
default_prior(formula, dat, model)
```

```{r}
Expand All @@ -102,7 +102,7 @@ For kappa, which we include and intercept and a predictor, we get class `b` with

```{r}
formula <- bmf(kappa ~ session, thetat ~ 1, thetant ~ 1)
get_model_prior(formula, dat, model)
default_prior(formula, dat, model)
```

```{r}
Expand All @@ -115,7 +115,7 @@ For kappa, which we include and intercept and a predictor, we get class `b` with

```{r}
formula <- bmf(kappa ~ 0+session, thetat ~ 1, thetant ~ 1)
get_model_prior(formula, dat, model)
default_prior(formula, dat, model)
```

```{r}
Expand All @@ -126,7 +126,7 @@ terms(formula$kappa)

```{r}
formula <- bmf(kappa ~ 0+session + ( 0+session|ID), thetat ~ 1, thetant ~ 1)
get_model_prior(formula, dat, model)
default_prior(formula, dat, model)
```

```{r}
Expand All @@ -138,7 +138,7 @@ terms(formula$kappa)
```{r}
formula <- bmf(kappa ~ session + cond, thetat ~ 1, thetant ~ 1)
get_model_prior(formula, dat, model)
default_prior(formula, dat, model)
```

```{r}
Expand All @@ -154,7 +154,7 @@ What we can do, is for each predictor, check how many levels appear.
```{r}
formula <- bmf(kappa ~ 0 + session + cond, thetat ~ 1, thetant ~ 1)
get_model_prior(formula, dat, model)
default_prior(formula, dat, model)
```

```{r}
Expand All @@ -166,7 +166,7 @@ terms(formula$kappa)
```{r}
formula <- bmf(kappa ~ 0 + session * cond, thetat ~ 1, thetant ~ 1)
get_model_prior(formula, dat, model)
default_prior(formula, dat, model)
```

```{r}
Expand All @@ -178,7 +178,7 @@ terms(formula$kappa)
```{r}
formula <- bmf(kappa ~ 0 + session:cond + cond + session, thetat ~ 1, thetant ~ 1)
get_model_prior(formula, dat, model)
default_prior(formula, dat, model)
```

```{r}
Expand All @@ -190,7 +190,7 @@ terms(formula$kappa)
```{r}
formula <- bmf(kappa ~ 0 + session:cond, thetat ~ 1, thetant ~ 1)
get_model_prior(formula, dat, model)
default_prior(formula, dat, model)
```

```{r}
Expand Down Expand Up @@ -235,11 +235,11 @@ A helper function to compare the priors with and without the default priors.

```{r}
compare_priors <- function(formula,dat,model) {
p1 <- withr::with_options(list('bmm.default_priors'=FALSE), get_model_prior(formula, dat, model)) %>%
p1 <- withr::with_options(list('bmm.default_priors'=FALSE), default_prior(formula, dat, model)) %>%
brms:::prepare_print_prior() %>%
rename(priorBRMS=prior) %>%
select(priorBRMS,class,coef,group,resp,dpar,nlpar)
p2 <- withr::with_options(list('bmm.default_priors'=TRUE), get_model_prior(formula, dat, model)) %>%
p2 <- withr::with_options(list('bmm.default_priors'=TRUE), default_prior(formula, dat, model)) %>%
brms:::prepare_print_prior() %>%
rename(priorBMM=prior) %>%
select(priorBMM,class,coef,group,resp,dpar,nlpar)
Expand All @@ -252,7 +252,7 @@ compare_priors <- function(formula,dat,model) {


```{r}
model3p <- mixture3p('dev_rad', nt_features = paste0('col_nt',1:7), setsize='set_size')
model3p <- mixture3p('dev_rad', nt_features = paste0('col_nt',1:7), set_size='set_size')
```

<details><summary>Click to expand</summary>
Expand Down Expand Up @@ -349,7 +349,7 @@ compare_priors(formula, dat, model3p)

```{r}
options(bmm.sort_data = F)
modelSDM <- sdmSimple('dev_rad')
modelSDM <- sdm('dev_rad')
```

<details><summary>Click to expand</summary>
Expand Down
10 changes: 5 additions & 5 deletions .dev/bmm_default_priors.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Click to expand
It puts a default prior on all parameters that have only an intercept

``` r
dat <- OberauerLin_2017
dat <- oberauer_lin_2017
dat$cond <- factor(rep(1:4, each=nrow(dat)/4)) # fake condition for testing formulas
get_prior(bf(dev_rad ~ 1, sigma ~ 1), dat)
```
Expand Down Expand Up @@ -136,7 +136,7 @@ get_prior(bf(dev_rad ~ 1, sigma ~ set_size + (set_size|ID)), dat)

Currently we put a default prior on all parameters, assuming naively
that they are specified with a suppressed intercept (except for the
sdmSimple, for which we have no default priors yet). We don’t want to
sdm, for which we have no default priors yet). We don’t want to
follow `brms` approach, because these measurement models need meaningful
default priors to help with sampling.

Expand Down Expand Up @@ -175,7 +175,7 @@ All model parameters are `nlpar` so they get class `b` with coef
`Intercept`

``` r
model <- mixture3p('dev_rad', nt_features = paste0('col_nt',1:7), setsize='set_size')
model <- mixture3p('dev_rad', nt_features = paste0('col_nt',1:7), set_size='set_size')
formula <- bmf(kappa ~ 1, thetat ~ 1, thetant ~ 1)
get_model_prior(formula, dat, model)
```
Expand Down Expand Up @@ -661,7 +661,7 @@ compare_priors <- function(formula,dat,model) {
```

``` r
model3p <- mixture3p('dev_rad', nt_features = paste0('col_nt',1:7), setsize='set_size')
model3p <- mixture3p('dev_rad', nt_features = paste0('col_nt',1:7), set_size='set_size')
```

<details>
Expand Down Expand Up @@ -912,7 +912,7 @@ compare_priors(formula, dat, model3p)

``` r
options(bmm.sort_data = F)
modelSDM <- sdmSimple('dev_rad')
modelSDM <- sdm('dev_rad')
```

<details>
Expand Down
111 changes: 111 additions & 0 deletions .dev/useful-git-commands.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
---
title: "Useful git commands"
output: html_notebook
editor_options:
chunk_output_type: console
---

## Setup

```{r setup}
knitr::opts_chunk$set(engine.opts = list(bash = "-l"))
```


```{bash}
pwd # checking where bash commands from this markdown are executed
```

This is a compilation of git commands I frequently use, but often forget. I have set the file to run from the project working directory. So you can execute code chunks within the notebook and they will be run. I keep this file always open, making it easier for something that typing out the commands in the terminal or googling again how to do something. Will update as I go.

::: {.blackbox style="color: red"}
*Since these commands will be actually executed, do not run a code block unless you know what it will do, and DO NOT knit the whole file*
:::

## Status

Always useful

```{bash, engine.opts='-l'}
git status
```

one-liner logs

```{bash}
git log --oneline -n 10 --decorate
```

## Branch management

### Check current local and remote branches

```{bash}
git branch
```

### Sync with remote without pulling changes

> Useful to just see if changes have been made to any branches without overwriting any work in progress.
>
> I usually run this every day when I sit down to work in the morning
```{bash}
git fetch origin
```

### Remove reference to remote branch after it has been deleted on github

> Run the following commands when you want to clean the local repo from outdated branches (merged or deleted on github). This does ***not*** delete the local branches
```{bash}
git fetch origin ## syncs with the remote repository
git remote prune origin ## deltes references to non-existing remote branches
```

or together

```{bash}
git fetch --prune ## sync with the remote and then delete non-existing branches
```

or you can set this as a configuration once

```{bash}
git config --global fetch.prune true
```

and then you will prune automatically whenever you run

```{bash}
git fetch origin
```

### Deleting pruned local branches

> After pruning, you can use the commands below to delete all pruned branches. Be careful! See [here](https://dillionmegida.com/p/delete-outdated-branches/#does-pruning-delete-the-local-branches)
```{bash}
git checkout develop ## switch to main develop branch
git branch --merged | egrep -v "master|develop" ## get a list of all branches that have been already merged into develop
```

check out the output. Do you really want to delete these branches? If yes, you can run

```{bash}
git branch --merged | egrep -v "master|develop" | xargs git branch -d
```

The `xargs` command converts the output of `egrep` to the arguments of `git branch -d`. i.e., this will be interpreted as `git branch -d [egrep output]`. And `git branch -d` does a soft delete on the branches. Soft deletes ensure that the branch has been fully merged.

Sometimes there are leftover branches because they were not merged but rather squashed or rebased into develop. You can delete individual branches with

```{bash}
git branch -d #followed by name of branch
```

or if that doesn't work, but you are sure you want to delete it, you can force with capital D

```{bash}
git branch -D #followed by name of branch
```
6 changes: 3 additions & 3 deletions .dev/visualizing_priors.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
data <- OberauerLin_2017
data <- oberauer_lin_2017
data$session <- as.factor(data$session)
formula <- bmf(c ~ 0 + set_size, kappa ~ session)
model <- sdmSimple('dev_rad')
get_model_prior(formula, data, model)
model <- sdm('dev_rad')
default_prior(formula, data, model)


x <- exp(rnorm(1000000,3,1.75))
Expand Down
42 changes: 39 additions & 3 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ on:

name: R-CMD-check

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}
Expand All @@ -28,20 +32,52 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
rtools-version: ${{ matrix.config.rtools }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

# As cmdstanr is not yet on CRAN, configure the action to only install the
# 'Depends' packages by default and then manually specify the 'Suggests'
# packages that are needed for R CMD CHECK
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check
dependencies: NA
extra-packages: |
rmarkdown
withr
knitr
posterior
here
testthat
rcmdcheck
stan-dev/cmdstanr
rmarkdown
bookdown
tidybayes
ggplot2
mixtur
ggthemes
cowplot
stringr
remotes
waldo
fansi
- name: Build Cmdstan
run: |
cmdstanr::check_cmdstan_toolchain(fix = TRUE)
cmdstanr::install_cmdstan(cores = parallel::detectCores())
shell: Rscript {0}

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
build_args: 'c("--no-manual", "--no-build-vignettes")'
args: 'c("--no-manual", "--as-cran", "--ignore-vignettes")'
Loading

0 comments on commit ca3abe4

Please sign in to comment.