---
title: "BayesPower: Output"
output:
  html_document: default
fontsize: 12pt
params:
  x: NA
  dat: NA
  pc_t1: NA
  rela_t1: NA
geometry: margin=2cm
classoption: a4paper
---

A Bayes Factor design analysis for one-sample/paired t-test 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_t1_code(params$x))
cat("\n```")


```

**Hypothesis**

```{r echo=FALSE, results='asis'}
if (params$x$interval == 1) {
  cat("\\(\\mathcal{H}_0: \\delta = 0\\) vs ")

  cat(switch(
    params$x$hypothesis,
    ">" = "\\(\\mathcal{H}_1: \\delta > 0\\)\n",
    "<" = "\\(\\mathcal{H}_1: \\delta < 0\\)\n",
    "\\(\\mathcal{H}_1: \\delta \\neq 0\\)\n"
  ))
} else if (params$x$interval == 2) {
  # Extract epsilon values
  hyp <- params$x$hypothesis
e <- params$x$e

eps <- switch(hyp,
  ">"  = list(eps_neg = 0,       eps_pos = e),
  "<"  = list(eps_neg = e,       eps_pos = 0),
  "!=" = list(eps_neg = e[1],    eps_pos = e[2]),
  list(eps_neg = NA,             eps_pos = NA)  # default/fallback
)

cat(sprintf("\\(\\mathcal{H}_0: \\delta \\in \\{ %.2f, %.2f \\} \\) vs ", eps[1], eps[2]))

cat(sprintf("\\(\\mathcal{H}_1: \\delta \\notin \\{ %.2f, %.2f \\} \\)", eps[1], eps[2]))

  

  
  
}

```

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

cat(paste0(params$x$model,"(location = ", params$x$location,", scale = ",params$x$scale)
    )
if (params$x$model == "t-distribution"){
  cat(paste0(", df = ",params$x$dff),")")
}else cat(paste0(")"))

```


```{r results='asis', echo=FALSE}
if (params$x$de_an_prior == 0) {
  cat("**Design prior**  \n")
  
  if (params$x$model_d == "Point") {
    cat(sprintf("Point(location = %s)  \n", params$x$location_d))
  } else {
    cat(sprintf("%s(location = %s, scale = %s", 
                params$x$model_d, 
                params$x$location_d, 
                params$x$scale_d))
    
    if (params$x$model_d == "t-distribution") {
      cat(sprintf(", df = %s)\n", params$x$dff_d))
    } else {
      cat(")\n")
    }
  }
}
```



**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$x$D, '\\, | \\, \\mathcal{H}_1) & ', round(params$dat[1,1], 3), ' \\\\
  \\text{p(BF}_{01} > ', params$x$D, '\\, | \\, \\mathcal{H}_0) & ', round(params$dat[1,3], 3), ' \\\\
  \\textbf{Probability of Misleading Evidence} & \\\\
  \\hline
  \\text{p(BF}_{01} > ', params$x$D, '\\, | \\, \\mathcal{H}_1) & ', round(params$dat[1,2], 3), ' \\\\
  \\text{p(BF}_{10} > ', params$x$D, '\\, | \\, \\mathcal{H}_0) & ', round(params$dat[1,4], 3), ' \\\\
  \\textbf{Required Sample Size} & \\\\
  \\hline
  \\text{N} & ', params$dat[1,5], ' \\\\
  \\end{array}'
)

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

cat("\n CSV format \n")

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

# Remove the D column if you want (assuming D is params$x$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$x$pc) || isTRUE(params$x$rela)) {
  cat("\\newpage\n\n")
}
```



```{r results='asis', echo=FALSE,  fig.width= 12, fig.height= 8}
if (params$x$pc && !is.null(params$pc_t1)) {

      cat("**Power Curve**\n\n")

}

```

```{r results='asis', echo=FALSE,  fig.width= 12, fig.height= 8}
if (params$x$pc && !is.null(params$pc_t1)) {

  # Print the plot
  print(params$pc_t1)
}

```

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

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

```
