---
title: "BayesPower: Output"
output:
  pdf_document: default
fontsize: 12pt
params:
  ff: NA
  dat: NA
  pc_f: NA
  rela_f: NA
geometry: margin=2cm
classoption: a4paper
---

A Bayes Factor design analysis for regression/ANOVA was conducted on `r Sys.time()`.

**Hypothesis**

```{r echo=FALSE, results='asis'}
if (params$ff$inter == 1) {
  cat("\\(\\mathcal{H}_0: \\lambda^2 = 0\\) vs ")
  
  cat("\\(\\mathcal{H}_1: \\lambda^2 > 0\\)\n")
 
} else if (params$ff$inter == 2) {
  # Extract epsilon values
e <- params$ff$e

cat(sprintf("\\(\\mathcal{H}_0: \\lambda^2 \\in \\{ 0, %.2f \\} \\) vs ", e))

  cat(sprintf("\\(\\mathcal{H}_1: \\lambda^2 > {%.2f}\\)\n", e))



  
  
}

```

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

model <- params$ff$model

if (model == "tdis") {
  cat(sprintf("Effect size prior (r = %.2f, \\(f^2 = %.2f\\), df = %.2f)\n", 
              params$ff$rscale, 
              params$ff$f_m^2, 
              params$ff$dff))
} else if (model == "Moment") {
  cat(sprintf("Moment (\\(f^2 = %.2f\\), df = %.2f)\n", 
              params$ff$f_m^2, 
              params$ff$dff))
  
}

if (params$ff$de_an_prior == 0) {
  cat("\n **Design prior**  \n")
  
  
  
  model <- params$ff$model_d

if (model == "tdis") {
  cat(sprintf("Effect size prior (r = %.2f, \\(f^2 = %.2f\\), df = %.2f)\n", 
              params$ff$rscale_d, 
              params$ff$f_m_d^2, 
              params$ff$dff_d))
} else if (model == "Moment") {
  cat(sprintf("Moment (\\(f^2 = %.2f\\), df = %.2f)\n", 
              params$ff$f_m_d^2, 
              params$ff$dff_d))
  
}else if (model == "Point") {
  cat(sprintf("Point (\\(\\lambda^2 = %.2f\\))\n", 
              params$ff$f_m_d^2))
  
}

  
  
  
  
}



```

```{r results='asis', echo=FALSE}
cat("**The compared models:**  \n\n")

if (params$ff$anovareg == 1) {
   choices <- c(
    "1" = "Intercept model",
    "2" = "One-factor model",
    "3" = "Two-factor - main effect model",
    "4" = "Two-factor - interaction effect model"
  )
   
  
  
  cat("The reduced model selected: ", choices[as.character(params$ff$reduced_model)], "  \n")
  
  cat("The full model selected: ", choices[as.character(params$ff$full_model)], "  \n")
  
  if (params$ff$full_model > 1) {
    cat(sprintf("Number of levels for factor one: %.0f  \n", params$ff$f1))
  }
  
  if (params$ff$full_model > 2) {
    cat(sprintf("Number of levels for factor one: %.0f  \n", params$ff$f2))
  }
}
if (params$ff$anovareg == 2) {
   cat(sprintf("Number of predictors in the reduced model: %.0f  \n", params$ff$p))
     cat(sprintf("Number of predictors in the full model: %.0f  \n", params$ff$k))
}
```



**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$ff$D, '\\, | \\, \\mathcal{H}_1) & ', round(params$dat[1,1], 3), ' \\\\
  \\text{p(BF}_{01} > ', params$ff$D, '\\, | \\, \\mathcal{H}_0) & ', round(params$dat[1,3], 3), ' \\\\
  \\textbf{Probability of Misleading Evidence} & \\\\
  \\hline
  \\text{p(BF}_{01} > ', params$ff$D, '\\, | \\, \\mathcal{H}_1) & ', round(params$dat[1,2], 3), ' \\\\
  \\text{p(BF}_{10} > ', params$ff$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$ff$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$ff$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$ff$pc) || isTRUE(params$ff$rela)) {
  cat("\\newpage\n")
}
```


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


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

params$pc_f}

```


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

params$rela_f
}

```
