Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
GidonFrischkorn committed Sep 3, 2024
1 parent 1ddebd4 commit c1099a5
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 85 deletions.
8 changes: 4 additions & 4 deletions R/distributions.R
Original file line number Diff line number Diff line change
Expand Up @@ -612,13 +612,13 @@ dm3 <- function(x, pars, m3_model, act_funs = NULL, log = TRUE, ...) {
acts

num_options <- m3_model$other_vars$num_options
if (tolower(m3_model$other_vars$choice_rule) == "luce") {
if (tolower(m3_model$other_vars$choice_rule) == "simple") {
probs <- (acts*num_options)/sum(acts*num_options)
} else if (tolower(m3_model$other_vars$choice_rule) == "softmax") {
probs <- (exp(acts)*num_options)/sum(exp(acts)*num_options)
} else {
stop2(glue("Unsupported choice rule: \" ", m3_model$other_vars$choice_rule,"\"\n",
"Please select either \"luce\" or \"softmax\" as choice_rule."))
"Please select either \"simple\" or \"softmax\" as choice_rule."))
}

density <- dmultinom(x, size = sum(x), prob = probs, log = TRUE)
Expand Down Expand Up @@ -667,13 +667,13 @@ rm3 <- function (n, size, pars, m3_model, act_funs = NULL, ...) {
acts

num_options <- m3_model$other_vars$num_options
if (tolower(m3_model$other_vars$choice_rule) == "luce") {
if (tolower(m3_model$other_vars$choice_rule) == "simple") {
probs <- (acts*num_options)/sum(acts*num_options)
} else if (tolower(m3_model$other_vars$choice_rule) == "softmax") {
probs <- (exp(acts)*num_options)/sum(exp(acts)*num_options)
} else {
stop2(glue("Unsupported choice rule: \" ", m3_model$other_vars$choice_rule,"\"\n",
"Please select either \"luce\" or \"softmax\" as choice_rule."))
"Please select either \"simple\" or \"softmax\" as choice_rule."))
}

t(rmultinom(n, size = size, prob = probs))
Expand Down
24 changes: 14 additions & 10 deletions R/model_m3.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
a = "General activation. This source of activation is added to all items that were presented during the current trial."
)

if (tolower(out$other_vars$choice_rule) == "luce") {
if (tolower(out$other_vars$choice_rule) == "simple") {
ss_links <- list(
c = "log",
a = "log"
Expand Down Expand Up @@ -76,7 +76,7 @@
f = "Filtering. This parameter captures the extent to which distractors remained in working memory."
)

if (tolower(out$other_vars$choice_rule) == "luce") {
if (tolower(out$other_vars$choice_rule) == "simple") {
cs_links <- list(
c = "log",
a = "log",
Expand Down Expand Up @@ -122,6 +122,11 @@
#' @title `r .model_m3()$name`
#' @name m3
#'
#' @description
#' The Memory Measurement Model (M3) is a measurement model for working memory
#' tasks with categorical responses. It assumes that each candidate in each response
#' category is activated by a combination of sources of activation. The probability
#' of choosing a response category is determined by the activation of the candidates.
#'
#' @param resp_cats The variable names that contain the number of responses for each of the
#' response categories used for the M3.
Expand All @@ -131,12 +136,11 @@
#' candidates in each response category. The order of these variables should be in the
#' same order as the names of the response categories passed to `resp_cats`
#' @param choice_rule The choice rule that should be used for the M3. The options are "softmax"
#' or "luce". The "softmax" option implements the softmax normalization of activation into
#' probabilities for choosing the different response categories. The "luce" option implements
#' the normalization of the different activations over the sum of all activations without
#' exponentiating them. For details on the differences of these choice rules please see
#' the appendix of Oberauer & Lewandowsky (2019) "Simple measurement models for complex
#' working memory tasks. Psychological Review"
#' or "simple". The "softmax" option implements the softmax normalization of activation into
#' probabilities for choosing the different response categories. The "simple" option implements
#' a simple normalization of the absolute activations over the sum of all activations. For details
#' on the differences of these choice rules please see the appendix of Oberauer & Lewandowsky (2019)
#' "Simple measurement models for complex working memory tasks" published in Psychological Review.
#' @param version Character. The version of the M3 model to use. Can be one of
#' `ss`, `cs`, or `custom`. The default is `custom`.
#' @param ... used internally for testing, ignore it
Expand Down Expand Up @@ -406,8 +410,8 @@ bmf2bf.m3 <- function(model, formula) {
choice_rule <- tolower(model$other_vars$choice_rule)

# add transformation to activation according to choice rules
transform_act <- ifelse(choice_rule == "luce", "log(", "")
end_act <- ifelse(choice_rule == "luce", ")", "")
transform_act <- ifelse(choice_rule == "simple", "log(", "")
end_act <- ifelse(choice_rule == "simple", ")", "")
zero_Opt <- ifelse(model$other_vars$choice_rule == "softmax", "(-100)", "(exp(-100))")
op_Nopts <- ifelse(model$other_vars$choice_rule == "softmax", "+", "*")
trans_Nopts <- ifelse(model$other_vars$choice_rule == "softmax", "log(", "")
Expand Down
9 changes: 6 additions & 3 deletions man/m3.Rd

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

Loading

0 comments on commit c1099a5

Please sign in to comment.