---
format:
  pdf:
    geometry:
      - top=19mm
      - left=17mm
      - right=17mm
      - bottom=22mm
    include-in-header: 
      text: |
       \usepackage[yyyymmdd,hhmmss]{datetime}
       \renewcommand{\dateseparator}{-}
       \usepackage{fancyhdr}
       \usepackage{lastpage}
       \usepackage{float}
       \usepackage{booktabs}
       \usepackage{soul}
       \usepackage{makecell}
       \usepackage{longtable}
       \usepackage{colortbl}
       \usepackage{fontspec}
       \setmainfont{Calibri}
       \newtheorem{priklad}{Príklad}
       \usepackage{animate}
       \usepackage{ragged2e}
       \usepackage{caption}
       \captionsetup{justification=raggedright,singlelinecheck=false}
       \usepackage{booktabs}
code-line-numbers: true
code-block-bg: true
code-block-border-left: "#E0EEEE"
code-block-size: 8pt
highlight-style: github
fontsize: 11pt
editor: source
number-sections: false
lang: sk
fig-align: left
---

\begin{titlepage}
\begin{center}

\vspace*{1cm}

\Huge 
\textbf{Číslo a názov predmetu}

\vspace{0.5cm}

\LARGE 
Projekt/Domáca úloha

\vspace{1.5cm}

Meno Priezvisko (UČO)

\vspace{1.5cm}

\includegraphics[angle=0,width=0.35\textwidth]{ustavmatematikyastat-lg-cze-rgb}

\vfill

\vspace{0.8cm}

\Large
Názov a skratka odboru

Přírodovědecká fakulta, Masarykova Univerzita

\today

\end{center}
\end{titlepage}

\newpage

\pagestyle{fancy} 
\fancyhf{}
\fancyhead[C]{\bfseries Projekt z predmetu Číslo a názov predmetu}
\fancyhead[R]{}
\fancyfoot[L]{Meno Priezvisko, \today}
\fancyfoot[R]{\includegraphics[angle=0,width=0.07\textwidth]{muni-lg-rgb}}

\tableofcontents

\newpage

\pagestyle{fancy} 
\fancyhf{}
\fancyhead[L]{\bfseries Projekt z predmetu Číslo a názov predmetu}
\fancyhead[R]{\thepage\ of \pageref{LastPage}}
\fancyfoot[L]{Meno Priezvisko, \today}
\fancyfoot[R]{\includegraphics[angle=0,width=0.07\textwidth]{muni-lg-rgb}}

\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0.5pt}

\setcounter{page}{1}

```{=html}
<style type="text/css">
caption, .table-caption {
  text-align: left;
}
</style>
```

```{r}
#| echo: FALSE
#| warning: FALSE
#| label: priklad_00
# nacitanie kniznic
library(knitr)
library(tidyverse)
library(kableExtra)
library(ggplot2)
library(gganimate)
library(extrafont)
```

# Pokyny

1. Tento vzor DÚ (ďalej \textit{template}) premenujte na \texttt{UCO-priezvisko-meno-predmet-2024.qmd} s Vaším UČO, priezviskom a menom.
2. Uložte logá \texttt{ustavmatematikyastat-lg-cze-rgb.png}, \texttt{muni-lg-rgb.png} a \texttt{Rlogo.png} do rovnakého adresára, ako súbor \texttt{UCO-prijmeni-jmeno-predmet-2024.qmd}.
3. Jazyk -- Ak píšete po slovensky, ponechajte v hlavičke "\texttt{lang: sk}". Ak píšete po česky, zameňte "\texttt{lang: sk}" za \texttt{lang: cs}.
4. Premenujte text na titulnej strane -- Číslo a názov predmetu, Meno Priezvisko (UČO) a Názov a skratka odboru.
5. Premenujte text v hlavičke a pätičke -- Číslo a názov predmetu a Meno Priezvisko.
6. Aktualizujte zoznam \includegraphics[angle=0,width=0.025\textwidth]{Rlogo.png}-knižníc v prvom bloku \includegraphics[angle=0,width=0.025\textwidth]{Rlogo.png}-kódu.
7. Nastavte \textit{execution options} v hlavičke podľa potreby pomocou <https://quarto.org/docs/computations/execution-options.html> alebo individuálne v každom bloku s \includegraphics[angle=0,width=0.025\textwidth]{Rlogo.png}-kódom.
8. Diakritika v opiskách obrázkov -- Príkaz \texttt{pdf.options(encoding = "CP1250")} musí byť prítomný v každom bloku s \includegraphics[angle=0,width=0.025\textwidth]{Rlogo.png}-kódom, aby sa správne zobrazovala diakritika v opiskách. 
9. Nastavenie bloku s \includegraphics[angle=0,width=0.025\textwidth]{Rlogo.png}-kódom v obrázkoch -- Nastavenie "\texttt{fig-asp: 1}" ponechajte, ak chcete mať pomer rozmerov osí obrázka rovnaký, inak modifikujte. Nastavenie "\texttt{layout-ncol: k}" ponechajte, ak chcete mať počet obrázkov vedľa seba $k=1,2,3$ (dole v templáte nastavené všetky možnosti), inak modifikujte. Nastavenia "\texttt{fig-height: 4}" a "\texttt{fig-width: 4}" odporúčam ponechať, rovnako aj nastavenie veľkosti písma v legende (\texttt{legend()}) a texte okolo osí (\texttt{mtext()}).
10. Tabuľky -- Pozor na \texttt{escape character} spätné lomítko. V hlavičkách tabuliek a názvoch stĺpcov s \LaTeX\ syntaxou sa používajú dve spätné lomítka (viď funkciu \texttt{kable()} a argument \texttt{col.name} nižšie), v pätičkách tabuľky štyri spätné lomítka (viď funkciu \texttt{kable()} a argument \texttt{footnote} nižšie).
12. Formátovanie čísel -- Zaokrúhľujte rozumne. Do textu a tabuliek formátujte čísla pomocou funkcie \texttt{format(cislo, digits = A, nsmall = B)}, kde \texttt{A} a \texttt{B} nastavte podľa potreby.
13. Text v sekcii Pokyny po dokončení domácej úlohy (projektu) vymažte.
14. Po vygenerovaní finálnej verzie domácej úlohy (projektu), odovzdávate dva súbory 

- \texttt{UCO-priezvisko-meno-predmet-2024.qmd} a 
- \texttt{UCO-priezvisko-meno-predmet-2024.pdf}.

# Riešenie príkladu 1
\begin{priklad}[silofunkcia jednovýberového testu o $\sigma^2$] Nakreslite silofunkciu jednovýberového testu $\sigma^{2}=\sigma_{0}^{2}$ oproti $\sigma^{2}\neq \sigma_{0}^{2}$, kde $1-\beta \left(\sigma^{2}\right)=1-\Pr\left(\frac{\sigma_{0}^{2}}{\sigma^{2}}t^{(l)}_{\alpha/2}<F^{(\text{alt})}<\frac{\sigma_{0}^{2}}{\sigma^{2}}t^{(u)}_{\alpha/2}\right)$.
\end{priklad}

Vzorec v prostredí \texttt{inline} $\sigma^2$.

Vzorec v prostredí \texttt{equation}
\begin{equation*}
\frac{1}{j(j+1)}\left( j\alpha_{j+1}-\sum_{t=1}^j \alpha_t\right)=\frac{1}{j+1}\left( \alpha_{j+1}-\frac{1}{j}\sum_{t=1}^j
\alpha_t\right)= \frac{1}{j+1}\left( \mu_{j+1}-\frac{1}{j}\sum_{t=1}^i \mu_t\right).
\end{equation*}
Vzorec v prostredí \texttt{split}
$$
\begin{split}
\frac{1}{j(j+1)}\left( j\alpha_{j+1}-\sum_{t=1}^j \alpha_t\right)&=\frac{1}{j+1}\left( \alpha_{j+1}-\frac{1}{j}\sum_{t=1}^j
\alpha_t\right)\\ &= \frac{1}{j+1}\left( \mu_{j+1}-\frac{1}{j}\sum_{t=1}^i \mu_t\right).
\end{split}
$$
```{r}
#| echo: TRUE
#| warning: FALSE
#| label: priklad_01_01
# H01
"Chipower11" <- function(ratio, n, alpha) {
  pchisq(qchisq(alpha/2, n - 1)/ratio, n - 1) +
    1 - pchisq(qchisq(1 - alpha/2, n - 1)/ratio, n - 1)
}
```

::: {#fig-01-01}
```{r}
#| echo: FALSE
#| warning: FALSE
#| label: priklad_01_02
#| fig-asp: 1
#| layout-ncol: 3
#| fig-height: 4
#| fig-width: 4
#| out-width: "99%"
#| fig-align: "center"
pdf.options(encoding = "CP1250")
# layout na tri obrázky
par(mar = c(6.8, 5, 1, 1))
# par(mfcol = c(1, 3), mar = c(6.8, 5, 1, 1))

x <- seq(0.01, 10, by = 0.01)
sila <- Chipower11(x, 10, 0.01)
plot(x, sila, type = "n", ylab = "", xlab = "", xlim = c(0, 6))
curve(Chipower11(x, 10, 0.05), 0.01, 6, lty = 1, add = TRUE)
curve(Chipower11(x, 20, 0.05), 0.01, 6, lty = 2, add = TRUE)
legend("bottomright", paste("n = ", seq(10, 20, length = 2), sep = ""),
       lty = 1:2, bty = "n", cex = 1.3
)
mtext("silofunkcia", side = 2, line = 3, cex = 1.3)
mtext(expression(paste(sigma^2/sigma[0]^2)), side = 1, line = 4, cex = 1.3)
mtext(
  expression(paste(H[11]:sigma^2 != sigma[0]^2, ", ", alpha == 0.05)),
  side = 1, line = 6, cex = 1.3
)

plot(x, sila, type = "n", ylab = "", xlab = "", xlim = c(0, 6))
curve(Chipower11(x, 10, 0.05), 0.01, 6, lty = 1, add = TRUE)
curve(Chipower11(x, 20, 0.05), 0.01, 6, lty = 2, add = TRUE)
legend("bottomright", paste("n = ", seq(10, 20, length = 2), sep = ""),
       lty = 1:2, bty = "n", cex = 1.3
)
mtext("silofunkcia", side = 2, line = 3, cex = 1.3)
mtext(expression(paste(sigma^2/sigma[0]^2)), side = 1, line = 4, cex = 1.3)
mtext(
  expression(paste(H[11]:sigma^2 != sigma[0]^2, ", ", alpha == 0.05)),
  side = 1, line = 6, cex = 1.3
)

plot(x, sila, type = "n", ylab = "", xlab = "", xlim = c(0, 6))
curve(Chipower11(x, 10, 0.05), 0.01, 6, lty = 1, add = TRUE)
curve(Chipower11(x, 20, 0.05), 0.01, 6, lty = 2, add = TRUE)
legend("bottomright", paste("n = ", seq(10, 20, length = 2), sep = ""),
       lty = 1:2, bty = "n", cex = 1.3
)
mtext("silofunkcia", side = 2, line = 3, cex = 1.3)
mtext(expression(paste(sigma^2/sigma[0]^2)), side = 1, line = 4, cex = 1.3)
mtext(
  expression(paste(H[11]:sigma^2 != sigma[0]^2, ", ", alpha == 0.05)),
  side = 1, line = 6, cex = 1.3
)
```
Tri obrázky vedľa seba
:::
Pozri @fig-01-01.

\newpage

# Riešenie príkladu 2

\begin{priklad}[silofunkcia jednovýberového testu o $\sigma^2$] Nakreslite silofunkciu jednovýberového testu $\sigma^{2}=\sigma_{0}^{2}$ oproti $\sigma^{2}\neq \sigma_{0}^{2}$, kde $1-\beta \left(\sigma^{2}\right)=1-\Pr\left(\frac{\sigma_{0}^{2}}{\sigma^{2}}t^{(l)}_{\alpha/2}<F^{(\text{alt})}<\frac{\sigma_{0}^{2}}{\sigma^{2}}t^{(u)}_{\alpha/2}\right)$.
\end{priklad}

```{r}
#| echo: FALSE
#| warning: FALSE
#| label: tbl_02_01
#| tbl-label: tbl-01
#| tbl-cap: "Bla bla"

x <- rnorm(5)
y <- paste("riadok", 1:5, sep = " ")
Table1 <- tibble(x0 = y, x1 = x, x2 = x, x3 = x, x4 = x)
Table1 <- Table1 %>% mutate_if(is.numeric, sprintf, fmt = "%0.000f")

kable(Table1,
  format = "latex", caption = "", escape = FALSE, booktabs = TRUE, linesep = "",
  col.names = c("čas", "$n_{\\text{A}}$", "$\\%_{\\text{A}}$", 
                "$\\overline{x}_{\\text{A}}$", 
                "$\\widehat{\\sigma}_{\\text{A}}$"),
  align = "r", format.args = list(digits = 5, nsmall = 5)
) %>%
  footnote("\\\\noindent Čas v rokoch, $n_{\\\\text{A}}$.",
    general_title = "",
    threeparttable = TRUE,
    escape = FALSE,
    footnote_as_chunk = TRUE
  ) %>%
  kable_styling(latex_options = c("striped", "HOLD_position"), 
                full_width = FALSE, font_size = 8,
                position = "left") %>%
  row_spec(0, angle = 0)
```


Pozri @tbl-01.

::: {#fig-02-01}
```{r}
#| echo: FALSE
#| warning: FALSE
#| label: priklad_02_02
#| fig-asp: 1
#| layout-ncol: 3
#| fig-height: 4
#| fig-width: 4
#| out-width: "99%"
#| fig-align: "center"
pdf.options(encoding = "CP1250")

# layout na dva obrázky
par(mar = c(6.8, 5, 1, 1))
# par(mfcol = c(1, 2), mar = c(6.8, 5, 1, 1))

x <- seq(0.01, 10, by = 0.01)
sila <- Chipower11(x, 10, 0.01)
plot(x, sila, type = "n", ylab = "", xlab = "", xlim = c(0, 6))
curve(Chipower11(x, 10, 0.05), 0.01, 6, lty = 1, add = TRUE)
curve(Chipower11(x, 20, 0.05), 0.01, 6, lty = 2, add = TRUE)
legend("bottomright", paste("n = ", seq(10, 20, length = 2), sep = ""),
       lty = 1:2, bty = "n", cex = 1.3
)
mtext("silofunkcia", side = 2, line = 3, cex = 1.3)
mtext(expression(paste(sigma^2/sigma[0]^2)), side = 1, line = 4, cex = 1.3)
mtext(
  expression(paste(H[11]:sigma^2 != sigma[0]^2, ", ", alpha == 0.05)),
  side = 1, line = 6, cex = 1.3
)

plot(x, sila, type = "n", ylab = "", xlab = "", xlim = c(0, 6))
curve(Chipower11(x, 10, 0.05), 0.01, 6, lty = 1, add = TRUE)
curve(Chipower11(x, 20, 0.05), 0.01, 6, lty = 2, add = TRUE)
legend("bottomright", paste("n = ", seq(10, 20, length = 2), sep = ""),
       lty = 1:2, bty = "n", cex = 1.3
)
mtext("silofunkcia", side = 2, line = 3, cex = 1.3)
mtext(expression(paste(sigma^2/sigma[0]^2)), side = 1, line = 4, cex = 1.3)
mtext(
  expression(paste(H[11]:sigma^2 != sigma[0]^2, ", ", alpha == 0.05)),
  side = 1, line = 6, cex = 1.3
)

plot.new()

```
Dva obrázky vedľa seba
:::
Pozri @fig-02-01.

\newpage

# Riešenie príkladu 3

::: {#fig-03-01}
```{r}
#| echo: FALSE
#| warning: FALSE
#| label: priklad_03_01
#| fig-asp: 1
#| layout-ncol: 1
#| fig-height: 4
#| fig-width: 4
#| fig-align: "center"
#| out-width: "33%"
#| fig-pos: "HT"
pdf.options(encoding = "CP1250")
# layout na jeden obrázok
par(mar = c(6.8, 5, 1, 1))

x <- seq(0.01, 10, by = 0.01)
sila <- Chipower11(x, 10, 0.01)
plot(x, sila, type = "n", ylab = "", xlab = "", xlim = c(0, 6))
curve(Chipower11(x, 10, 0.05), 0.01, 6, lty = 1, add = TRUE)
curve(Chipower11(x, 20, 0.05), 0.01, 6, lty = 2, add = TRUE)
legend("bottomright", paste("n = ", seq(10, 20, length = 2), sep = ""),
       lty = 1:2, bty = "n", cex = 1.3
)
mtext("silofunkcia", side = 2, line = 3, cex = 1.3)
mtext(expression(paste(sigma^2/sigma[0]^2)), side = 1, line = 4, cex = 1.3)
mtext(
  expression(paste(H[11]:sigma^2 != sigma[0]^2, ", ", alpha == 0.05)),
  side = 1, line = 6, cex = 1.3
)

```
Jeden obrázok
:::
Pozri @fig-03-01.
\newpage

# Riešenie príkladu 4

\begin{priklad}[silofunkcia testu o strednej hodnote $\mu$, keď je $\sigma^2$ neznáma]
Predpokladajme, že $X\sim N(\mu,\sigma^2)$, kde $\sigma^2$ nepoznáme, ale predpokladáme, že $\widehat{\sigma}^2=10^2$ (kvôli simulácii) a $n=100$. Na hladine významnosti $\alpha=0.05$ testujte nulovú hypotézu $H_{01}:\mu=\mu_0$ oproti alternatíve $H_{11}:\mu\neq\mu_0$, kde $\mu_0=150$. Vytvorte animáciu zobrazujúcu zmenu polohy necentrálneho rozdelenia vzhľadom k hodnote centrálneho rozdelenia testovacej štatistiky jednovýberového testu o $\mu$ keď $\sigma^2$ nepoznáme, spolu s farebne odlišenou oblasťou kritického oboru a sily pri danej alernatíve. Zmenu hodnoty sily pri danej alernatíve, pri meniacej sa strednej hodnote $\mu = 140,141,\dots,146,146.5,\dots,153.5,154,155,\dots,160$.
\end{priklad}

::: {#fig-04-01}
```{r}
#| echo: FALSE
#| warning: FALSE
#| message: FALSE
#| label: priklad_04_01
#| fig-asp: 1
#| layout-ncol: 1
#| fig-height: 4
#| fig-width: 4
#| out-width: 2.5in
#| fig-align: "left"
#| fig-show: "animate"
#| interval: 0.05

# fig-show: "animate" fig-format: "png" animation-hook: "gifski" interval: "1/10" #| out-width: "33%" 
# pdf.options(encoding = "CP1250") 

x <- seq(0.01, 10, by = 0.01)
k <- length(x)
sila <- Chipower11(x, 20, 0.05)
DATA <- tibble(x = x, sila = sila)

# ggplot(data = DATA, mapping = aes(x = x, y = sila)) +
#   geom_line() + 
#   theme_bw() +
#   # labs(y = 'x: {frame_time}', x = expression(paste(sigma^2/sigma[0]^2))) +
#   geom_point(color = "red", alpha = 0.7, show.legend = FALSE) +
#   transition_reveal(x)
# # labs(title = expression(paste(sigma^2/sigma[0]^2), "=", sila[i],sep = ""))

par(mar = c(6.8, 5, 1, 1))
for (i in 1:k) {
  plot(x, sila, type = "n", ylab = "", xlab = "", xlim = c(0, 6))
  curve(Chipower11(x, 20, 0.05), 0.01, 6, lty = 1, add = TRUE)
  legend("bottomright", "n = 20",
       lty = 1:2, bty = "n", cex = 1.3
       )
  mtext("silofunkcia", side = 2, line = 3, cex = 1.3)
  mtext(
    expression(paste(H[11]:sigma^2 != sigma[0]^2, ", ", alpha == 0.05)),
    side = 1, line = 6, cex = 1.3
)
  points(x[i], sila[i], pch = 16, col = "red")
  mtext(expression(paste(sigma^2/sigma[0]^2)),
        side = 1, line = 4, cex = 1.3)
}

# layout na jeden obrázok
# par(mar = c(6.8, 5, 1, 1))

# x <- seq(0.01, 10, by = 0.01)
# sila <- Chipower11(x, 10, 0.01)
# plot(x, sila, type = "n", ylab = "", xlab = "", xlim = c(0, 6))
# curve(Chipower11(x, 10, 0.05), 0.01, 6, lty = 1, add = TRUE)
# curve(Chipower11(x, 20, 0.05), 0.01, 6, lty = 2, add = TRUE)
# legend("bottomright", paste("n = ", seq(10, 20, length = 2), sep = ""),
#        lty = 1:2, bty = "n", cex = 1.3
# )
# mtext("silofunkcia", side = 2, line = 3, cex = 1.3)
# mtext(expression(paste(sigma^2/sigma[0]^2)), side = 1, line = 4, cex = 1.3)
# mtext(
#   expression(paste(H[11]:sigma^2 != sigma[0]^2, ", ", alpha == 0.05)),
#   side = 1, line = 6, cex = 1.3
# )

```
Jeden obrázok
:::
Pozri @fig-04-01.


```{r}
#| echo: FALSE
#| warning: FALSE
#| label: priklad_04_02

x <- rnorm(5)
y <- paste("riadok", 1:5, sep = " ")
Table1 <- tibble(x0 = y, x1 = x, x2 = x, x3 = x, x4 = x)
Table1 <- Table1 %>% mutate_if(is.numeric, sprintf, fmt = "%0.000f")

kable(Table1,
  format = "latex", caption = "Bla bla tabuľka B", escape = FALSE, booktabs = TRUE, linesep = "",
  col.names = c("čas", "$n_{\\text{A}}$", "$\\%_{\\text{A}}$", 
                "$\\overline{x}_{\\text{A}}$", 
                "$\\widehat{\\sigma}_{\\text{A}}$"),
  align = "r", format.args = list(digits = 5, nsmall = 5)
) %>%
  footnote("\\\\noindent Čas v rokoch, $n_{\\\\text{A}}$.",
    general_title = "",
    threeparttable = TRUE,
    escape = FALSE,
    footnote_as_chunk = TRUE
  ) %>%
  kable_styling(latex_options = c("striped", "HOLD_position"), 
                full_width = FALSE, font_size = 8,
                position = "left") %>%
  row_spec(0, angle = 0)
```
