Skip to content

Commit

Permalink
Revise package for paper
Browse files Browse the repository at this point in the history
  • Loading branch information
Rausch authored and Rausch committed Dec 8, 2024
1 parent 0d3f7d3 commit 5a57214
Show file tree
Hide file tree
Showing 9 changed files with 278 additions and 363 deletions.
41 changes: 0 additions & 41 deletions R/compareBayes.R

This file was deleted.

14 changes: 8 additions & 6 deletions R/estimateMetaI.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#' Meta-\eqn{I} is expressed in bits, i.e. the log base is 2).
#' The other measures are different normalizations of meta-\eqn{I} and are unitless.
#' It should be noted that Dayan (2023) pointed out that a liberal or
#' conservative use of the confidence levels will affected th mutual
#' conservative use of the confidence levels will affected the mutual
#' information and thus influence meta-I.
#'
#' @param data a `data.frame` where each row is one trial, containing following
Expand All @@ -57,11 +57,13 @@
#' (default: TRUE).

#' @return a `data.frame` with one row for each subject and the following
#' columns: `participant` is the participant ID, `meta_I` is the estimated
#' meta-\eqn{I} value (expressed in bits, i.e. log base is
#' 2), `meta_Ir1` is meta-\eqn{I_{1}^{r}}, `meta_Ir1_acc` is meta-\eqn{I_{1}^{r\prime}},
#' `meta_Ir2` is meta-\eqn{I_{2}^{r}}, and RMI is RMI.
#' with , or unitless for the normalized measures)
#' columns:
#' * `participant` is the participant ID,
#' * `meta_I` is the estimated meta-\eqn{I} value (expressed in bits, i.e. log base is 2),
#' * `meta_Ir1` is meta-\eqn{I_{1}^{r}},
#' * `meta_Ir1_acc` is meta-\eqn{I_{1}^{r\prime}},
#' * `meta_Ir2` is meta-\eqn{I_{2}^{r}}, and
#' * `RMI` is RMI.

#' @examples
#' # 1. Select two subjects from the masked orientation discrimination experiment
Expand Down
15 changes: 0 additions & 15 deletions R/fitConfModels.R
Original file line number Diff line number Diff line change
Expand Up @@ -328,21 +328,6 @@ fitConfModels <- function(data, models="all",
# bind list-outout together into data.frame
res <- do.call(rbind, res)

if ("all" %in% models | length(models) > 1){
res$wAIC <- NA
res$wAICc <- NA
res$wBIC <- NA
for (sbj in subjects){
Ls <- exp(-0.5 * (res$AIC[res$participant==sbj] - min(res$AIC[res$participant==sbj])))
res$wAIC[res$participant==sbj] <- Ls / sum(Ls)
Ls <- exp(-0.5 * (res$AICc[res$participant==sbj] - min(res$AICc[res$participant==sbj])))
res$wAICc[res$participant==sbj] <- Ls / sum(Ls)
Ls <- exp(-0.5 * (res$BIC[res$participant==sbj] - min(res$BIC[res$participant==sbj])))
res$wBIC[res$participant==sbj] <- Ls / sum(Ls)
}
}


# finally, drop columns with unnecessary parameters
res <- res[,apply(res, 2, function(X) any(!is.na(X)))]
if (no_sbj_column) res$participant <- NULL
Expand Down
43 changes: 15 additions & 28 deletions R/plotConfModelFit.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' @title Plot the prediction of fitted parameters of one model of confidence over the corresponding real data
#' @title Plot the prediction of fitted parameters of one model of confidence over the corresponding data
#'
#' @description The `plotConfModelFit` function plots the predicted distribution of discrimination responses
#' and confidence ratings created from a `data.frame` of parameters obtaind from \code{\link{fitConfModels}}
Expand All @@ -25,38 +25,25 @@
#' If there is no model column in data or if there are multiple models in fitted_pars,
#' it is necessary to specify the model argument.
#'
#' @param model `character`. See \code{\link{fitConf}} for all available models
#' @param model `character`. See \code{\link{fitConfModels}} for all available models
#'
#' @return a `data.frame` with one row for each combination of model and
#' participant. There are different columns for the model, the participant ID, and one
#' one column for each estimated model parameter (parameters
#' not present in a specific model are filled with NAs)
#' @return a `ggplot` object with empirically observed distribution of responses and confidence ratings
#' as bars on the x-axis as a function of discriminability (in the rows) and stimulus
#' (in the columns). Superimposed on the empirical data,
#' the plot also shows the prediction of one selected model as dots.
#'
#' @examples
#' # 1. Select two subjects from the masked orientation discrimination experiment
#' data <- subset(MaskOri, participant %in% c(1:2))
#' head(data)
#' # 1. Fit some models to each subject of the masked orientation discrimination experiment
#' # Normally, the fits should be created using the function fitConfModels
#' # Fits <- fitConfModels(data, models = "WEV", .parallel = TRUE)
#' # Here, we create a dummy dataframe because fitting models takes about 10 minutes per model fit per participant on a 2.8GHz processor
#'
#' # 2. Fit some models to each subject of the masked orientation discrimination experiment
#' \donttest{
#' # Fitting several models to several subjects takes quite some time
#' # (about 10 minutes per model fit per participant on a 2.8GHz processor
#' # with the default values of nInits and nRestart).
#' # If you want to fit more than just two subjects,
#' # we strongly recommend setting .parallel=TRUE
#' Fits <- fitConfModels(data, models = "ITGc", .parallel = FALSE)
#' }
#' # 3. Plot the predicted probabilies based on model and fitted parameter over the observed relative frequencies.
#'
#' \donttest{
#' # Fitting several models to several subjects takes quite some time
#' # (about 10 minutes per model fit per participant on a 2.8GHz processor
#' # with the default values of nInits and nRestart).
#' # If you want to fit more than just two subjects,
#' # we strongly recommend setting .parallel=TRUE
#' myPlottedFit <- plotConfModelFit(data, Fits)
#' myPlottedFit
#' }
#' # 2. Plot the predicted probabilies based on model and fitted parameter over the observed relative frequencies.
#'
#' PlotFitWEV <- plotConfModelFit(MaskOri, fitted_pars, model="WEV")
#' PlotFitWEV
#'
#' @import ggplot2
#' @importFrom plyr ddply summarise
#' @importFrom Rmisc summarySEwithin
Expand Down
Loading

0 comments on commit 5a57214

Please sign in to comment.