---
title: "BayesPower: Output"
output:
  html_document: default
fontsize: 12pt
params:
  p2: NA
  dat: NA
  pc_p2: NA
  rela_p2: NA
geometry: margin=2cm
classoption: a4paper
---

A Bayes Factor design analysis for testing one proportion was conducted on `r Sys.time()`.The code for reproducing the results:
```{r, echo=FALSE, results='asis'}
# Generate the reproducible code

cat("```r\n")
cat(BayesPower:::show_props_code(params$p2))
cat("\n```")


```

**Hypothesis**

```{r echo=FALSE, results='asis'}
# Null hypothesis
cat(sprintf("\\(\\mathcal{H}_0: \\theta_0 = \\theta_1 = \\theta_2,\\quad \\theta_0 \\sim \\mathrm{beta}(\\alpha = %s, \\beta = %s)\\) vs ", params$p2$a0, params$p2$b0))

cat(sprintf("\\(\\mathcal{H}_1: \\theta_1 \\neq \\theta_2\\)"))


```

```{r echo=FALSE, results='asis'}
if (params$p2$de_an_prior == 1) {
  cat("**Analysis and design prior**  \n\n")
} else {
  cat("**Analysis prior**  \n\n")
}


 cat(sprintf("\\(\\theta_1 \\sim \\mathrm{Beta}(\\alpha = %s, \\beta = %s),\\quad \\theta_2 \\sim \\mathrm{Beta}(\\alpha = %s, \\beta = %s)\\)", 
            params$p2$a1, params$p2$b1, params$p2$a2, params$p2$b2))


if (params$p2$de_an_prior != 1) {
  cat("\n\n **Design prior**  \n")
  
switch(params$p2$model1,
  "Point" = {
    cat(sprintf("\\(\\theta_1 \\sim \\mathrm{Point}(\\text{location} = %s),\\quad\\)", params$p2$dp1))
  },
  "same" = {
    cat(sprintf("\\(\\theta_1 \\sim \\mathrm{Beta}(\\alpha = %s, \\beta = %s),\\quad\\)", params$p2$a1, params$p2$b1))
  },
  "beta" = {
    cat(sprintf("\\(\\theta_1 \\sim \\mathrm{Beta}(\\alpha = %s, \\beta = %s),\\quad\\)", params$p2$a1d, params$p2$b1d))
  }
)
  
  switch(params$p2$model2,
  "Point" = {
    cat(sprintf("\\(\\theta_2 \\sim \\mathrm{Point}(\\text{location} = %s)\\)", params$p2$dp2))
  },
  "same" = {
    cat(sprintf("\\(\\theta_2 \\sim \\mathrm{Beta}(\\alpha = %s, \\beta = %s)\\)", params$p2$a2, params$p2$b2))
  },
  "beta" = {
    cat(sprintf("\\(\\theta_2 \\sim \\mathrm{Beta}(\\alpha = %s, \\beta = %s)\\)", params$p2$a2d, params$p2$b2d))
  }
)
  


}

```



**Result**
```{r results='asis', echo=FALSE}
cat("\n Table format \n") 

# Your existing LaTeX table output
table_latex <- paste0(
  '\\begin{array}{l c}
  \\textbf{Probability of Compelling Evidence} & \\\\
  \\hline
  \\text{p(BF}_{10} > ', params$p2$D, '\\, | \\, \\mathcal{H}_1) & ', round(params$dat[[1]][1,1], 3), ' \\\\
  \\text{p(BF}_{01} > ', params$p2$D, '\\, | \\, \\mathcal{H}_0) & ', round(params$dat[[1]][1,3], 3), ' \\\\
  \\textbf{Probability of Misleading Evidence} & \\\\
  \\hline
  \\text{p(BF}_{01} > ', params$p2$D, '\\, | \\, \\mathcal{H}_1) & ', round(params$dat[[1]][1,2], 3), ' \\\\
  \\text{p(BF}_{10} > ', params$p2$D, '\\, | \\, \\mathcal{H}_0) & ', round(params$dat[[1]][1,4], 3), ' \\\\
  \\textbf{Required Sample Size} & \\\\
  \\hline
  \\text{N}_1 & ', params$dat[[1]][1,5], ' \\\\
  \\text{N}_2 & ', params$dat[[1]][1,6], ' \\\\
  \\end{array}'
)

cat('$$', table_latex, '$$\n\n')

cat("\n CSV format \n")

# Prepare a CSV output for dat (excluding params$rr$D)
dat_csv <- params$dat[[1]][1, ]  # assuming dat is a matrix or data frame row

# Remove the D column if you want (assuming D is params$rr$D, not in dat)
# Just print the dat row as CSV
cat("```\n")  # start of code block in markdown
write.csv(as.data.frame(t(dat_csv)), row.names = TRUE, quote = FALSE)
cat("```\n")  # end of code block in markdown
```



```{r results='asis', echo=FALSE}
if (isTRUE(params$p2$pc) || isTRUE(params$p2$rela)) {
  cat("\\newpage\n")
}
```



```{r results='asis', echo=FALSE,fig.width= 12, fig.height= 8}

if (params$p2$pc){
    cat("**Power Curve **\n\n")

}

```
```{r results='asis', echo=FALSE,fig.width= 12, fig.height= 8}

if (params$p2$pc){

print(params$pc_p2)
}

```

```{r results='asis', echo=FALSE,  fig.width= 12, fig.height= 8}
if (params$p2$rela){
    cat("**Relationship between BF and data **\n\n")

}

```

```{r results='asis', echo=FALSE,  fig.width= 12, fig.height= 8}
if (params$p2$rela){

print(params$rela_p2)
}

```


