Skip to content

Commit

Permalink
Update to version 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
giorgiopaulon committed Jan 27, 2023
1 parent 2a59ca7 commit 25b64e1
Show file tree
Hide file tree
Showing 19 changed files with 66 additions and 64 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
Package: lddmm
Type: Package
Title: Longitudinal Drift-Diffusion Mixed Models (LDDMM)
Version: 0.1.0.9000
Date: 2021-11-02
Version: 0.2.0
Date: 2023-01-27
Authors@R: c(person("Giorgio", "Paulon", email = "giorgio.paulon@utexas.edu",
role = c("aut", "cre")),
person("Abhra", "Sarkar", email = "abhra.sarkar@utexas.edu",
role = c("aut", "ctb")))
Description: Implementation of the drift-diffusion mixed model for category learning as described in Paulon et al. (2021) <https://doi.org/10.1080/01621459.2020.1801448>.
Description: Implementation of the drift-diffusion mixed model for category learning as described in Paulon et al. (2021) <doi:10.1080/01621459.2020.1801448>.
Depends: R (>= 3.5.0)
Language: en-US
License: MIT + file LICENSE
Encoding: UTF-8
Imports: Rcpp (>= 1.0.6), RcppProgress, rgen, gtools, LaplacesDemon, dplyr, plyr, tidyr, ggplot2, latex2exp, reshape2, RColorBrewer
LazyData: true
LinkingTo: Rcpp, RcppArmadillo, RcppProgress, rgen
RoxygenNote: 7.1.2
RoxygenNote: 7.2.3
Roxygen: list(markdown = TRUE)
Suggests:
rmarkdown,
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
YEAR: 2021
YEAR: 2022
COPYRIGHT HOLDER: Giorgio Paulon
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License

Copyright (c) 2021 Giorgio Paulon
Copyright (c) 2022 Giorgio Paulon

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 4 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
useDynLib(lddmm, .registration=TRUE)
importFrom(Rcpp, evalCpp)
# Generated by roxygen2: do not edit by hand

importFrom(Rcpp,sourceCpp)
useDynLib(lddmm, .registration = TRUE)
importFrom("stats", "dgamma", "rnorm", "runif", "sd", "setNames",
"quantile")
importFrom("utils", "data", "setTxtProgressBar", "txtProgressBar")
Expand Down
5 changes: 4 additions & 1 deletion News.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

## Major changes

* Now the boundary parameter in the model can either be unrestricted (`boundaries = "flexible"`), constant over time (`boundaries = "constant"`) or fixed at the same value across predictors (`boundaries = "fixed"`).

## Minor changes

* Added the DOI for the article reference
* Clarified that response times should be the log transformed of time (in milliseconds) for numerical stability.

## Bug fixes


# LDDMM 0.1.0

* First version
* First version
54 changes: 20 additions & 34 deletions R/fcts.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require(mvtnorm)
require(gtools)
require(ggplot2)
require(latex2exp)
library(RColorBrewer)
require(RColorBrewer)
require(LaplacesDemon)
require(plyr)

Expand All @@ -21,7 +21,7 @@ require(plyr)
#' * block: vector of size n containing the training blocks (longitudinal units)
#' * s: vector of size n containing the stimuli
#' * d: vector of size n containing the decisions
#' * r_time: vector of size n containing the response times
#' * r_time: vector of size n containing the log transformed of the response times (in milliseconds)
#' * cens: vector of size n containing the censoring indicators (1 censored, 0 non censored)
#' @return Individual and population level raw accuracies
plot_accuracy <- function(data){
Expand Down Expand Up @@ -69,7 +69,7 @@ plot_accuracy <- function(data){
#' * block: vector of size n containing the training blocks (longitudinal units)
#' * s: vector of size n containing the stimuli
#' * d: vector of size n containing the decisions
#' * r_time: vector of size n containing the response times
#' * r_time: vector of size n containing the log transformed of the response times (in milliseconds)
#' * cens: vector of size n containing the censoring indicators (1 censored, 0 non censored)
#' @return Population level raw response times
plot_RT <- function(data){
Expand Down Expand Up @@ -294,11 +294,13 @@ sample_smooth_var <- function(sigma2_ua_old, sigma2_us_old,
#' * block: vector of size n containing the training blocks (longitudinal units)
#' * s: vector of size n containing the stimuli
#' * d: vector of size n containing the decisions
#' * r_time: vector of size n containing the response times
#' * r_time: vector of size n containing the log transformed of the response times (in milliseconds)
#' * cens: vector of size n containing the censoring indicators (1 censored, 0 non censored)
#' @param hypers hyperparameters of the MCMC: list containing "s_sigma_mu" and "s_sigma_b",
#' which are the smoothness parameters for drifts and boundaries, respectively)
#' @param fix_boundary whether to fix the boundary parameters to a single scalar or not
#' @param boundaries whether to fit the unrestricted model (flexible), assume constant
#' boundaries over time (constant) or fix the boundaries to the same level
#' across predictors (fixed)
#' @param Niter total number of iterations
#' @param burnin burnin of the chain
#' @param thin thinning factor
Expand All @@ -319,7 +321,7 @@ sample_smooth_var <- function(sigma2_ua_old, sigma2_us_old,
#' * pred_time: predicted population-level response times
#' * pred_ans_ind: predicted individual-level categories
#' * pred_time_ind: predicted individual-level response times
LDDMM <- function(data, hypers, fix_boundary = FALSE,
LDDMM <- function(data, hypers, boundaries = 'flexible',
Niter = 5000, burnin = 2000, thin = 5){

# Check for data issues
Expand All @@ -337,12 +339,18 @@ LDDMM <- function(data, hypers, fix_boundary = FALSE,
}

# Call one of the main functions
if (!fix_boundary){
if (boundaries == 'flexible'){
fit <- LDDMM_full(data, hypers, Niter, burnin, thin)
}
else {
else if (boundaries == 'constant') {
fit <- LDDMM_fix_bound(data, hypers, Niter, burnin, thin)
}
else if (boundaries == 'fixed') {
fit <- LDDMM_fix_all_bound(data, hypers, Niter, burnin, thin)
}
else {
stop("The argument boundaries can be only one of the following: flexible, constant, or fixed")
}

return (fit)
}
Expand Down Expand Up @@ -1550,29 +1558,7 @@ LDDMM_fix_bound <- function(data, hypers, Niter = 5000, burnin = 2000, thin = 5)
}
}

# 2(a) Update the single scalar boundary parameter
# b_prop <- rnorm(1, b_old, sd_MH_beta_b)
#
# # Modify the proposed values in the corresponding positions
# B_beta_b_prop_dat <- matrix(b_prop, n, d_j[1])
#
# # This is the proposed value for b
# b_prop_dat <- exp(B_beta_b_prop_dat)
#
# logpost_prop <- log_likelihood(tau, mu_dat,
# b_prop_dat, delta_dat,
# cens, D, TRUE)
# logpost_old <- log_likelihood(tau, mu_dat,
# b_dat, delta_dat,
# cens, D, TRUE)
#
# alpha_acc <- min(0, logpost_prop - logpost_old)
# l_u <- log(runif(1))
#
# if (l_u < alpha_acc){
# b_old <- b_prop
# b_dat <- b_prop_dat
# }
# 2(a) Update the constant boundary parameters
for (d1 in 1:d_j[1]){
idx_i <- which( (D[,1] == d1) )
tau_temp <- tau[idx_i]
Expand Down Expand Up @@ -2700,7 +2686,7 @@ LDDMM_fix_all_bound <- function(data, hypers, Niter = 5000, burnin = 2000, thin
#' * block: vector of size n containing the training blocks (longitudinal units)
#' * s: vector of size n containing the stimuli
#' * d: vector of size n containing the decisions
#' * r_time: vector of size n containing the response times
#' * r_time: vector of size n containing the log transformed of the response times (in milliseconds)
#' * cens: vector of size n containing the censoring indicators (1 censored, 0 non censored)
#' @param fit fit from the lddmm function
#' @param par parameter to output ('drift', or 'boundary')
Expand Down Expand Up @@ -2744,7 +2730,7 @@ extract_post_mean = function(data, fit, par = c('drift', 'boundary')){
#' * block: vector of size n containing the training blocks (longitudinal units)
#' * s: vector of size n containing the stimuli
#' * d: vector of size n containing the decisions
#' * r_time: vector of size n containing the response times
#' * r_time: vector of size n containing the log transformed of the response times (in milliseconds)
#' * cens: vector of size n containing the censoring indicators (1 censored, 0 non censored)
#' @param fit fit from the lddmm function
#' @param par parameter to output ('drift', or 'boundary')
Expand Down Expand Up @@ -2790,7 +2776,7 @@ extract_post_draws = function(data, fit, par = c('drift', 'boundary')){
#' * block: vector of size n containing the training blocks (longitudinal units)
#' * s: vector of size n containing the stimuli
#' * d: vector of size n containing the decisions
#' * r_time: vector of size n containing the response times
#' * r_time: vector of size n containing the log transformed of the response times (in milliseconds)
#' * cens: vector of size n containing the censoring indicators (1 censored, 0 non censored)
#' @param fit fit from the lddmm function
#' @param par parameter to output ('drift', or 'boundary')
Expand Down
8 changes: 5 additions & 3 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ knitr::opts_chunk$set(

# LDDMM

An R package for Longitudinal Drift-Diffusion Mixed Models (LDDMM), v0.1.
An R package for Longitudinal Drift-Diffusion Mixed Models (LDDMM), v0.2.0.

**Authors**: [Giorgio Paulon](https://giorgiopaulon.github.io/), [Abhra Sarkar](https://abhrastat.github.io/)

Expand Down Expand Up @@ -47,6 +47,7 @@ If you are using a Windows machine, you might have to also install and configure
### Usage

The following is a minimal example of a simple model fit.
For numerical stability, the response times should be provided as the log transform of time (in milliseconds) so that, for most applications, typical values lie in $[0, 10]$.

```{r, eval = TRUE, results = 'hide', fig.show = 'hide', warning = FALSE, message = FALSE}
# Load libraries
Expand Down Expand Up @@ -81,7 +82,6 @@ samp_size <- (Niter - burnin) / thin
set.seed(123)
fit <- LDDMM(data = data,
hypers = hypers,
fix_boundary = FALSE,
Niter = Niter,
burnin = burnin,
thin = thin)
Expand All @@ -91,8 +91,10 @@ plot_post_pars(data, fit, par = 'drift')
plot_post_pars(data, fit, par = 'boundary')
```


To extract relevant posterior draws or posterior summaries instead of simply plotting them, one can use the functions `extract_post_mean` or `extract_post_draws`.
An auxiliary function that fixes the boundary parameters can be called with the option `fix_boundary = TRUE`.
Auxiliary functions that assume constant boundary parameters over time or fix the boundaries to the same level across predictors can be called with the options `boundaries = "constant"` and `boundaries = "fixed"`, respectively.


### Questions or bugs

Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# LDDMM

An R package for Longitudinal Drift-Diffusion Mixed Models (LDDMM),
v0.1.
v0.2.0.

**Authors**: [Giorgio Paulon](https://giorgiopaulon.github.io/), [Abhra
Sarkar](https://abhrastat.github.io/)
Expand Down Expand Up @@ -58,6 +58,7 @@ configure `Rtools` using the following
### Usage

The following is a minimal example of a simple model fit.
For numerical stability, the response times should be provided as the log transform of time (in milliseconds) so that, for most applications, typical values lie in $[0, 10]$.

``` r
# Load libraries
Expand Down Expand Up @@ -92,7 +93,6 @@ samp_size <- (Niter - burnin) / thin
set.seed(123)
fit <- LDDMM(data = data,
hypers = hypers,
fix_boundary = FALSE,
Niter = Niter,
burnin = burnin,
thin = thin)
Expand All @@ -104,8 +104,12 @@ plot_post_pars(data, fit, par = 'boundary')

To extract relevant posterior draws or posterior summaries instead of
simply plotting them, one can use the functions `extract_post_mean` or
`extract_post_draws`. An auxiliary function that fixes the boundary
parameters can be called with the option `fix_boundary = TRUE`.
`extract_post_draws`. Auxiliary functions that assume constant boundary
parameters over time or fix the boundaries to the same level across predictors
can be called with the options `boundaries = "constant"` and
`boundaries = "fixed"`, respectively.



### Questions or bugs

Expand Down
12 changes: 8 additions & 4 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@

## R CMD check results

── R CMD check results ────────────────────────────────────────────────────────────────────────────────────────────── lddmm 0.1.0 ────
Duration: 1m 7.1s
── R CMD check results ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────── lddmm 0.2.0.9000 ────
Duration: 1m 15.7s

❯ checking dependencies in R code ... NOTE
Namespaces in Imports field not imported from:
‘RColorBrewer’ ‘RcppProgress’ ‘rgen’
All declared Imports should be used.

0 errors | 0 warnings | 0 notes ✓
0 errors | 0 warnings | 1 note ✖

R CMD check succeeded

Expand Down
8 changes: 5 additions & 3 deletions man/LDDMM.Rd

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

2 changes: 1 addition & 1 deletion man/extract_post_draws.Rd

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

2 changes: 1 addition & 1 deletion man/extract_post_mean.Rd

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

2 changes: 1 addition & 1 deletion man/plot_RT.Rd

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

2 changes: 1 addition & 1 deletion man/plot_accuracy.Rd

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

2 changes: 1 addition & 1 deletion man/plot_post_pars.Rd

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

Binary file modified src/RcppExports.o
Binary file not shown.
Binary file modified src/drift_diff_fcts.o
Binary file not shown.
Binary file modified src/lddmm.so
Binary file not shown.
3 changes: 1 addition & 2 deletions vignettes/minimal_example.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ samp_size <- (Niter - burnin) / thin
set.seed(123)
fit <- LDDMM(data = data,
hypers = hypers,
fix_boundary = FALSE,
Niter = Niter,
burnin = burnin,
thin = thin)
Expand All @@ -63,4 +62,4 @@ plot_post_pars(data, fit, par = 'boundary')
```

To extract relevant posterior draws or posterior summaries instead of simply plotting them, one can use the functions `extract_post_mean` or `extract_post_draws`.
An auxiliary function that fixes the boundary parameters can be called with the option `fix_boundary = TRUE`.
Auxiliary functions that assume constant boundary parameters over time or fix the boundaries to the same level across predictors can be called with the options `boundaries = "constant"` and `boundaries = "fixed"`, respectively.

0 comments on commit 25b64e1

Please sign in to comment.