---
title: "Writing up analysis 01"
subtitle: "Basic descriptives"
author: "insert your name"
output:
  html_document:
    number_sections: true
---

This is the first in a series of documents that will teach you how to inspect, tidy up, and analyse various kinds of data as well as write up the results of your analysis.


# Setup

First things first, when you're writing a document in R Markdown, it is worth setting some global chunk options. This is what the chunk below does. `echo = TRUE` means that the code will be displayed by default, unless you explicitly change it to `FALSE` for any given code chunk. There are rarely any reasons to show your code in the write up so normally, you would change the option to `FALSE` before generating the final version of your report. `warning = FALSE` and `message = FALSE` mean that any warnings/messages given by functions will not be displayed in the final document. It is very important to be aware of any warnings and know what they mean but they are for you, the analyst, not for the reader.

```{r setup}
# setting up default code chunk behaviour
knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE)
# add library() commands to load all packages you need for this document

```

Normally, you would want to hide both this chunk and its output from the final document. You can do it by adding `, include=FALSE` right after the `{r setup` bit so that it reads `{r setup, include=FALSE}`.

Next, to be able to use `R` to its full potential, you need to load packages (you must install them first - this is only done once). It's good to have them all loaded in the `setup` chunk at the top of your .Rmd. Whenever you realise you need to load another package, just scroll up and add another `library()` command to the chunk.

# Read-in, inspect, and clean

OK, time to read in your data. Remember, you must store the data in an object using `<-`, otherwise `R` will just spit them out into the console and forget all about them.

```{r read-in}
# complete the line to read in the data

data <- read_csv()
```

\ 

The first step in analysis is a thorough data inspection. Before you start fitting statistical models and what not, you need to make sure you know your data inside-out. How many columns/variables do you have? How many rows? What are the names of your variables? Which ones are `numeric`, which ones are `character`/`factor`? Are there `NA`s? How many? Are all values sensible? What are the levels of the non-numeric variables? These are *some* of the questions you should be able to answer and, in the following weeks, you will learn how find answers to them.

```{r inspect}
# check number of rows and columns, and names of variables

# only keep the ID, Condition, Humanness, Harm, Gender, and Age variables in the dataset

# check range of the Age column

```

```{r clean}
# how many rows are we about to remove?

# only keep participants over 16 in your data
data <- 
```

# Describe 

Once you've gathered the basic info about your data set as a whole, it's useful to look at the descriptive statistics for every single variable to get a better feel for it. This is also a good time to prepare objects/tibbles you'll use for write-up and tables.

```{r descriptives}
age_desc <- 

gender_desc <- 

```

\ 

Looking at numbers is important but, as the saying goes, sometimes a picture is worth a thousand words. For that reason, plot stuff. Plot everything - single variables, relationships between variables, trends (more on that in later weeks). Exploring your data visually is good! Just make sure you don't flood your report/dissertation/paper with unnecessary exploratory plots. **Only include visualisations if they add something of value to the body text or if they communicate information more concisely than words/tables.**

```{r prepare-plots}
# you can store plots iside objects too!
age_hist <- data %>%
  ggplot(aes(x = )) +
  geom_histogram(fill = "white", colour = "black") +
  labs(x = "Participants' age in years") +
  cowplot::theme_cowplot() # this adds quite a neat clean theme

gender_bar <- data %>%
  ggplot() +
  cowplot::theme_cowplot()

age_by_condition_gender <- data %>%
  ...add code here...
  ggplot2::ggplot(aes(x = , y = , colour = Harm)) +
  geom_point(size = 3) +
  facet_wrap(~Humanness) +
  theme_bw()
```

\ 

# Report

Now that all that's dealt with, you can start writing up. It doesn't matter that you don't have the results yet. The sample, material, and procedure details aren't going to change. In fact, there's no reason why you can't start writing up even before you have your data!

## Method

### Participants

The study was conducted on a sample of `r nrow(data)` volunteers (*M*~age~ = [provide value], *SD*~age~ = `r age_desc$age_sd`). The data were collected anonymously on-line. Data from [provide value] participants were excluded due to unlikely values of age. Table 1 shows the distribution of gender as well as an age brake-up by individual gender categories.

### Materials

We used images of faces of a photorealistic human avatar and a robotic avatar as stimuli. These two faces were then modified to create the faces’ harmed analogues by adding the facial texture of a moderate burn to their right side. All images measured 960&times;720 pixels and were displayed individually on a white background.

We measured the extent to which participants attributed the capacity to experience (7 items), agency (7 items), consciousness (2 items), and pain (1 item) to the avatars. A 7-item measure of empathy with avatars was used and avatars were also rated on attractiveness (1 item). All items used a 7-point likert scale.

### Procedure

[ *Read the relevant bit of the paper and provide your own account of the procedure* ]

```{r table-1}
# provide tibble to push to kableExtra::kbl() and fill in missing column names
 %>%
  kableExtra::kbl(col.names = c( , "*N*", "%", "*M*~age~", ),
        caption = "") %>%
  kableExtra::kable_styling()
```

```{r print-plots}

```

\ 

\ 

That's it for now. Next time we'll dig deeper into our data and continue writing up our report.
