Preliminaries

You can find the solutions for this exercise as well as the following ones in the exercises folder in the workshop material. You can also navigate the workshop material online (including exercises and solutions).

You can copy code from the exercise and solution files by clicking on the small blue clipboard icon in the upper right corner of the boxes showing the code.

Some of the exercise require you to add text and R code. Feel free to copy from the example paper in the folder exercises/example_manuscript. We do, however, encourage you to use material from a project of your own, if possible. It will be a lot more fun.

Exercises

In this exercise, you will create a first papaja document. The example data we use here is taken from the example manuscript provided with the workshop material. However, we encourage you to use your own data for this and the following exercises.

Document template

Exercise 1

Create a new papaja document and populate the YAML front matter of with the manuscript metadata.

File > New File > R Markdown… > From Template

In the YAML front matter, the note field and each author’s role field can simply be omitted.

Solution

# The following is taken from the example article.

title: "Distorted estimates of implicit and explicit learning in applications of the process-dissociation procedure to the SRT task"
shorttitle: "Distorted PD estimates in sequence learning"

author: 
  - name: "Christoph Stahl"
    affiliation: ""
    corresponding: yes
    address: "Herbert-Lewin-Straße 2, 50931 Köln"
    email: "christoph.stahl@uni-koeln.de"
  - name: "Marius Barth"
    affiliation: ""
  - name: "Hilde Haider"
    affiliation: ""

affiliation:
  - id: ""
    institution: "University of Cologne"

authornote: |
  This work was funded by Deutsche Forschungsgemeinschaft grants STA-1269/1-1 and HA-5447/8-1.

abstract: |
  We investigated potential biases affecting the validity of the process-dissociation (PD) procedure when applied to sequence learning.
  Participants were or were not exposed to a serial reaction time task (SRTT) with two types of pseudo-random materials.
  Afterwards, participants worked on a free or cued generation task under inclusion and exclusion instructions.
  Results showed that pre-experimental response tendencies,
  non-associative learning of location frequencies,
  and the usage of cue locations introduced bias to PD estimates.
  These biases may lead to erroneous conclusions regarding the presence of implicit and explicit knowledge.
  Potential remedies for these problems are discussed.

keywords: "implicit learning, serial reaction time task, process-dissociation procedure, response bias"
wordcount: "8,167"



Exercise 2

Make your manuscript “preprint-ready”:

  1. Hide line numbers,
  2. use the single-column single-spaced document style (i.e. use the "doc" class option), and
  3. add a “DRAFT” watermark on every page.
Use the draft and linenumbers options in the YAML front matter.

Solution

draft: yes
linenumbers: no

classoption: "doc"



Report statistics

Exercise 3

Now let’s report some results.

  1. Copy the contents of your R Markdown document to your papaja document.
  2. Report the nummerical results of one or more analysis using in-line code chunks. If possible, use apa_print().

If you are working with the example manuscript, locate and open the R-script analyses.R and data folder data accompanying the example manuscript in the folder exercises/3_papaja_example_manuscript.

If you are unsure, whether your analysis is supported, methods(apa_print) provides a list of supported classes.

If you cannot use apa_print() you will need to manually pick numerical results from your results object. str() may help to find the numbers you are looking for and apa_num(), apa_p(), apa_df(), and apa_confint() will facilitate formatting.

Solution

The following is an excerpt of the example manuscript. We first load and filter the data before performing an analysis of variance.

```{r}
#| load-data

acquisition <- readRDS("data/acquisition-task.rds")
```

...

```{r}
#| acquisition-rt

# within the permuted-material group, high vs. low frequency locations can be distinguished
tmp.perm <- acquisition[
  acquisition$error == 0 &
  acquisition$trial > 1 &
  acquisition$included_participant & 
  acquisition$material == "Permuted" & 
  !is.na(acquisition$frequency),
]

out.perm <- apa_print(
  aov_ez(data = tmp.perm, dv = "SRI", within = c("block",     "frequency"), id = "id")
)
```

A 2 (*frequency*: high vs. low) $\times$ 6 (*block number*) ANOVA revealed a main effect of *frequency*, `r out.perm$full_result$frequency`; high-frequency responses were faster than low-frequency responses. 
The main effect of *block number* was also significant, `r out.perm$full_result$block`, but not the interaction, `r out.perm$full_result$block_frequency`.



Figures and tables

Exercise 4

Add a figure and/or table to your results section and cross-reference it in the text. Use text-references to add a caption.

You can use apa_factorial_plot() (or one of the short-hands apa_barplot(), apa_beeplot(), and apa_lineplot()) or try our ggplot2-theme theme_apa(), if applicable.

Handles used to cross-reference figures and tables are generated automatically from the chunk label:

  • fig:chunk-label or
  • tab:chunk-label.
Text reference definitions must be on their own line, surrounded by empty lines, and start with (ref:reference-name).

Solution

The following are excerpts fromm the example manuscript.

This first section is an example of a figure. Note that the chunk from the previous exercise is continued here (same chunk label, accesses same data object).

(ref:acquisition-rt) Mean reaction times for permuted material, split by high-frequency (filled circles) vs. low-frequency locations (open circles). Error bars represent 95% within-subjects CIs.

```{r}
#| acquisition-rt
#| fig.cap: "(ref:acquisition-rt)"

apa_lineplot(
  data = tmp.perm
  , id = "id"
  , dv = "SRI"
  , factors = c("block", "frequency")
  , dispersion = wsci
  , ylab = ""
  , args_lines = list(lty = c("solid", "solid"))
  , args_points = list(pch = c(21, 21))
  , args_legend = list(legend = c("High", "Low"), title = "Location frequency")
  , ylim = c(475, 650)
  , jit = .05
)
```

Figure\ \@ref(fig:acquisition-rt) shows the mean RTs for these two types of stimuli.

The following sections are an example of a table that is given in the appendix of the example manuscript. The first chunk puts together the to-be-presented summary statistics in a data.frame.

```{r}
#| proportion-correct-table-df

tmp <- generation[
  generation$included_participant &
  generation$repetition == 0 &
  generation$post_repetition == 0,
]

# calculate proportion of regular transitions per participant
agg <- aggregate(
  formula = correct_SOC ~ material + generation + order + PD_instruction + id
  , data = tmp
  , FUN = mean
  , na.rm = TRUE
)

# calculate condition means and standard errors
means <- aggregate(
  formula = cbind(M = correct_SOC) ~ material + generation + order + PD_instruction
  , data = agg
  , FUN = mean
)
SEs <- aggregate(
  formula = cbind(`SE` = correct_SOC) ~ material + generation + order + PD_instruction
  , data = agg
  , FUN = se
)

# merge means and CI width
tab <- merge(means, SEs)

# bind Inclusion and Exclusion side-by-side
tab <- cbind(tab[tab$PD_instruction == "Inclusion", ], tab[tab$PD_instruction == "Exclusion", c("M", "SE")])
tab$PD_instruction <- NULL

tab$material <- gsub(tab$material, pattern = "-", replacement = " ", fixed = TRUE)
tab$generation <- as.character(tab$generation)
tab$generation[duplicated(paste0(tab$material, tab$generation))] <- ""
tab$material[duplicated(tab$material)] <- ""
```

This second chunk generates the table that is included in the appendix.

(ref:table-caption) Means ($M$) and standard errors ($\mathit{SE}$) of proportion of correctly generated second-order conditionals (SOCs).

```{r}
#| proportion-correct-table

apa_table(
  tab
  , row.names = FALSE
  , col_spanners = list(Inclusion = c(4, 5), Exclusion = c(6, 7))
  , midrules = c(4, 8, 12)
  , caption = "(ref:table-caption)"
  , placement = NULL
)
```

Table\ \@ref(tab:proportion-correct-table) shows the proportion of correctly generated second-order conditionals.



Bonus

Bonus 1

Try out the DOCX output format.
The DOCX format is provided by apa6_docx().

Solution

output: papaja::apa6_docx



Bonus 2

Add an appendix to your manuscript.

To start an appendix, use the following special heading:

# (APPENDIX) Appendix {-}

Solution

\newpage

# References

::: {#refs custom-style="Bibliography"}
:::


\newpage

# (APPENDIX) Appendix {-}

This is the content of the appendix



Bonus 3

Manually (i.e. without using apa_print()) report the results for the following one-sided t-test according to the APA guidelines.

t.test(extra ~ 1, data = sleep, alternative = "greater")

Report

  • mean difference,
  • confidence interval,
  • degrees of freedom,
  • \(t\) value, and
  • \(p\) value.
str() may help to find the numbers you are looking for and apa_num(), apa_p(), apa_df(), and apa_confint() will facilitate formatting.

Solution

Calculate the t-test in a code chunk and pick the required information from the resulting object.

```{r}
#| t-test

ttest_res <- t.test(
  extra ~ 1
  , data = sleep
  , alternative = "greater"
)
```

The mean difference of `r ttest_res$estimate` `r apa_confint(ttest_res$conf.int)` we observedd was significant, $t(`r apa_df(ttest_res$parameter)`) = `r ttest_res$statistic`$, $p `r apa_p(ttest_res$p.value, add_equals = TRUE)`$.

Solutions

After you have tried yourself, feel free to have a look at our solutions.