This week I hope to play around with the papaja package at Jenny’s recommendation. If all goes well, I should be able to learn how to use this package to create some cool APA formatted things, which might come in handy for the verification report project.
So I have just had the most frustrating hour of my life trying to install the papaja package. It required me to install the devtools package, which sent my RStudio into an endless loop of restarts and sent an army of error messages. I would relay some of those messages here but they are all lost since my RStudio eventually hard-crashed :(.
I eventually uninstalled and re-installed RStudio, updated every single package I have and now it finally works!!! Time to get started.
The papaja package is useful for creating APA style markdown documents. Because this is a learning log, I won’t make the whole document APA format, but I can try to create some APA tables with some sample data.
load("~/Desktop/Uni/Third Year/T1/3361 (Internship)/data/mixed_data.rdata")
summary(mixed_data[,-1])
## Subject Gender Dosage Task Valence Recall
## A : 6 F:54 A:36 C:54 Neg:36 Min. : 4.00
## B : 6 M:54 B:36 F:54 Neu:36 1st Qu.:13.00
## C : 6 C:36 Pos:36 Median :15.00
## D : 6 Mean :15.63
## E : 6 3rd Qu.:19.00
## F : 6 Max. :25.00
## (Other):72
Now we can prepare the data to be displayed in the table. Let’s start by preparing some descriptive statistics:
descriptives <- mixed_data %>%
group_by(Dosage) %>%
summarise(Mean = mean(Recall),
Median = median(Recall),
SD = sd(Recall),
Min = min(Recall),
Max = max(Recall))
descriptives[, -1] <- printnum(descriptives[, -1])
descriptives
## # A tibble: 3 x 6
## Dosage Mean Median SD Min Max
## <fct> <chr> <chr> <chr> <chr> <chr>
## 1 A 14.19 14.00 4.45 5 25
## 2 B 13.50 14.00 5.15 4 22
## 3 C 19.19 19.00 3.52 13 25
Now to run all of this data through the apa_table function:
apa_table(descriptives,
caption = "Descriptive statistics of correct recall by dosage.",
note = "Wow I cannot believe that creating the APA formatted table was the easiest part of this whole task...")
| Dosage | Mean | Median | SD | Min | Max |
|---|---|---|---|---|---|
| A | 14.19 | 14.00 | 4.45 | 5 | 25 |
| B | 13.50 | 14.00 | 5.15 | 4 | 22 |
| C | 19.19 | 19.00 | 3.52 | 13 | 25 |
Note. Wow I cannot believe that creating the APA formatted table was the easiest part of this whole task…
Â
Now, this is definitely not an APA table, but that is because the papaja package is not meant for HTML markdown documents. If you type the same code into the APA markdown template (which comes with the package) and set the output to a pdf you get the following:
Whilst exploring the basics of papaja I came across another potentially useful package called apaTables. After reading an article about the package’s utility, I decided to give it a try. I must say, this package seems fairly easy to use, because I managed to create an APA correlation table for the RStudio sample dataset attitude with just a few lines of code.
library(apaTables)
apa.cor.table(attitude, filename="Table1_APA.doc", table.number=1)
Like the papaja package, the code does not produce an APA formatted table in the output of the markdown doc. Instead, running this code will create a word doc with the newly produced table, in the same folder as your working directory. This was the result from the above two lines of code:
The apaTables package can be used to create tables for all types of data, from regression to complex ANOVA designs. The only downside I can see at this stage is I’m not sure how to change the particular details of the table (they seem to be set in stone within the function itself). So this package is more accessible but it might offer less freedom in how you design your tables. Nevertheless, this is really cool.
This week was a nightmare of endless errors and frustration. I probably spent more time researching how to install certain packages then I did learning how to use them. There were also some issues trying to get my tables to be in proper APA format. However, after some digging, I realised that these packages are not designed for HTML markdown documents. Once I figured that out, it was smooth sailing.
I managed to create some fairly cool (albeit basic) tables. I’m looking foward to seeing how I can improve upon these in the future.
I didn’t get around to Dani’s data wrangling tutorials this week. However, I am fairly comfortable with managing data already. Having said that, I am sure there is plenty left to learn, and so next week I hope to watch her videos and practice some data wrangling. This will also give me a much needed break from working with graphs and certain packages (yes, I’m talking about you devtools).