---
title: "Übung 4"
author: "Vitaly Belik"
output:
  html_document:
    depth: 3
    fig_caption: yes
    highlight: tango
    number_sections: yes
    theme: paper
    toc: yes
  pdf_document:
    toc: yes
---




```{r, echo=FALSE, message=FALSE, warning=FALSE}
#Install the relevant libraries - do this one time
#install.packages("data.table")
#install.packages("dplyr")
#install.packages("formattable")
#install.packages("tidyr")
#Load the libraries
library(data.table)
library(dplyr)
library(formattable)
library(tidyr)
library(ggplot2)
```


# Katzen

```{r,echo = F, out.width="80%", warning=FALSE}
library(ggplot2)
library(gmodels)
theme_update(text = element_text(size=20))
# df <- read.delim('/Users/vitaly/Lehre/WS1920/Beuth/Data files/cats.dat', header = TRUE)
df <- read.table('/Users/vitaly/Lehre/WS1920/Beuth/Data files/cats.dat', sep = "\t", header = TRUE)
CrossTable(df$Training, df$Dance, fisher = T, chisq = T, expected = T, sresid = T)
```

# Korrelationskoeffizient

```{r}
df1 <- read.table('/Users/vitaly/Lehre/WS1920/Beuth/4_Statistische_Tests_and_Regression/Data/Data files/Album Sales 2.dat', sep = '', header = TRUE)
cor(df1$sales, df1$adverts)
library(ggplot2)
ggplot(data = df1, aes(x = adverts, y = sales)) + geom_point() +
  geom_smooth(fill = NA, color = "red", size = 1, method = "lm")

cor(df1$sales, df1$airplay)
ggplot(data = df1, aes(x = airplay, y = sales)) + geom_point() +
  geom_smooth(fill = NA, color = "red", size = 1, method = "lm")

cor(df1$adverts, df1$airplay)
ggplot(data = df1, aes(x = airplay, y = adverts)) + geom_point() +
  geom_smooth(fill = NA, color = "red", size = 1, method = "lm")

cor(df1)

cor(df1, method = 'spearman')

```
# Corrgram package

```{r}
library(corrgram)

corrgram(df1)

corrgram(df1, lower.panel = panel.ellipse, upper.panel = panel.pts, diag.panel = panel.density)

corrgram(df1, lower.panel = panel.pie, upper.panel = panel.pts, diag.panel = panel.density)

df2 <- read.table('/Users/vitaly/Lehre/WS1920/Beuth/2_Deskriptive_Statistik/Data/titanic.csv', sep = ',', header = TRUE)

corrgram(df2, lower.panel = panel.pie, upper.panel = panel.pts, diag.panel = panel.density)

```
