lisa_stuff/demo.R

# load function definitions
library(magrittr)
source("lisa_stuff/study_framework.R")

#########################
# demo functional setup #
#########################

# set up empty study object
mystudy <- study("IAT Demo")

# add hypothesis 1
mystudy <- add_hypothesis(
  study = mystudy,
  id = "H1", # defaults to index
  description = "Mean RT will be significantly slower in the incongruent condition compared to the congruent condition.",
  evaluation = "&"
)

# add criterion 1 to hypothesis 1
mystudy <- add_criterion(
  study = mystudy,
  hypothesis_id = "H1", # defaults to last hypothesis
  analysis_id = "H1_ttest", # defaults to last analysis or index 1 if none yet
  result = "p.value",
  direction = "<",
  comparator = .05
)

# add criterion 2 to hypothesis 1
mystudy <- add_criterion(
  study = mystudy,
  hypothesis_id = "H1",
  analysis_id = "H1_ttest",
  result = "estimate",
  direction = ">",
  comparator = 0
)

# add hypothesis 2
mystudy <- add_hypothesis(
  study = mystudy,
  id = "H2",
  description = "Reaction times for congruent and incongruent trials will be signifiantly and positively correlated.",
  evaluation = "&"
)

# add criterion 2 to hypothesis 2
mystudy <- add_criterion(
  study = mystudy,
  hypothesis_id = "H2",
  analysis_id = "H2_cor",
  result = "p.value",
  direction = "<",
  comparator = 0.05
)

# add criterion 2 to hypothesis 2
mystudy <- add_criterion(
  study = mystudy,
  hypothesis_id = "H2",
  analysis_id = "H2_cor",
  result = "estimate",
  direction = ">",
  comparator = 0
)

# add analysis 1
mystudy <- add_analysis(
  study = mystudy,
  id = "H1_ttest",
  func = "t.test",
  params = list(
    x = ".data$incongruent",
    y = ".data$congruent",
    alternative = "two.sided",
    paired = TRUE,
    var.equal = FALSE,
    conf.level = 0.95
  )
)

# add analysis 2
mystudy <- add_analysis(
  study = mystudy,
  id = "H2_cor",
  func = "cor.test",
  params = list(
    x = ".data$congruent",
    y = ".data$incongruent",
    alternative = "two.sided",
    method = "pearson",
    conf.level = 0.95
  )
)

# generate pre-registration report
study_report(mystudy, type="prereg")

# add data
n_sub <- 50
dat <- faux::rnorm_multi(n_sub, 2, .5, c(500, 750), 250,
                         c("congruent", "incongruent"))
dat$sub_id = 1:n_sub
add_data(mystudy, dat)

# run analyses
study_analyse(mystudy)

# generate post-registration report
study_report(mystudy, type="postreg")




##############################
# demo object-oriented setup #
##############################

mystudy <- study("IAT Demo")  %>%
  add_hypothesis(
    id = "H1", # defaults to index
    description = "Mean RT will be significantly slower in the incongruent condition compared to the congruent condition.",
    evaluation = "&") %>%
  add_criterion(
    hypothesis_id = "H1",
    analysis_id = "H1_ttest",
    result = "p.value",
    direction = "<",
    comparator = .05
  ) %>%
  add_criterion(
    hypothesis_id = "H1",
    analysis_id = "H1_ttest",
    result = "estimate",
    direction = ">",
    comparator = 0
  ) %>%
  add_hypothesis(
    id = "H2",
    description = "Reaction times for congruent and incongruent trials will be signifiantly and positively correlated.",
    evaluation = "&"
  ) %>%
  add_criterion(
    hypothesis_id = "H2",
    analysis_id = "H2_cor",
    result = "p.value",
    direction = "<",
    comparator = 0.05
  ) %>%
  add_criterion(
    hypothesis_id = "H2",
    analysis_id = "H2_cor",
    result = "estimate",
    direction = ">",
    comparator = 0
  ) %>%
  add_analysis(
    id = "H1_ttest",
    func = "t.test",
    params = list(
      x = ".data$incongruent",
      y = ".data$congruent",
      alternative = "two.sided",
      paired = TRUE,
      var.equal = FALSE,
      conf.level = 0.95
    )
  ) %>%
  add_analysis(
    id = "H2_cor",
    func = "cor.test",
    params = list(
      x = ".data$congruent",
      y = ".data$incongruent",
      alternative = "two.sided",
      method = "pearson",
      conf.level = 0.95
    )
  ) %>%
  study_report(type="prereg") %>%
  add_data(dat) %>%
  study_analyse() %>%
  study_report(type="postreg")
debruine/pipeline documentation built on May 8, 2019, 8:59 a.m.