---
exname: schiefe-erkennen
extype: schoice
exsolution: r mchoice2string(d$is_correct, single = TRUE)
exshuffle: no
categories:
- eda
- distributions
- schoice
date: '2023-04-19'
slug: Schiefe-erkennen
title: Schiefe-erkennen
---
```{r libs, include = FALSE}
library(tidyverse)
library(mosaic)
library(testthat)
library(e1071)
library(glue)
```
```{r global-knitr-options, include=FALSE}
knitr::opts_chunk$set(fig.pos = 'H',
fig.asp = 0.618,
fig.width = 4,
fig.cap = "",
fig.path = "",
cache = FALSE)
```
# Aufgabe
```{r solution, echo = FALSE}
sol_set <- c("symmetrisch", "linksschief", "rechtsschief") # "gleichverteilt"
sol <- sample(sol_set, 1)
```
Wählen Sie das Histogramm, welches am deutlichsten die Eigenschaft "`r sol`" aufweist!
```{r generate-data, echo = FALSE}
n <- 1000
d_symm <- rnorm(n = n) %>% as_tibble()
d_left1 <- rbeta(n, 5, 2) %>% as_tibble()
d_right1 <- rbeta(n, 2, 5) %>% as_tibble()
d_right2 <- rexp(n, 10) %>% as_tibble()
d_left2 <- -rexp(n, 10) %>% as_tibble()
d <- tibble(
data = list(d_symm,
d_left1,
d_left2,
d_right1,
d_right2)) %>%
mutate(id = c("d", "d_left1", "d_left2", "d_right1", "d_right2"))
d <-
d %>%
mutate(skew = map(data, ~ skewness(.x[[1]]))) %>% # as .x is a tibble, we need to access its first column
mutate(skew = unlist(skew)) %>%
sample_n(size = nrow(.)) %>% # shuffle it
mutate(plot_id = LETTERS[1:nrow(.)])
```
```{r generate-solution, echo = FALSE}
d <-
d %>%
mutate(correct_plot = case_when(
sol == "rechtsschief" ~ plot_id[which.max(skew)],
sol == "linksschief" ~ plot_id[which.min(skew)],
sol == "symmetrisch" ~ plot_id[which.min(abs(skew))],
TRUE ~ NA_character_
)) %>%
mutate(is_correct = plot_id == correct_plot)
#stopifnot(d$is_correct[1] != NA) # "`is_correct` must not be NA."
```
```{r generate-histograms, echo = FALSE, message = FALSE, fig.show='hold', comment="", results="hide"}
gg_hist <- function(data, title) {
ggplot(data = data) +
aes(x = value) +
geom_histogram() +
ggtitle(glue("Diagramm {title}"))
}
map2(.x = d$data,
.y = d$plot_id,
.f = ~ gg_hist(.x, .y))
```
```{r questionlist, echo = FALSE, results = "asis"}
exams::answerlist(d$plot_id, markup = "markdown")
```
</br>
</br>
</br>
</br>
</br>
</br>
</br>
</br>
</br>
</br>
# Lösung
Das Histogramm ``r d$plot_id[d$is_correct == TRUE]`` zeigt die Eigenschaft ``r sol`
` am deutlichsten.
```{r solutionlist, echo = FALSE, results = "asis"}
exams::answerlist(ifelse(d$is_correct, "Wahr", "Falsch"), markup = "markdown")
```
---
Categories:
- eda
- distributions
- schoice