Skip to content

Commit

Permalink
Merge pull request #75 from venpopov/71-remove-gen_3p_data-and-gen_im…
Browse files Browse the repository at this point in the history
…m_data

Remove gen_3p_data and gen_imm_data
  • Loading branch information
venpopov authored Feb 8, 2024
2 parents 8a99014 + bddc801 commit 56f3053
Show file tree
Hide file tree
Showing 18 changed files with 96 additions and 391 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ Imports:
dplyr,
withr,
tidyr,
circular,
stats,
matrixStats,
methods
Expand Down
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ export(dmixture2p)
export(dmixture3p)
export(dsdm)
export(fit_model)
export(gen_3p_data)
export(gen_imm_data)
export(get_model_prior)
export(k2sd)
export(mixture2p)
Expand Down
2 changes: 1 addition & 1 deletion R/bmm_model_mixture2p.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#' @examples
#' \dontrun{
#' # generate artificial data
#' dat <- gen_3p_data(N=2000, pmem=0.6, pnt=0.3, kappa=10, setsize=4, relative_resp=T)
#' dat <- data.frame(y = rmixture2p(n=2000))
#'
#' # define formula
#' ff <- brms::bf(y ~ 1,
Expand Down
11 changes: 8 additions & 3 deletions R/bmm_model_mixture3p.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@
#' @examples
#' \dontrun{
#' # generate artificial data from the Bays et al (2009) 3-parameter mixture model
#' dat <- gen_3p_data(N=2000, pmem=0.6, pnt=0.3, kappa=10, setsize=4, relative_resp=T)
#' dat <- data.frame(
#' y = rmixture3p(n=2000, mu = c(0,1,-1.5,2)),
#' nt1_loc = 1,
#' nt2_loc = -1.5,
#' nt3_loc = 2
#' )
#'
#' # define formula
#' ff <- brms::bf(y ~ 1,
Expand All @@ -53,14 +58,14 @@
#' thetant ~ 1)
#'
#' # specify the 3-parameter model
#' model <- mixture3p(non_targets = paste0('nt',1:3,'_loc'), setsize=4)
#' model <- mixture3p(non_targets = paste0('nt',1:3,'_loc'), setsize = 4)
#'
#' # fit the model
#' fit <- fit_model(formula = ff,
#' data = dat,
#' model = model,
#' parallel=T,
#' iter=500,
#' iter = 500,
#' backend='cmdstanr')
#' }
mixture3p <- .model_mixture3p
Expand Down
9 changes: 4 additions & 5 deletions R/fit_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,17 @@
#' @examples
#' \dontrun{
#' # generate artificial data from the Bays et al (2009) 3-parameter mixture model
#' dat <- gen_3p_data(N=2000, pmem=0.6, pnt=0.3, kappa=10, setsize=4, relative_resp=T)
#' dat <- rsdm(n=2000)
#'
#' # define formula
#' ff <- brms::bf(y ~ 1,
#' kappa ~ 1,
#' thetat ~ 1,
#' thetant ~ 1)
#' c ~ 1,
#' kappa ~ 1)
#'
#' # fit the model
#' fit <- fit_model(formula = ff,
#' data = dat,
#' model = mixture3p(non_targets = paste0('nt',1:3,'_loc'), setsize=4),
#' model = sdmSimple(),
#' parallel=T,
#' iter=500,
#' backend='cmdstanr')
Expand Down
14 changes: 5 additions & 9 deletions R/get_model_prior.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,18 @@
#'
#' @examples
#' \dontrun{
#' # generate artificial data from the Bays et al (2009) 3-parameter mixture model
#' dat <- gen_3p_data(N=2000, pmem=0.6, pnt=0.3, kappa=10, setsize=4, relative_resp=T)
#' # generate artificial data from the Signal Discrimination Model
#' dat <- rsdm(n=2000)
#'
#' # define formula
#' ff <- brms::bf(y ~ 1,
#' kappa ~ 1,
#' thetat ~ 1,
#' thetant ~ 1)
#'
#' # simulate data
#' dat <- gen_3p_data(N = 200)
#' c ~ 1,
#' kappa ~ 1)
#'
#' # fit the model
#' get_model_prior(formula = ff,
#' data = dat,
#' model = mixture3p(non_targets = paste0('nt',1,'_loc'), setsize = 2)
#' model = sdmSimple()
#' )
#' }
#'
Expand Down
203 changes: 0 additions & 203 deletions R/random_data_generation.R

This file was deleted.

31 changes: 14 additions & 17 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,17 @@ responses can come from three different sources - noisy representation of the
target, confusion with noisy representation of non-target items, or guessing
based on a uniform distribution. To estimate these parameters for a dataset, we
can use the `fit_model()` function. First, let's generate a dataset with known
parameters. We can use the function `gen_3p_data()`
parameters. We can use the function `rmixture3p()`

```{r example, message=FALSE, warning=FALSE}
library(bmm)
library(tidyverse)
dat <- gen_3p_data(N=2000, pmem=0.6, pnt=0.3, kappa=10, setsize=4, relative_resp=T)
dat <- data.frame(
y = rmixture3p(n = 2000, mu = c(0,1,-1.5,2)),
nt1_loc = 1,
nt2_loc = -1.5,
nt3_loc = 2
)
head(dat)
```

Expand All @@ -82,19 +87,12 @@ tails:
hist(dat$y, breaks = 60, xlab = "Response error relative to target")
```
Another key property of the data is that some error responses are not random,
but that they are due to confusion of the target with one of the lures. We can
visualize this by centering the response error relative to each of the possible
non-target locations. We do this with the helper function
`calc_error_relative_to_nontargets()`:

```{r}
dat %>%
calc_error_relative_to_nontargets('y', paste0('nt',1:3,'_loc')) %>%
ggplot(aes(y_nt)) +
geom_histogram()
```
but that they are due to confusion of the target with one of the lures. This is already
visible by the additional peaks in the histogram. Typically these peaks are not immediately
visible as the non-target locations vary from trial to trial.

Ok, so now let's fit the three-parameter model. We only need to do two things:

- Specify the model formula
- Call fit_model()

Expand All @@ -105,9 +103,9 @@ proportion for correct responses and mixing proportion for non-target swaps.

```{r}
ff <- brms::bf(y ~ 1,
kappa ~ 1,
thetat ~ 1,
thetant ~ 1)
kappa ~ 1,
thetat ~ 1,
thetant ~ 1)
```

Then specify the model and give it information about the required arguments. In
Expand All @@ -134,4 +132,3 @@ fit <- fit_model(formula = ff,
iter=500,
backend='cmdstanr')
```

Loading

0 comments on commit 56f3053

Please sign in to comment.