Assignment Goals

# Knit the document using the Command + Shift + K shortcut (or by clicking the "knit" button at the top of your source editor)
library() # load papaja

library(yarrr) # To get the pirates dataframe

# ---------------------
# Show APA syle conclusions from a t.test object
# ------------------

# t.test comparing the ages of male and female pirates

sex_age_ttest <- t.test(formula = age ~ sex,
                        data = pirates,
                        subset = sex %in% c("male", "female"))

# Create apa style outputs from sex_age_ttest
sex_age_ttest_apa <- apa_print(sex_age_ttest)

# Show all output types
sex_age_ttest_apa

# Here are the different types of outputs
names(sex_age_ttest_apa)

# Full output
sex_age_ttest_apa$full_result

# $\\Delta M = -4.96$, 95\\% CI $[4.29$, $5.62]$, $t(949.43) = 14.53$, $p < .001$

# ---------------------
# Show APA syle conclusions from an lm (regression) object
# ------------------

# regression comparing tattoos as a function of sex, headband, and age

tattoos_lm <- lm(formula = tattoos ~ sex + headband + age,
                  data = pirates)

# Create apa style outputs from tattoos_lm
tattoos_lm_apa <- apa_print(tattoos_lm)

# Look at all outputs
tattoos_lm_apa

# Full result for age
tattoos_lm_apa$full_result$age

# Here is the full APA style conclusion for age
# $b = 0.02$, 95\\% CI $[-0.02$, $0.05]$, $t(995) = 0.96$, $p = .340$

# ---------------------
# Show APA syle conclusions from an Anova object
# ------------------

# Create anova object from tattoos_lm
# In this example I'm conducting a type II anova using car::Anova
tattoos_aov <- car::Anova(tattoos_lm)

# Get apa style results
tattoos_aov_apa <- apa_print(tattoos_aov)

# Look at all outputs
tattoos_aov_apa

# Full result for sex
tattoos_aov_apa$full_result$sex

# ANOVA table
tattoos_aov_apa$table


# ---------------------
# Show a APA style table of data
# ------------------

# Convert a dataframe to an APA formatted LaTeX table

apa_table(pirates[1:10, c("id", "sex", "age", "tattoos", "tchests")],
          caption = "First few rows of the pirates dataframe")

Get Started

  1. Create a new R project called studentAPA.RProj

  2. Navigate to the project directory (the one you just put studentAPA.RProj in). Create two new folders R and data in your project directory.

  3. The two data files you need for this assignment are located at https://raw.githubusercontent.com/ndphillips/IntroductionR_Course/master/assignments/wpa/data/studentmath.txt (https://raw.githubusercontent.com/ndphillips/IntroductionR_Course/master/assignments/wpa/data/studentmath.txt) (the mathdata) and https://raw.githubusercontent.com/ndphillips/IntroductionR_Course/master/assignments/wpa/data/studentpor.txt (https://raw.githubusercontent.com/ndphillips/IntroductionR_Course/master/assignments/wpa/data/studentpor.txt) (the portugesedata), we need to get these files into your data folder. To do this, open a new script. Then run code to save both data files into your data folder,

  4. Open a new R Markdown document using the papaja template. Save the file in the top level of your working directory (that is, next to the studentAPA.Rproj ) as studentAPA.Rmd

  5. Knit the document to see a simple APA style document! Do this by clicking the Knit button at the top of your source window, or by using the Command + Shift + K shortcut.

  6. In a web browser, go to https://raw.githubusercontent.com/ndphillips/IntroductionR_Course/master/assignments/wpa/studentAPA/studentAPA_blank.Rmd (https://raw.githubusercontent.com/ndphillips/IntroductionR_Course/master/assignments/wpa/studentAPA/studentAPA_blank.Rmd)

Copy all of the text, and paste it into your studentAPA.Rmd file (replace all of the text that was there before). Save the file.

  1. Open a new text file by clicking File – New File – Text File. Save the file in the top level of your working directory as studentAPA.bib

  2. In a web browser, go to https://raw.githubusercontent.com/ndphillips/IntroductionR_Course/master/assignments/wpa/studentAPA/studentAPA.bib (https://raw.githubusercontent.com/ndphillips/IntroductionR_Course/master/assignments/wpa/studentAPA/studentAPA.bib) .Copy all of the text, and paste it into your studentAPA.bib file. Save the file.

  3. Your goal is to create the following APA document( https://github.com/ndphillips/IntroductionR_Course/blob/master/assignments/wpa/studentAPA/studentAPA_comp.pdf?raw=true) ) by adding elements to the studentAPA.Rmd document. In a web browser, go to the link above to download the studentAPA_comp.pdf file and see how it looks.

Adding titles and knitting

  1. In studentAPA.Rmd, replace the X values in the main fields at the top of the document (name, paper title, short-title, affiliation) with the appropriate names and titles.

  2. Now Knit your document to see the current version of the PDF output! You can do this by clicking the “Knit” button at the top of your window or by using the Command + Shift + K shortcut (on Mac).

Add References to .bib

  1. Now it’s time to add some references to your studentAPA.bib file! You will be referencing three papers in this document. Using scholar.google.com (scholar.google.com), find the BibTeX references for the following paper(s) and add them to your studentAPA.bib file. Make sure to save the file!
  1. Now it’s time to cite your new references. I’ve included one citation already in the studentAPA.Rmd document in the . Now cite the additional papers in your studentAPA.bib file by replacing the XXX values with the appropriate citations. Knit your document to see the result.

Load Data

  1. You need to load your data in a separate chunk. Knit your document to see the result If you don’t see any errors, then the data should have been correctly loaded!
  2. In the Participants section, there are inline code chunks that should indicate the number of participants in each data set. Replace the 1+1 values with nrow(student.por) and nrow(student.math) to get the number of students in each data set. Knit yourvdocument to see the result

Add Plots

  1. In the Results section, I’ve included a chunk called fig1 that creates Figure 1, a series of histograms. Update the caption to the plot in the chunk options. Then change eval = FALSE to eval = TRUE to tell Markdown to run the chunk. Knit your document to see the result. You should now see the histograms in your document!

  2. There is another chunk called fig2 that plots the correlations between numeric predictors in the math data. Turn on the chunk by setting eval = TRUE , update the caption. Knit your document to see the result

Look at Different Document Classes

  1. You can render your document in one of three document classes: doc (document), man (manuscript) and pub (publication). At the top of your Markdown file, you’ll see the text class: man. Change the class to doc and knit. Then change the class to pub and knit. Look at the new outputs!

Add Statistics

  1. Below the Figure 1 chunk, there are some inline chunks that calculate the mean grades for exam 1 and exam 3 of the Portuguese data. Update these chunks with the correct code to calculate the mean G3 scores for the math and portugese datasets. Knit your document to see the result.
  2. The next two chunks create tables of summary statistics for the Math and Portuguese data. Update the captions in these chunks.Then, change eval = FALSE to eval = TRUE in the chunk options. Knit your document to see the result. You should now see the tables in your document.
  3. The next chunk conducts and saves t-tests for both the math and Portuguese data. The code for the Portuguese test sex.por.ttest is already completed, but the code to create a similar test for the math data is missing. Add the code for the math test to create the object sex.math.ttest.Then, change eval = FALSE to eval = TRUE in the chunk options.
  4. The next lines use inline code to refer to the results of your t-test objects. Replace the 1+1 values with papaja::apa_print(sex.por.ttest)\(full_result and papaja::apa_print(sex.math.ttest)\)full_result Knit your document to see the result.

Submit

  1. Save and email me your studentAPA.Rmd file, studentAPA.pdf, and studentAPA.doc.