diff --git a/DESCRIPTION b/DESCRIPTION
index 9a2c9657..b77bd240 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -33,7 +33,6 @@ Imports:
dplyr,
withr,
tidyr,
- circular,
stats,
matrixStats,
methods
diff --git a/NAMESPACE b/NAMESPACE
index ebc3ec4f..1c978211 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -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)
diff --git a/R/bmm_model_mixture2p.R b/R/bmm_model_mixture2p.R
index 6d1d48b0..9ce600fd 100644
--- a/R/bmm_model_mixture2p.R
+++ b/R/bmm_model_mixture2p.R
@@ -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,
diff --git a/R/bmm_model_mixture3p.R b/R/bmm_model_mixture3p.R
index 677e1acd..63fe7bf0 100644
--- a/R/bmm_model_mixture3p.R
+++ b/R/bmm_model_mixture3p.R
@@ -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,
@@ -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
diff --git a/R/fit_model.R b/R/fit_model.R
index 56a91be1..7fd471fc 100644
--- a/R/fit_model.R
+++ b/R/fit_model.R
@@ -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')
diff --git a/R/get_model_prior.R b/R/get_model_prior.R
index 80bc05c6..fa5ecfe2 100644
--- a/R/get_model_prior.R
+++ b/R/get_model_prior.R
@@ -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()
#' )
#' }
#'
diff --git a/R/random_data_generation.R b/R/random_data_generation.R
deleted file mode 100644
index 8e5c1e7d..00000000
--- a/R/random_data_generation.R
+++ /dev/null
@@ -1,203 +0,0 @@
-#' @title Generate artificial data from the Bays et al (2009) 3-parameter
-#' mixture model
-#' @description Given a set of parameters, and desired setsize, it generates
-#' responses in a continuous reproduction task, with corresponding proportions
-#' coming from memory, non-target location errors, or guessing.
-#'
-#' @param N Numeric. Number of samples
-#' @param pmem Numeric. Probability of response coming from memory
-#' @param pnt Numeric. Probability of response coming from a non-target item
-#' @param kappa Numeric. Precision of the von mises distribution
-#' @param setsize Numeric. Number of presented items
-#' @param relative_resp Logical. if TRUE, returns response error relative to the
-#' target and all non-target item locations are coded relative to the target.
-#' If FALSE, returns actual response and the location of all items is absolute
-#' @keywords simulation
-#'
-#' @return A data.frame object. y is the response (if relative_resp==F) or
-#' response error (if relative_resp==T), t_loc is the value of the target
-#' (only if relative_resp==F), nt1_loc to nti_loc, are values of the
-#' non-targets, where i=setsize-1.
-#'
-#' @export
-#'
-#' @examples
-#' # example code
-#' nsub = 30
-#' df_3p_parms <- data.frame(
-#' theta_pmem = rnorm(nsub, mean = 2, sd = 1),
-#' theta_pnt = rnorm(nsub, mean = 1, sd = 0.5),
-#' kappa = pmax(0,rnorm(nsub, mean = 5, sd = 1)),
-#' pmem = numeric(nsub),
-#' pnt = numeric(nsub),
-#' pguess = numeric(nsub)
-#' )
-#'
-#' # transform continous mixture weights into probabilities using the softmax
-#' df_3p_parms[,c("pmem","pnt","pguess")] <- apply(df_3p_parms[,c("theta_pmem","theta_pnt")],
-#' 1,softmax)
-#'
-gen_3p_data <- function(N=2000, pmem=0.6, pnt=0.3, kappa=10, setsize=2, relative_resp=T) {
- t_loc <- NULL
- resample <- function(x, ...) x[sample.int(length(x), ...)]
-
- # set parameters
- pguess = 1-pmem-pnt # probability of guessing
-
- # uniformly distributed locations on the circle
- locations <- matrix(0, nrow = N, ncol = setsize)
- for (i in 1:setsize) {
- locations[,i] <- brms::rvon_mises(N, 0, 0)
- }
-
- idx_t <- 1:(round(pmem*N)) # which responses are target based
- target_resp <- brms::rvon_mises(round(pmem*N), # vector of target reponses
- locations[idx_t,1],
- kappa)
- if (pnt > 0) {
- Npnt <- round(pnt*N)
- idx_nt <- (round(pmem*N)+1):(round(pmem*N)+Npnt) # which responses are non-target
- idx_loc <- resample(2:setsize, Npnt, replace=T) # which lure generated the response
- idx_select <- cbind(idx_nt, idx_loc)
- nontarget_resp <- brms::rvon_mises(round(pnt*N), # vector of nontarget responses
- locations[idx_select],
- kappa)
- } else {
- nontarget_resp <- c()
- }
-
- if (pguess > 0) {
- guess_resp <- brms::rvon_mises(N-round(pmem*N)-round(pnt*N), 0, 0) # vector of guessing responses
- } else {
- guess_resp <- c()
- }
-
- # put the data together in a data.frame
- dat <- data.frame(y = c(target_resp, nontarget_resp, guess_resp))
- dat <- do.call(cbind, list(dat, as.data.frame(locations)))
- names(dat) <- c('y','t_loc', paste0('nt',1:(setsize-1),'_loc'))
-
-
- # if a relative response is requested
- # recode responses such that the response is the error relative to the target
- # also recode nt_loc, such that it is relative to the target as well
- if (relative_resp) {
- dat <- bmm::wrap(dat-dat$t_loc)
- dat <- dplyr::select(dat, -t_loc)
- }
- return(dat)
-}
-
-#' @title Generate artificial data from the Interference measurement model
-#' @description Given a set of parameters, and desired setsize, this function generates
-#' data following the assumptions of the interference measurement models
-#'
-#' @param parms Matrix/DataFrame. Matrix or Data frame of IMM parameters,
-#' must contain at least one row of values for:
-#' c = context activation,
-#' a = general activation,
-#' s = spatial similarity gradient,
-#' n = background noise,
-#' kappa = precision of memory representations
-#' @param ntrials Numeric. number of responses to simulate for each subject
-#' @param setsize Numeric. Number of items in memory set
-#' @keywords simulation
-#'
-#' @return A data.frame object. resp is the response, respErr is the relative
-#' response to the target, Item1 to ItemN is the absolute location of the
-#' N items from -pi to pi for the number of items N specified by the setsize
-#' variable, D1 to DN is the spatial distance of the N items for the N items
-#' specified by the setsize variable
-#'
-#' @export
-gen_imm_data <- function(parms,
- ntrials = 200, setsize=6){
- # pre-allocate & collect variables for the data simulation
- nsubj <- nrow(parms) # number of subject
-
- # pre-allocate activation matrix
- acts <- matrix(0, 1, setsize + 1)
-
- # switch off warnings -> rvonmises function throws a lot of information when
- # generating random responses
- options(warn = -1)
-
- # pre-allocate data frame for collecting all simulated data
- simData <- data.frame(
- ID = integer(), trial = integer(), setsize = integer(),
- resp = numeric(), respErr = numeric(),
- c = numeric(), a = numeric(), s = numeric(), n = numeric(), kappa = numeric()
- )
- names <- colnames(simData)
-
- # pre-allocate item location & spatial distance variable
- for (s in 1:(2*setsize)) {
- simData[,ncol(simData) + 1] <- numeric()
- }
-
- # update column names
- newNames <- c(names,paste0("Item",1:setsize,"_abs"),paste0("spaD",1:setsize))
- colnames(simData) <- newNames
-
- # Loop through all subject
- for (idx in 1:nsubj) {
- x <- NULL
- dev <- NaN
-
- memset <- matrix(0, ntrials, setsize)
- colnames(memset) <- paste0("Item",1:setsize,"_abs")
-
- D <- matrix(0, ntrials, setsize)
- colnames(D) <- paste0("spaD",1:setsize)
-
- # Loop through all trials
- for (trial in 1:ntrials) {
- # generate random memory set & distances for each trial
- memset[trial,1:setsize] <- bmm::wrap(circular::rvonmises(setsize, 0, 0, control.circular = list(units = "radians"))) # draw items from uniform
- D[trial,2:setsize] <- stats::runif(setsize - 1, 0.5, pi) # draw distances of non-targets from uniform range 0.5 to pi
-
- # compute activation for all items + random guessing
- acts[1:setsize] <- parms[idx,"a"] + exp(-parms[idx,"s"]*D[trial,]) * parms[idx,"c"]
- acts[setsize + 1] <- parms[idx,"n"]
-
- # convert activations into probabilities
- P <- exp(acts)/sum(exp(acts))
-
- # randomly select from which distribution the response will come from
- cumP <- cumsum(P)
- draw <- stats::runif(1,0,1)
- aa <- draw < cumP
- choice <- min(which(aa == TRUE))
-
- # draw response dependent on choice
- if (choice <= setsize) x[trial] <- bmm::wrap(circular::rvonmises(1, memset[trial,choice], parms[idx,"kappa"])) # response from a memory distribution
- if (choice > setsize) x[trial] <- bmm::wrap(circular::rvonmises(1, 0, 0)) # response from noise distribution
-
- # compute response error as the deviation of the response from the target item
- dev[trial] = bmm::wrap(x[trial] - memset[trial,1])
- }
-
- # collect subject data
- subData <- data.frame(ID = idx, setsize = setsize, trial = 1:ntrials, resp = x, respErr = dev,
- c = parms[idx,"c"], a = parms[idx,"a"], n = parms[idx, "n"],
- s = parms[idx, "s"], kappa = parms[idx,"kappa"])
-
- # bind all subject data together
- subData <- cbind(subData,memset,D)
-
- # bind subject data to full data set
- simData <- rbind(simData,subData)
- }
-
- # switch warnings back on
- options(warn = 0)
-
- # add relative locations to the simulated data
- locData <- simData[,grepl("Item",colnames(simData))]
- relLocData <- bmm::wrap(locData - locData$Item1_abs)
- colnames(relLocData) <- paste0("Item",1:setsize,"_rel")
- simData <- cbind(simData,relLocData)
-
- # return the simulated data
- return(simData)
-}
diff --git a/README.Rmd b/README.Rmd
index 93c84bf7..3fabd483 100644
--- a/README.Rmd
+++ b/README.Rmd
@@ -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)
```
@@ -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()
@@ -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
@@ -134,4 +132,3 @@ fit <- fit_model(formula = ff,
iter=500,
backend='cmdstanr')
```
-
diff --git a/README.md b/README.md
index 4005f931..27df3897 100644
--- a/README.md
+++ b/README.md
@@ -78,15 +78,20 @@ let’s generate a dataset with known parameters. We can use the function
``` r
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)
-#> y nt1_loc nt2_loc nt3_loc
-#> 1 0.51775824 1.0020511 0.76339413 -1.2897954
-#> 2 0.03960327 -0.6206519 1.09208784 -0.8679937
-#> 3 -0.48213423 1.1447270 2.81885045 -1.4363374
-#> 4 -0.34510101 2.7482095 -0.06612305 2.0340003
-#> 5 0.09348744 -1.3952246 2.17738363 0.7796131
-#> 6 0.39001975 -0.8049496 2.07371921 -1.1887811
+#> y nt1_loc nt2_loc nt3_loc
+#> 1 -0.21935776 1 -1.5 2
+#> 2 -0.09542148 1 -1.5 2
+#> 3 -0.46152746 1 -1.5 2
+#> 4 2.20892562 1 -1.5 2
+#> 5 -0.52996268 1 -1.5 2
+#> 6 -0.47483031 1 -1.5 2
```
We have a dataset of 2000 observations of response error, of which 60%
@@ -108,22 +113,15 @@ 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()
-#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
-```
-
-
+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()
+things:
+
+- Specify the model formula
+- Call fit_model()
In this example the parameters don’t vary over conditions, so we have no
predictors. `y` is the name of the response error variable, whereas
@@ -133,9 +131,9 @@ 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
diff --git a/man/figures/README-unnamed-chunk-4-1.png b/man/figures/README-unnamed-chunk-4-1.png
index 688ac204..72dd9d83 100644
Binary files a/man/figures/README-unnamed-chunk-4-1.png and b/man/figures/README-unnamed-chunk-4-1.png differ
diff --git a/man/fit_model.Rd b/man/fit_model.Rd
index 2fb8adba..56b0a9c7 100644
--- a/man/fit_model.Rd
+++ b/man/fit_model.Rd
@@ -73,18 +73,17 @@ Type \code{help(package=bmm)} for a full list of available help topics.
\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')
diff --git a/man/gen_3p_data.Rd b/man/gen_3p_data.Rd
deleted file mode 100644
index abd45b41..00000000
--- a/man/gen_3p_data.Rd
+++ /dev/null
@@ -1,60 +0,0 @@
-% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/random_data_generation.R
-\name{gen_3p_data}
-\alias{gen_3p_data}
-\title{Generate artificial data from the Bays et al (2009) 3-parameter
-mixture model}
-\usage{
-gen_3p_data(
- N = 2000,
- pmem = 0.6,
- pnt = 0.3,
- kappa = 10,
- setsize = 2,
- relative_resp = T
-)
-}
-\arguments{
-\item{N}{Numeric. Number of samples}
-
-\item{pmem}{Numeric. Probability of response coming from memory}
-
-\item{pnt}{Numeric. Probability of response coming from a non-target item}
-
-\item{kappa}{Numeric. Precision of the von mises distribution}
-
-\item{setsize}{Numeric. Number of presented items}
-
-\item{relative_resp}{Logical. if TRUE, returns response error relative to the
-target and all non-target item locations are coded relative to the target.
-If FALSE, returns actual response and the location of all items is absolute}
-}
-\value{
-A data.frame object. y is the response (if relative_resp==F) or
-response error (if relative_resp==T), t_loc is the value of the target
-(only if relative_resp==F), nt1_loc to nti_loc, are values of the
-non-targets, where i=setsize-1.
-}
-\description{
-Given a set of parameters, and desired setsize, it generates
-responses in a continuous reproduction task, with corresponding proportions
-coming from memory, non-target location errors, or guessing.
-}
-\examples{
-# example code
-nsub = 30
-df_3p_parms <- data.frame(
- theta_pmem = rnorm(nsub, mean = 2, sd = 1),
- theta_pnt = rnorm(nsub, mean = 1, sd = 0.5),
- kappa = pmax(0,rnorm(nsub, mean = 5, sd = 1)),
- pmem = numeric(nsub),
- pnt = numeric(nsub),
- pguess = numeric(nsub)
-)
-
-# transform continous mixture weights into probabilities using the softmax
-df_3p_parms[,c("pmem","pnt","pguess")] <- apply(df_3p_parms[,c("theta_pmem","theta_pnt")],
- 1,softmax)
-
-}
-\keyword{simulation}
diff --git a/man/gen_imm_data.Rd b/man/gen_imm_data.Rd
deleted file mode 100644
index c9ffe007..00000000
--- a/man/gen_imm_data.Rd
+++ /dev/null
@@ -1,33 +0,0 @@
-% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/random_data_generation.R
-\name{gen_imm_data}
-\alias{gen_imm_data}
-\title{Generate artificial data from the Interference measurement model}
-\usage{
-gen_imm_data(parms, ntrials = 200, setsize = 6)
-}
-\arguments{
-\item{parms}{Matrix/DataFrame. Matrix or Data frame of IMM parameters,
-must contain at least one row of values for:
-c = context activation,
-a = general activation,
-s = spatial similarity gradient,
-n = background noise,
-kappa = precision of memory representations}
-
-\item{ntrials}{Numeric. number of responses to simulate for each subject}
-
-\item{setsize}{Numeric. Number of items in memory set}
-}
-\value{
-A data.frame object. resp is the response, respErr is the relative
-response to the target, Item1 to ItemN is the absolute location of the
-N items from -pi to pi for the number of items N specified by the setsize
-variable, D1 to DN is the spatial distance of the N items for the N items
-specified by the setsize variable
-}
-\description{
-Given a set of parameters, and desired setsize, this function generates
-data following the assumptions of the interference measurement models
-}
-\keyword{simulation}
diff --git a/man/get_model_prior.Rd b/man/get_model_prior.Rd
index db90c056..de52152b 100644
--- a/man/get_model_prior.Rd
+++ b/man/get_model_prior.Rd
@@ -54,22 +54,18 @@ Type \code{help(package=bmm)} for a full list of available help topics.
}
\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()
)
}
diff --git a/man/mixture2p.Rd b/man/mixture2p.Rd
index 0c3edf53..0ac5b177 100644
--- a/man/mixture2p.Rd
+++ b/man/mixture2p.Rd
@@ -38,7 +38,7 @@ Two-parameter mixture model by Zhang and Luck (2008).
\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,
diff --git a/man/mixture3p.Rd b/man/mixture3p.Rd
index 696ac5c1..5155c5d2 100644
--- a/man/mixture3p.Rd
+++ b/man/mixture3p.Rd
@@ -48,7 +48,12 @@ Three-parameter mixture model by Bays et al (2009).
\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,
@@ -57,14 +62,14 @@ ff <- brms::bf(y ~ 1,
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')
}
}
diff --git a/tests/testthat/test-fit_model.R b/tests/testthat/test-fit_model.R
index 5fe6767a..f80a26f3 100644
--- a/tests/testthat/test-fit_model.R
+++ b/tests/testthat/test-fit_model.R
@@ -1,7 +1,12 @@
test_that('Available mock models run without errors',{
skip_on_cran()
- dat <- gen_imm_data(parms = data.frame(c=2,a=0.5,n=0,s=2,kappa=5),
- ntrial = 2, setsize = 5)
+ dat <- data.frame(
+ respErr = rIMM(n = 5),
+ Item2_rel = 2,
+ Item3_rel = -1.5,
+ spaD2 = 0.5,
+ spaD3 = 2
+ )
# two-parameter model mock fit
f <- brms::bf(respErr ~ 1, kappa ~ 1, thetat ~ 1)
@@ -10,10 +15,10 @@ test_that('Available mock models run without errors',{
expect_type(mock_fit$fit_args, "list")
expect_equal(names(mock_fit$fit_args[1:4]), c("formula", "data", "family", "prior"))
-
# three-parameter model mock fit
f <- brms::bf(respErr ~ 1, kappa ~ 1, thetat ~ 1, thetant ~ 1)
- mock_fit <- fit_model(f, dat, mixture3p(setsize=5, non_targets = paste0('Item',2:5,'_rel')),
+ mock_fit <- fit_model(f, dat, mixture3p(setsize = 3,
+ non_targets = paste0('Item',2:3,'_rel')),
backend="mock", mock_fit=1, rename=FALSE)
expect_equal(mock_fit$fit, 1)
expect_type(mock_fit$fit_args, "list")
@@ -21,7 +26,8 @@ test_that('Available mock models run without errors',{
# IMMabc model mock fit
f <- brms::bf(respErr ~ 1, kappa ~ 1, c ~ 1, a ~ 1)
- mock_fit <- fit_model(f, dat, IMMabc(setsize=5, non_targets = paste0('Item',2:5,'_rel')),
+ mock_fit <- fit_model(f, dat, IMMabc(setsize =3,
+ non_targets = paste0('Item',2:3,'_rel')),
backend="mock", mock_fit=1, rename=FALSE)
expect_equal(mock_fit$fit, 1)
expect_type(mock_fit$fit_args, "list")
@@ -29,7 +35,7 @@ test_that('Available mock models run without errors',{
# IMMbsc model mock fit
f <- brms::bf(respErr ~ 1, kappa ~ 1, c ~ 1, s ~ 1)
- mock_fit <- fit_model(f, dat, IMMbsc(setsize=5, non_targets = paste0('Item',2:5,'_rel'), spaPos=paste0('spaD',2:5)),
+ mock_fit <- fit_model(f, dat, IMMbsc(setsize=3, non_targets = paste0('Item',2:3,'_rel'), spaPos=paste0('spaD',2:3)),
backend="mock", mock_fit=1, rename=FALSE)
expect_equal(mock_fit$fit, 1)
expect_type(mock_fit$fit_args, "list")
@@ -37,7 +43,7 @@ test_that('Available mock models run without errors',{
# IMMbsc model mock fit
f <- brms::bf(respErr ~ 1, kappa ~ 1, c ~ 1, a ~ 1, s ~ 1)
- mock_fit <- fit_model(f, dat, IMMfull(setsize=5, non_targets = paste0('Item',2:5,'_rel'), spaPos=paste0('spaD',2:5)), backend="mock", mock_fit=1, rename=FALSE)
+ mock_fit <- fit_model(f, dat, IMMfull(setsize=3, non_targets = paste0('Item',2:3,'_rel'), spaPos=paste0('spaD',2:3)), backend="mock", mock_fit=1, rename=FALSE)
expect_equal(mock_fit$fit, 1)
expect_type(mock_fit$fit_args, "list")
expect_equal(names(mock_fit$fit_args[1:4]), c("formula", "data", "family", "prior"))
@@ -45,8 +51,13 @@ test_that('Available mock models run without errors',{
test_that('Available models produce expected errors', {
skip_on_cran()
- dat <- gen_imm_data(parms = data.frame(c=2,a=0.5,n=0,s=2,kappa=5),
- ntrial = 100, setsize = 5)
+ dat <- data.frame(
+ respErr = rIMM(n = 5),
+ Item2_rel = 2,
+ Item3_rel = -1.5,
+ spaD2 = 0.5,
+ spaD3 = 2
+ )
# Missing data
okmodels <- supported_models(print_call=FALSE)
@@ -73,4 +84,3 @@ test_that('Available models produce expected errors', {
}
})
-
diff --git a/tests/testthat/test-get_model_prior.R b/tests/testthat/test-get_model_prior.R
index 9b6e446e..45d35a1c 100644
--- a/tests/testthat/test-get_model_prior.R
+++ b/tests/testthat/test-get_model_prior.R
@@ -1,7 +1,4 @@
test_that("get_model_prior() returns a brmsprior object", {
- # generate artificial data from the Bays et al (2009) 3-parameter mixture model
- dat <- gen_3p_data(N=2, pmem=0.6, pnt=0.3, kappa=10, setsize=4, relative_resp=T)
-
# define formula
ff <- brms::bf(y ~ 1,
kappa ~ 1,
@@ -9,7 +6,9 @@ test_that("get_model_prior() returns a brmsprior object", {
thetant ~ 1)
# simulate data
- dat <- gen_3p_data(N = 200)
+ dat <- data.frame(y = rmixture3p(n = 200),
+ nt1_loc = 2,
+ nt2_loc = -1.5)
# fit the model
prior <- get_model_prior(formula = ff,