```{r data generation, echo = FALSE, results = "hide"}
library("exams")
library("exams.forge")
instruction <- NULL
#points
points4 <- 1
#Variables
n <- 6
x <- sample(-9:9,6)
y <- x+sample(0:2,6,replace=TRUE)
x[6] <- 0-sum(x[1:5])
y[6] <- 0 - sum(y[1:5])
sumXi <- sum(x)
sumYi <- sum(y)
sumYi2 <- sum(y^2)
sumXiYi <- sum(x*y)
sumXi2 <- sum(x^2)
tab  <- cbind(x,y)
colnames(tab) <- c("$X$", "$Y$")
row.names(tab) <- 1:n
htab <- html_matrix_sk(tab, "$i$", fmt=rep("%i", ncol(tab)))
#part (c)
R2 <- round(((n*sumXiYi - sumXi*sumYi)^2)/((n*sumXi2 - (sumXi)^2)*(n*sumYi2 - (sumYi)^2)),4)
strp   <- num2str(sumXi, sumYi, sumXiYi, sumXi2, sumYi2, R2)
sc <- num_result(R2, 3)
```

Question
========

```{r, error=TRUE, child=instruction}
```

Untersuchen Sie den linearen Zusammenhang zwischen den Variablen X und Y anhand der folgenden Daten aus einer Umfrage: 

```{r, echo=FALSE, results='asis'}
cat(toHTMLorLatex(htab))
```

Berechnen Sie das Bestimmtheitsmaß. `r round_de(sc$digits)`.


Solution
========

\begin{align*}
R^2 &= \dfrac{ \left(  `r n` \cdot \sum\limits_{i=1}^{ `r n`} x_i y_i - \sum\limits_{i=1}^{ `r n`} x_i \cdot \sum\limits_{i=1}^{ `r n`} y_i \right)^2 }{ \left[  `r n` \cdot \sum\limits_{i=1}^{ `r n`} x_i^2 - \left( \sum\limits_{i=1}^{ `r n`} x_i \right) ^2 \right] \left[  `r n` \cdot \sum\limits_{i=1}^{ `r n`} y_i^2 - \left( \sum\limits_{i=1}^{ `r n`} y_i \right) ^2 \right]} \\
&= \dfrac{ \left(  `r n` \cdot  `r sumXiYi` -  `r sumXi` \cdot  `r sumYi` \right)^2 }{ \left[  `r n` \cdot  `r sumXi2` - \left(  `r sumXi` \right)^2 \right] \left[  `r n` \cdot  `r sumYi2` - \left(  `r sumYi` \right)^2 \right]} =  `r R2` \\
\end{align*}


Meta-information
================
extype: num
exsolution: `r sc$fx[1]`
extol: `r sc$tolerance`
exname: ../../statistik_i_ii/AARnw/lr_koef12_1b.Rmd
