---
title: |
  | Doggy Demographics: 
  | Discerning Dimensions of Depth, Dye, and Dartiness
author: "Collin Nolte"
output: pdf_document
---


```{r setup, include=FALSE}
## A few things to note:

# echo = FALSE will make it so code does not print out
# message = FALSE and warning = FALSE hides startup messages
# fig.width and fig.height control figure size
# fig.align = 'center' will center them all

knitr::opts_chunk$set(echo = FALSE, message = FALSE, 
                      warning = FALSE, fig.align = 'center', 
                      fig.width = 6, fig.height = 3)
```

```{r}
## Code block to load packages and read in data
# (note that because echo = FALSE, this will not show up in final document)

library(ggplot2)
library(dplyr)

# Change theme to make it look much nicer
theme_set(theme_bw())

dogs <- read.csv("https://collinn.github.io/data/dogs.csv")
```


## Introduction

My first paragraph will be an introduction to my report, including broad-stroke information about my study and my goals. In for this particular study, there are primarily two research questions that I have. The first asks if the size and color of dogs are independent, while the second asks if dogs differ in how fast they are, based on their size. Notice how my report starts with regular text, too -- there are no messages, warnings, or R code that appear anywhere.

Next, I will describe the data I have and how it was collected. For example, for this study I visited several parks, befriending various canines until I had collected data on 400 individual observations. For each dog, I recorded the dog's breed, its size, color, and the highest speed obtained in a one hundred meter dash, measured in miles per hour. As one of my primary research questions relates to size and color, I have included summary information below. I don't have to include formatted summary tables, but if I wanted to, the Rmd file associated with this document shows how to create this one (included on the course webpage).

```{r}
## Packages for HTML/PDF tables in markdown
# install.packages(c("knitr", "kableExtra"))
library(knitr)
library(kableExtra)

# Step 1: Create table with table()
tab <- with(dogs, table(size, color))

# Step 2: Put in kable() function with caption (kable = knit table)
kab <- kable(tab, caption = "Table with size and color")

# Step 3: kable_styling() allows you to modify appearance
kable_styling(kab, full_width = FALSE)
```

As the relationship between size and speed makes up our second research question, I have presented a plot demonstrating this association below.

```{r}
ggplot(dogs, aes(speed, y = size, fill = size)) + 
  geom_boxplot() +
  scale_fill_brewer(palette = "Pastel1") +
  theme(legend.position = "bottom")
```


## Methods

My first research question addresses the issue of independence between the size of a dog and its color. As these are both qualitative variables, I will be conducting a $\chi^2$ test of independence at a significance level of $\alpha = 0.05$. I should note that if I try and copy $\alpha$ or $\chi^2$ directly into my document, I will *not* be able to get it to knit. Instead, I should look at the Rmd file to see how these symbols are created using Latex.

My second research question asks if there is any difference in speed between the different sizes of dogs. As this question involves both a categorical variable and a quantitative variable, I have a number of options available. First, I could do a simple ANOVA to test the hypothesis

$$
% Percent sign is a comment in latex
% Note that the double \$\$ above and below this text allows me to create a mathematical expression
% on its own line in the document.
H_0: \mu_1 = \mu_2 = \mu_3.
$$

Alternatively, I could could use linear regression to see if there is an association or not. Because I am a man of rather refined taste, I have decided on using ANOVA, again testing at the $\alpha = 0.05$ level.

## Results

Generally speaking, there will seldom be an occasion in which it is appropriate to include raw R output, including output from statistical tests. For example, our first test is a $\chi^2$ test of independence. I can see the Rmd file that I have conducted this test *without* printing the output into R. From this test, I should write out the results directly.

```{r, include = FALSE, echo = FALSE}
## Notice that I am not printing this into my document
tab <- with(dogs, table(size, color))
chisq.test(tab)
```

In testing our first hypothesis, that is, the independence of size and color of our dogs, we derive a $\chi^2$ test statistic of $\chi^2 = 112$ with 6 degrees of freedom, resulting in a $p$-value of $p < 0.0002$. As $p < \alpha = 0.05$, we handedly reject the null hypothesis that size and color are independent. 

Next we consider an ANOVA model to investigate whether or not there are differences in group means in speed between dogs of different sizes.

```{r, echo = FALSE, include = FALSE}
aov(speed ~ size, dogs) %>% summary()
```

Our ANOVA results in an F statistic of $F = 1.9$ with 2 and 397 degrees of freedom, giving us a $p$-value of $p = 0.15$. As $p > \alpha$, we fail to reject our hypothesis that dogs of each size have the same average speed. Note further that it is completely acceptable to have a statistical test that does not reject our null hypothesis.

## Discussion

We started this study in pursuit of two questions: is the size and color of a dog independent, and is there evidence to suggest that dogs differ in their average speed, given their size. Based on our statistical tests, we have concluded that there does appear to be an association between size and color, while there is no evidence of any relationship between size and speed. Both of these outcomes are surprising in that both are contrary to what we expected to be true prior to beginning our study. Although there are no statistical tests to confirm this, these results appear to suggest that perhaps this data has been artificially generated, lending support to the theory that we do indeed live in a simulation.










