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

add DV as variable to model() call & add bmm_formula #92

Merged
merged 50 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
caadeb1
add DV as variable to model() call & add bmm_formula
GidonFrischkorn Feb 12, 2024
1d976a9
Resovle conflicts
GidonFrischkorn Feb 12, 2024
ab76a47
change "bias" to "mu"
GidonFrischkorn Feb 12, 2024
6aa24f9
Adapt unit test to bmm_formula set-up.
GidonFrischkorn Feb 13, 2024
412aa84
Merge branch 'develop' into 79-DV-passed-to-model
venpopov Feb 13, 2024
58b635d
Add more detailed description of the bmm formulas
venpopov Feb 13, 2024
f33ff77
rename bmm_formula to bmmformula and replace all old brmsformula refe…
venpopov Feb 13, 2024
b191f0e
add bmf() alias, move bmmformula to own file
venpopov Feb 13, 2024
5739124
update valid formula check, add class 'bmmformula'
venpopov Feb 13, 2024
b6a240a
fix bmf copy paste error
venpopov Feb 13, 2024
b7034e9
use base all.vars for extracting par names
venpopov Feb 13, 2024
d96b96f
delete not longer necessary get_response function
venpopov Feb 13, 2024
11e813e
simplify and move param check to own function
venpopov Feb 13, 2024
bb5aa36
change respErr to resp_err to be consistent in style with naming of o…
venpopov Feb 13, 2024
8d153f5
fix typos and some examples
venpopov Feb 14, 2024
5054896
update documentation
venpopov Feb 14, 2024
ff7793c
add + method for bmmformula
venpopov Feb 14, 2024
27cf549
add global optiom 'bmm.silent' to be able to supress messages'
venpopov Feb 14, 2024
3ed8b0d
minor fix to configure_options
venpopov Feb 14, 2024
fdef4fa
remove b parameter from IMM description
venpopov Feb 14, 2024
3f08fc5
make wrong_parameters recognize non-linear transformations
venpopov Feb 14, 2024
ae84729
check for "resp_err" in data should be in the vwm class
venpopov Feb 14, 2024
ffc60b2
add placeholder for notyetimplemented update method
venpopov Feb 14, 2024
7a88eb1
add void_mu argument to model_objects
venpopov Feb 14, 2024
14a9892
generalize formula conversion with bmf2bf method
venpopov Feb 14, 2024
7127c4f
generalize setting constant priors via function
venpopov Feb 14, 2024
0b6824f
fix missing brms:: before set_prior
venpopov Feb 15, 2024
c77a375
mixture3p ready with new formula syntax
venpopov Feb 15, 2024
6870f5d
mixture2p model ready with new syntax
venpopov Feb 15, 2024
9b684aa
imm ready with new formul syntax
venpopov Feb 15, 2024
553b65d
complete transition to bmmformula syntax
venpopov Feb 15, 2024
4733b8d
update formula and distribution tests, minor cleanup
venpopov Feb 15, 2024
6f0ddff
Update Vignettes to `bmmformula`
GidonFrischkorn Feb 15, 2024
4b2bc66
Remove test for spatial distances in `check_data.IMMspatial`
GidonFrischkorn Feb 15, 2024
49c9437
Add tests for `check_data.IMMspatial`
GidonFrischkorn Feb 15, 2024
f12c55a
Merge branch 'develop' into 79-DV-passed-to-model
venpopov Feb 15, 2024
80e6916
avoid overwrite of `bmf` when using `bmf2bf.bmmmodel`
GidonFrischkorn Feb 15, 2024
7bead4b
Update NEWS.md
GidonFrischkorn Feb 15, 2024
e9c12dd
Relabel `non_targets` and `spaPos` to `nt_features` and `nt_distance`
GidonFrischkorn Feb 15, 2024
1329df7
Update `use_model_template` and documentation
GidonFrischkorn Feb 16, 2024
b490d80
Spelling updates.
GidonFrischkorn Feb 16, 2024
d718d12
shorten var checks
venpopov Feb 16, 2024
b9ae6ba
Merge branch '79-DV-passed-to-model' of https://github.com/venpopov/b…
venpopov Feb 16, 2024
d27d8a3
rename nt_distance to nt_distances for consistency
venpopov Feb 16, 2024
3884a2d
minor stylistic changes, add class bmmfit,
venpopov Feb 16, 2024
72c7f79
revert renaming of arguments in ref fits
venpopov Feb 16, 2024
7b74826
change how stan files are read
venpopov Feb 16, 2024
80c50b2
add keywords to bmf2bf for website
venpopov Feb 16, 2024
e292e73
add fixed parameters to documentation of each model
venpopov Feb 16, 2024
52e8a8b
bump version number
venpopov Feb 16, 2024
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
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export("%>%")
export(IMMabc)
export(IMMbsc)
export(IMMfull)
export(bmf)
export(bmmformula)
export(c_bessel2sqrtexp)
export(c_sqrtexp2bessel)
Expand Down
102 changes: 102 additions & 0 deletions R/bmmformula.R
venpopov marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#' @title Create formula for predicting parameters of a `bmmmodel`
#'
#' @description This function is used to specify the formulas predicting the
#' different parameters of a `bmmmodel`.
#'
#' @aliases bmf
#'
#' @details # General formula structure
#'
#' The formula argument accepts formulas of the following syntax:
#'
#' ``` r
#' parameter ~ fixed_effects + (random_effects | grouping_variable)
#' ```
#'
#' `bmm` formulas are built on `brms` formulas and function in nearly the same
#' way, so you can use most of the `brms` formula syntax. The main differences
#' is that in `bmm` formulas, the response variable is not specified in the
#' formula. Instead, each parameter of the model is explicitly specified as the
#' left-hand side of the formula. In `brms`, the response variable is always
#' specified as the left-hand side of the first formula, which implicitly means
#' that any predictors in the first formula are predictors of the `mu` parameter
#' of the model. In general, measurement models do not all have a `mu`
#' parameter, therefore it is more straigthforward to explicitely predict each
#' parameter of the model.
#'
#' For example, in the following `brms` formula for the drift diffusion model,
#' the first line corresponds to the drift rate parameter, but this is not
#' explicitely stated.
#'
#'
#' brmsformula(rt | dec(response) ~ condition + (condition | id),
#' bs ~ 1 + (1 | id),
#' ndt ~ 1 + (1 | id),
#' bias ~ 1 + (1 | id))
#'
#'
#'
#'
#' In `bmm`, the same formula would be written as:
#'
#' bmmformula(drift ~ condition + (condition | id),
#' bs ~ 1 + (1 | id),
#' ndt ~ 1 + (1 | id),
#' bias ~ 1 + (1 | id))
#'
#' and the rt and response variables would be specified in the model argument of
#' the `fit_model` function.
#'
#' Aside from that, the `bmm` formula syntax is the same as the `brms` formula
#' syntax. For more information on the `brms` formula syntax, see
#' [brms::brmsformula()].
#'
#' You can also use the `bmf()` function as a shorthand for `bmmformula()`.
#'
#'
#' @param formula Formula for predicting a `bmmmodel` parameter.
#' @param ... Additional formulas for more than a single model parameter.
#'
#' @return A list of formulas for each parameters being predicted
#' @export
#' @examples
#' imm_formula <- bmmformula(
#' c ~ 0 + setsize + (0 + setsize | id),
#' a ~ 1,
#' kappa ~ 0 + setsize + (0 + setsize | id)
#' )
#'
#' # or use the shorter alias 'bmf'
#' imm_formula2 <- bmf(
#' c ~ 0 + setsize + (0 + setsize | id),
#' a ~ 1,
#' kappa ~ 0 + setsize + (0 + setsize | id)
#' )
#' identical(imm_formula, imm_formula2)
#'
#'
bmmformula <- function(formula, ...){
# paste formulas into a single list
dots <- list(...)
formula <- list(formula)
formula <- c(formula, dots)

# extract parameter names
pform_names <- character()
for (i in 1:length(formula)) {
form_line <- formula[[i]]
parm <- formula.tools::lhs(form_line)
pform_names <- c(pform_names, as.character(parm))
}

# label the different formulas according to the parameter predicted
names(formula) <- pform_names
return(formula)
}


# alias of bmmformula
#' @export
bmf <- function(formula, ...) {
venpopov marked this conversation as resolved.
Show resolved Hide resolved
brmsformula(bmmformula(formula, ...))
venpopov marked this conversation as resolved.
Show resolved Hide resolved
}
86 changes: 0 additions & 86 deletions R/helpers-formula.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,89 +41,3 @@ get_response <- function(formula) {
response <- attr(tt, "response") # index of response var
vars[response]
}


#' @title Create formula for predicting parameters of a `bmmmodel`
#'
#' @description This function is used to specify the formulas predicting the
#' different parameters of a `bmmmodel`.
#'
#' @details # General formula structure
#'
#' The formula argument accepts formulas of the following syntax:
#'
#' ``` r
#' parameter ~ fixed_effects + (random_effects | grouping_variable)
#' ```
#'
#' `bmm` formulas are built on `brms` formulas and function in nearly the same
#' way, so you can use most of the `brms` formula syntax. The main differences
#' is that in `bmm` formulas, the response variable is not specified in the
#' formula. Instead, each parameter of the model is explicitly specified as the
#' left-hand side of the formula. In `brms`, the response variable is always
#' specified as the left-hand side of the first formula, which implicitly means
#' that any predictors in the first formula are predictors of the `mu` parameter
#' of the model. In general, measurement models do not all have a `mu`
#' parameter, therefore it is more straigthforward to explicitely predict each
#' parameter of the model.
#'
#' For example, in the following `brms` formula for the drift diffusion model,
#' the first line corresponds to the drift rate parameter, but this is not
#' explicitely stated.
#'
#'
#' brmsformula(rt | dec(response) ~ condition + (condition | id),
#' bs ~ 1 + (1 | id),
#' ndt ~ 1 + (1 | id),
#' bias ~ 1 + (1 | id))
#'
#'
#'
#'
#' In `bmm`, the same formula would be written as:
#'
#' bmmformula(drift ~ condition + (condition | id),
#' bs ~ 1 + (1 | id),
#' ndt ~ 1 + (1 | id),
#' bias ~ 1 + (1 | id))
#'
#' and the rt and response variables would be specified in the model argument of
#' the `fit_model` function.
#'
#' Aside from that, the `bmm` formula syntax is the same as the `brms` formula
#' syntax. For more information on the `brms` formula syntax, see
#' [brms::brmsformula()].
#'
#'
#' @param formula Formula for predicting a `bmmmodel` parameter.
#' @param ... Additional formulas for more than a single model parameter.
#'
#' @return A list of formulas for each parameters being predicted
#' @export
#' @examples
#' imm_formula <- bmmformula(
#' c ~ 0 + setsize + (0 + setsize | id),
#' a ~ 1,
#' kappa ~ 0 + setsize + (0 + setsize | id)
#' )
#'
#' imm_formula
#'
bmmformula <- function(formula, ...){
# paste formulas into a single list
dots <- list(...)
formula <- list(formula)
formula <- c(formula, dots)

# extract parameter names
pform_names <- character()
for (i in 1:length(formula)) {
form_line <- formula[[i]]
parm <- formula.tools::lhs(form_line)
pform_names <- c(pform_names, as.character(parm))
}

# label the different formulas according to the parameter predicted
names(formula) <- pform_names
return(formula)
}
14 changes: 12 additions & 2 deletions man/bmmformula.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.