---
title: "Rmarkdown intro"
author: "The ASTA Team"
output:
  html_document:
    fig_height: 3
    fig_width: 5
    theme: cerulean
    highlight: tango
  pdf_document:
    fig_height: 3
    fig_width: 5
---


# Quantitative data
We shall again use the `mosaic` package, so we first load it into R:
```{r results="hide", message=FALSE}
library(mosaic)
```


## Data set
We again consider the dataset called `BrainSize`. We first load it into R:
```{r}
BrainSize = read.delim("https://asta.math.aau.dk/datasets?file=BrainSize.txt")
```

Recall the variables in the data frame by using the `head()` function:
```{r}
head(BrainSize)
```

We can extract columns (vectors) from a data frame with the `$` operator:
```{r}
height = BrainSize$Height # Extracting the 'Height' column from data frame 'BrainSize' and naming it 'height'
mean(height)
```


## Numerical summaries
We can also summarize the `Height` by `Gender` numerically with the `favstats` function: 

```{r}
favstats(Height ~ Gender, data = BrainSize)
```

As we have already guessed, the mean height of men is larger than the mean of women height.

We can also use the `mean` function to extract the means directly:

```{r}
mean(Height ~ Gender, data = BrainSize)
```

### Exercises

Consider the BrainSize data.

- What is the mean value of the Weight variable?
- What is the mean value of the Weight variable for each group of the Gender variable?
- How many females weigh $146$?

## Visualizing Data

### Boxplots

```{r}
gf_boxplot(Height ~ Gender, data = BrainSize)
```

```{r}
gf_boxplot(Weight ~ HeightIntervals | Gender, data = BrainSize)
```

### Normal Q-Q plots

We can also draw a Q-Q plot of the variable ´Height´:

```{r}
qqnorm(BrainSize$Height)
qqline(BrainSize$Height)
```

### Exercises

Consider the BrainSize data.

- Use the function `gf_point` from `mosaic` to plot `Weight` against `Height` with a different color for each `Gender` (fill in the missing code).

```{r}
# gf_point( ... ~ ..., col = ~Gender, data = BrainSize)
```

- Do the same, but with separate plots for males and females (fill in the missing code).

```{r}
# gf_point( ... ~ ... | ..., data = BrainSize)
```

- Do you see a different picture for males and females? 

- Draw a normal Q-Q plot of the variable ´Weight´. Is it reasonable to assume that the variable follows a normal distribution?

```{r}
# qqnorm(...)
# qqline(...)
```

