knitr::opts_chunk$set(
  collapse = TRUE
  , comment = "#>"
  , warning = FALSE
  , message = FALSE
)

Example 2: Smith et al. (2011)

# load packages:
library("MPTmultiverse")


# Make sure that working directory is correct via either:
# - setwd() / getwd()
# - Rstudio->Sessions->Set Working Directory->'To Source File Location'

# If you're running the analysis from an .rmd file, you only need to ensure that
# the .rmd, .eqn, and .csv files are all in the same directory.


# ------------------------------------------------------------------------------
# MPT model definition & Data

EQN_FILE <- "prospective_memory.eqn"
DATA_FILE <- "smith_et_al_2011.csv"


### if .csv format uses semicolons ";" (German format):
# data <- read.csv2(DATA_FILE, fileEncoding = "UTF-8-BOM")
### if .csv format uses commata "," (international format):
data <- read.csv(DATA_FILE, fileEncoding = "UTF-8-BOM")

head(data)
TreeBUGS::plotFreq(data, boxplot = FALSE, eqn = EQN_FILE)

COL_CONDITION <- "WM_EX"  # name of the variable encoding group membership

# experimental condition should be labeled meaningfully ----
unique(data[[COL_CONDITION]])

data[[COL_CONDITION]] <- factor(
  data[[COL_CONDITION]]
  , levels = 1:2
  , labels = c("low_WM", "high_WM")
)


# check input data.frame ----
head(data)

Options

Every time the package MPTmultiverse is loaded, it automatically sets some more or less useful defaults for model estimation, usage of multiple processor cores, number of posterior predictive samples, etc. By calling mpt_options() without any parameters, you can inspect these default values. If you want to change them, call mpt_options with the respective parameter specified, i.e. mpt_options(n.iter = 1000). For testing purposes, you can also specify mpt_options("test"), which is a shorthand for setting fast, but highly unreliable settings. You can set options to defaults, again, by typing the shorthand mpt_options("default").

# How to change a single option:
mpt_options(n.iter = 1e3)

# For testing purposes, you can use this shorthand to set fast, but unreliable options:
mpt_options("test")

# List all options that were set for the different analysis approaches:
mpt_options()

Estimation

In the next chunk, the main computations are done. Type ?fit_mpt in the R console if you want to find out more about the parameters of the function.

all_supported_methods <- c(
  "asymptotic_complete"
  , "asymptotic_no"
  , "pb_no"
  , "simple"
  , "simple_pooling"
  , "trait"
  , "trait_uncorrelated"
  , "beta"
)

results <- fit_mpt(
  method = all_supported_methods
  , dataset = DATA_FILE
  , data = data
  , model = "prospective_memory.eqn"
  , condition = COL_CONDITION
)

Post-processing of Results

# print convergence results
checks <- (check_results(results))

used_options <- getOption("MPTmultiverse")
# store results
save(
  results
  , data
  , EQN_FILE
  , DATA_FILE
  , used_options
  , checks
  , file = "results.RData"
)

# Write model checks to a file:
# write_check_results(paste0(EQN_FILE, "-", DATA_FILE), results)

The analysis output results is an object of class multiverseMPT, that has its own plot() method. Type ?plot.multiverseMPT to see the documentation of possible arguments to this method.

To plot group-level parameter estimates, type:

plot(results, save = FALSE, "est")

To plot between-subjects comparisons, type:

plot(results, save = FALSE, "test_between")

To plot overall goodness-of-fit, type:

plot(results, save = FALSE, "gof1")

To plot group-wise goodness-of-fit, type:

plot(results, save = FALSE, "gof2")


mpt-network/MPTmultiverse documentation built on May 25, 2023, 4:10 p.m.