---
title: "Edinburgh Handedness Inventory"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{ehi}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
options(rmarkdown.html_vignette.check_title = FALSE)
frag_path <- here::here("man", "fragments", "ehi")
paths <- list.files(frag_path, "Rmd", full.names = TRUE)
names(paths) <- gsub("\\.Rmd", "", basename(paths))
paths <- as.list(paths)
```


## Background
```{r child=paths$background, eval = TRUE} 
```

## Scoring
```{r child=paths$scoring, eval = TRUE} 
```

### Questionnaire Items
**01** - Writing  
**02** - Drawing  
**03** - Throwing  
**04** - Use scissors  
**05** - Brush teeth  
**06** - Use knife (without fork)  
**07** - Use spoon  
**08** - Use broom (top hand)  
**09** - Strike match (holding match)  
**10** - Opening container (hand on lid)  

## Data requirements  
```{r child=paths$datareqs, eval = TRUE} 
```

## Using the `ehi` functions
### Nominal value
The nominal value from the EHI is based on the answer to question number 1, regarding writing. 
The `ehi_factorise_nominal` function should be supplied this answer directly, and will return a factor vector of equal length with the categories.

```{r}
library(dplyr)
library(questionnaires)

writing <- c(2, 2, -1, 0, 1, -2)
ehi_factorise_nominal(writing)
```

### Laterality quotient
Calculating the laterality quotient requires the entire dataset of all EHI columns to be computed, and as such takes an entire data.frame, with a tidy-selector selecting the columns that contain the EHI columns.
If you are working with MOAS-like data, the columns are select by default settings. 

```{r}
# Make some synthetic data to try on
ehi_data <- data.frame(
  ehi_01 = c(2L, 2L, -2L, 1L, 2L), 
  ehi_02 = c(2L, 1L, -2L, 1L, 2L), 
  ehi_03 = c(2L, 0L, -1L, 0L, 1L), 
  ehi_04 = c(2L, -1L, -2L, -1L, 1L), 
  ehi_05 = c(2L, 0L, -1L, 1L, 1L),
  ehi_06 = c(1L, 0L, -1L, 0L, 1L), 
  ehi_07 = c(2L, 2L, -1L, 0L, 1L), 
  ehi_08 = c(1L, 2L, 1L, -1L, 1L), 
  ehi_09 = c(2L, 1L, -2L, -1L, 1L),
  ehi_10 = c(2L, 0L, -1L, 0L, 1L)
  )

ehi_data
```

```{r}
ehi_data %>% 
  ehi_compute_lq()
```

These values can then be categorized into the two different laterality factors we have available.

```{r}
ehi_data %>% 
  ehi_compute_lq() %>% 
  ehi_factorise_lq()

ehi_data %>% 
  ehi_compute_lq() %>% 
  ehi_factorise_lqa()
```

### Combine EHI results into a data.frame
In most cases, people will want to add the data derived from the `ehi` functions directly into their data.frame.
This is in most cases best done using `dplyr::mutate`.

```{r}
ehi_data %>% 
  mutate(
    ehi_lq = ehi_compute_lq(ehi_data),
    ehi_nominal = ehi_factorise_nominal(ehi_01),
    ehi_lq_cat = ehi_factorise_lq(ehi_lq),
    ehi_lqa_cat = ehi_factorise_lqa(ehi_lq),
  )
```

Because this is a little cumbersome to remember, a convenience function is made that will add columns using this naming convention.

```{r}
ehi_data %>% 
  ehi_compute()
```



## References
```{r child=paths$references, eval = TRUE} 
```
