Skip to content

Commit

Permalink
08102023
Browse files Browse the repository at this point in the history
  • Loading branch information
pablobernabeu committed Oct 8, 2023
1 parent b2f81cf commit 3603235
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .Rproj.user/093035E2/pcs/files-pane.pper
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"ascending": true
}
],
"path": "~/OSF/osf.io-ueryq/semanticdecision/frequentist_analysis/model_diagnostics"
"path": "~/OSF/osf.io-ueryq/semanticdecision/power_analysis/results"
}
2 changes: 1 addition & 1 deletion .Rproj.user/093035E2/pcs/source-pane.pper
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"activeTab": -1
"activeTab": 0
}
14 changes: 7 additions & 7 deletions .Rproj.user/093035E2/pcs/windowlayoutstate.pper
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"left": {
"splitterpos": 482,
"topwindowstate": "HIDE",
"panelheight": 1041,
"windowheight": 1079
"splitterpos": 348,
"topwindowstate": "NORMAL",
"panelheight": 753,
"windowheight": 791
},
"right": {
"splitterpos": 684,
"splitterpos": 494,
"topwindowstate": "MINIMIZE",
"panelheight": 1041,
"windowheight": 1079
"panelheight": 753,
"windowheight": 791
}
}
26 changes: 26 additions & 0 deletions .Rproj.user/093035E2/sources/per/t/98902CB9
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"id": "98902CB9",
"path": "~/OSF/osf.io-ueryq/semanticdecision/bayesian_analysis/semanticdecision_brms_weaklyinformativepriors_exgaussian.R",
"project_path": "semanticdecision/bayesian_analysis/semanticdecision_brms_weaklyinformativepriors_exgaussian.R",
"type": "r_source",
"hash": "602524222",
"contents": "",
"dirty": false,
"created": 1696285940543.0,
"source_on_save": false,
"relative_order": 1,
"properties": {
"source_window_id": "",
"Source": "Source",
"cursorPosition": "7,0",
"scrollLine": "0"
},
"folds": "",
"lastKnownWriteTime": 1696285960,
"encoding": "UTF-8",
"collab_server": "",
"source_window": "",
"last_content_update": 1696285960873,
"read_only": false,
"read_only_alternatives": []
}
156 changes: 156 additions & 0 deletions .Rproj.user/093035E2/sources/per/t/98902CB9-contents
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@


# Part of Study 2: Semantic decision

# Part of Bayesian analysis

# Model with weakly-informative priors (SD = 0.2)


library(dplyr)
library(brms) # Version 2.17.0

# Read in data
semanticdecision = read.csv('semanticdecision/data/final_dataset/semanticdecision.csv')

# Define priors

# In the function `set_prior` used below, the argument `class` often represents
# groups of parameters. For instance, class 'b' refers to fixed effects.

# Since most priors do not specify the negative/positive direction of effects,
# distributions are first specified for entire classes, and those are
# overridden wherever a direction is specified.

weaklyinformative_priors =
c(set_prior('normal(0, 0.2)', class = 'Intercept'),
set_prior('normal(0, 0.2)', class = 'b'),
set_prior('normal(0.1, 0.2)', class = 'b',
coef = 'z_orthographic_Levenshtein_distance'),
set_prior('normal(-0.1, 0.2)', class = 'b',
coef = 'z_word_frequency'),
set_prior('normal(0, 0.2)', class = 'sd'), # automatically truncated to keep positive values only
set_prior('normal(0, 0.2)', class = 'sigma'), # automatically truncated to keep positive values only
set_prior('lkj(2)', class = 'cor') # standard, regularising prior on random-effects covariance to aid convergence
)

# Model

semanticdecision_brms_weaklyinformativepriors_exgaussian =

brm(

# Dependent variable
z_RTclean ~

# FIXED EFFECTS

# Controlled lexical variables
z_word_frequency + z_orthographic_Levenshtein_distance +

# Controlled word concreteness, important because the task is a word concreteness assessment.
z_word_concreteness +

# Control interaction between word concreteness and vocabulary size to allow a rigorous analysis of the
# interaction between word co-occurrence and vocabulary size, and the interaction between word visual
# rating and vocabulary size.
z_word_concreteness : z_vocabulary_size +

# Control interaction between word concreteness and participant gender to allow a rigorous analysis
# of the interaction between visual rating and participant gender.
z_word_concreteness : z_recoded_participant_gender +

# Important control due to the relationship between this variable and vocabulary size (Pexman & Yap, 2018;
# http://germel.dyndns.org/psyling/pdf/2018_PexmanYap_SemCat_IndividualDifferences.pdf)
z_information_uptake +

# Control interactions with information uptake to allow a rigorous analysis of the interactions with
# vocabulary size specified below.
z_word_cooccurrence : z_information_uptake +
z_visual_rating : z_information_uptake +

# Main effects of interest
z_vocabulary_size + z_recoded_participant_gender +
z_word_cooccurrence + z_visual_rating +

# Interactions of interest
z_word_cooccurrence : z_vocabulary_size +
z_visual_rating : z_vocabulary_size +
z_word_cooccurrence : z_recoded_participant_gender +
z_visual_rating : z_recoded_participant_gender +

# RANDOM EFFECTS: maximal structure constructed following the guidelines of Brauer and Curtin (2018;
# https://psych.wisc.edu/Brauer/BrauerLab/wp-content/uploads/2014/04/Brauer-Curtin-2018-on-LMEMs.pdf).
# Interactions only require random slopes if all variables involved vary within the same units.

# By-participant random slopes

# Below, the random slopes for control covariates (i.e., 'z_word_frequency',
# 'z_orthographic_Levenshtein_distance' and 'z_word_concreteness') were removed
# due to non-convergence, inspired by Remedy 11 from Table 17 in Brauer and
# Curtin (2018). However, whereas Brauer and Curtin constrain such a removal
# to cases in which the covariate does not interact with any effects of
# interest, the random slopes for 'z_word_concreteness' were removed below
# because the interactions between this covariate and the effects of interest
# were control covariates, not interactions of interest. That is, they
# were not critical to the research question.

(z_word_cooccurrence + z_visual_rating | Participant) +

# By-word random slopes

# Below, the random slopes for the control covariate (i.e., 'z_information_uptake')
# were removed due to non-convergence, inspired by Remedy 11 from Table 17 in Brauer
# and Curtin (2018). However, whereas Brauer and Curtin constrained such a removal to
# cases in which the covariate does not interact with any effects of interest, the
# random slopes for 'z_information_uptake' were removed below because the interactions
# between this covariate and the effects of interest were control covariates, not
# interactions of interest. That is, they were not critical to the research question.

(z_vocabulary_size + z_recoded_participant_gender | Word),

data = semanticdecision, prior = weaklyinformative_priors,

# Following the prior predictive checks, an ex-gaussian distribution is set below.
# This distribution is well suited for the analysis of response times (Bürkner et al.,
# 2022, https://cran.r-project.org/web/packages/brms/brms.pdf; Rodríguez-Ferreiro
# et al., 2020, see supplementary materials via https://doi.org/10.7717/peerj.9511).
# Furthermore, the use of link functions, instead of transformations of the
# dependent variable, largely preserves the interpretability of the coefficients
# (Knief & Forstmeier, 2021; Lo & Andrews, 2015, https://doi.org/10.3389/fpsyg.2015.01171).

family = exgaussian(),

seed = 123, # allow exact replication of results
warmup = 2000, # warmup iterations
iter = 8000, chains = 16, # (iter - warmup) x chains = total post-warmup draws (brms v2.17.0)
cores = 5, # parallel computation
control = list(adapt_delta = 0.99, max_treedepth = 15) # facilitate convergence
)


# NOTE: Output takes up more than 15G, so it was removed from the project due to the 50G
# limit on OSF.io. If you wish to save the output, please uncomment the lines below.
# saveRDS(semanticdecision_brms_weaklyinformativepriors_exgaussian,
# 'semanticdecision/bayesian_analysis/results/semanticdecision_brms_weaklyinformativepriors_exgaussian.rds')

# Model summary
summary(semanticdecision_brms_weaklyinformativepriors_exgaussian) %>%
saveRDS('semanticdecision/bayesian_analysis/results/semanticdecision_summary_weaklyinformativepriors_exgaussian.rds')

# Posterior predictive check
# Next, a posterior predictive check is performed to examine the sensitivity of
# the model to priors varying in informativeness (for similar procedures, see
# Rodríguez-Ferreiro et al., 2020, https://doi.org/10.7717/peerj.9511;
# Stone et al., 2020, https://doi.org/10.7717/peerj.10438). The posterior
# predictive checks from all models are compared in the folder
# 'posterior_predictive_checks'.
pp_check(semanticdecision_brms_weaklyinformativepriors_exgaussian, ndraws = 100) %>%
saveRDS('semanticdecision/bayesian_analysis/posterior_predictive_checks/semanticdecision_posteriorpredictivecheck_weaklyinformativepriors_exgaussian.rds')

# Plot posterior distribution of each fixed effect (i.e., effects commencing with 'b_')
mcmc_plot(semanticdecision_brms_weaklyinformativepriors_exgaussian,
type = 'areas', variable = '^b_', regex = TRUE) %>%
saveRDS('semanticdecision/bayesian_analysis/results/posteriordistributions_semanticdecision_weaklyinformativepriors_exgaussian.rds')


6 changes: 6 additions & 0 deletions .Rproj.user/093035E2/sources/prop/3406D2DF
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"source_window_id": "",
"Source": "Source",
"cursorPosition": "7,0",
"scrollLine": "0"
}
1 change: 1 addition & 0 deletions .Rproj.user/093035E2/sources/prop/INDEX
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
~%2FOSF%2Fosf.io-ueryq%2Fsemanticdecision%2Fbayesian_analysis%2Fposterior_predictive_checks%2Fsemanticdecision_posteriorpredictivechecks.R="2EA34ACD"
~%2FOSF%2Fosf.io-ueryq%2Fsemanticdecision%2Fbayesian_analysis%2Fprior_predictive_checks%2Fsemanticdecision_priorpredictivecheck_diffusepriors_exgaussian.R="434AA05B"
~%2FOSF%2Fosf.io-ueryq%2Fsemanticdecision%2Fbayesian_analysis%2Fsemanticdecision_brms_diffusepriors_exgaussian.R="98D87F8C"
~%2FOSF%2Fosf.io-ueryq%2Fsemanticdecision%2Fbayesian_analysis%2Fsemanticdecision_brms_weaklyinformativepriors_exgaussian.R="3406D2DF"
~%2FOSF%2Fosf.io-ueryq%2Fsemanticdecision%2Fcorrelations%2Fsemanticdecision_correlations.R="3EDC62B8"
~%2FOSF%2Fosf.io-ueryq%2Fsemanticdecision%2Fdata%2Fsemanticdecision_data_preparation.R="5F25266B"
~%2FOSF%2Fosf.io-ueryq%2Fsemanticdecision%2Ffrequentist_analysis%2Flexical_covariates_selection%2Flexical_covariates_selection_semanticdecision_lmerTest.R="A4DD5B32"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ semanticdecision_brms_weaklyinformativepriors_exgaussian =

(z_vocabulary_size + z_recoded_participant_gender | Word),

data = semanticdecision, prior = weaklyinformative_priors,

# Following the prior predictive checks, an ex-gaussian distribution is set below.
# This distribution is well suited for the analysis of response times (Bürkner et al.,
# 2022, https://cran.r-project.org/web/packages/brms/brms.pdf; Rodríguez-Ferreiro
Expand Down

0 comments on commit 3603235

Please sign in to comment.