```{r data generation, echo = FALSE, results = "hide"}
library("exams")
library("exams.forge")
instruction <- NULL
n <- sample(25:50,1)
x   <- 36:50
b_1 <- sample((-10:10)/10, 1)
b_0 <- sample(10:20, 1)
y   <- b_0+b_1*x
meanX <- round(mean(x),0)
meanY <- round(mean(y),0)
sumX <- sum(x)
sumY <- sum(y)
sumXY <- sum((x-meanX)*(y-meanY))
sumX2 <- sum((x-meanX)^2)
sumY2 <- sum((y-meanY)^2)
sumXY <- sum((x-meanX)*(y-meanY))
#part b
strp <- num2str(meanX, meanY, sumX, sumY, sumXY, sumX2, sumY2, sumXY)
sc   <- num_result(sumXY/(sqrt(sumX2*sumY2)), 4)
b_1  <- sumXY/sumX2
b_0  <- meanY - b_1*meanX
b01  <- (runif(1)<0.5)
sc   <- num_result(if(b01) b_0 else b_1, 4)
```

Question
========

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

Betrachten Sie ein (einfaches) Regressionsmodell  $y_i = b_0 + b_1 x_i + \hat{u}_i$, das die  üblichen Annahmen erfüllt. Aus der Analyse von $n=`r n`$ Datenpaaren gehen folgende Größen hervor:

\begin{align*}
\sum_{i=1}^{ `r n`} (x_i - \bar{x})(y-\bar{y}) &=  `r strp$sumXY`,\\
\sum_{i=1}^{ `r n`} (x_i -\bar{x})^2 &=  `r strp$sumX2`, \\
\sum_{i=1}^{ `r n`} (y_i -\bar{y})^2 &=  `r strp$sumY2`, \\
\bar{x}&= `r strp$meanX`, \\
\bar{y}&= `r strp$meanY`.
\end{align*}


Berechnen Sie den Parameter `r if(b01) "$b_0$" else "$b_1$"` dieses Regressionsmodells.  `r round_de(sc$digits)`.

Solution
========

\begin{align*}
b_1 &= \frac{ \sum_{i=1}^{n} (x_i - \bar{x})(y-\bar{y})}{\sum_{i=1}^{n} (x_i - \bar{x})^2} = \frac{`r strp$sumXY`}{ `r strp$sumX2`} =  `r b_1` \\
b_0 &= \bar{y} - b_1 \cdot \bar{x} =  `r strp$meanY` - (  `r b_1` ) \cdot  `r strp$meanX` =  `r b_0` \\
\end{align*}

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