```{r setup,eval=TRUE,echo=FALSE}
if (!exists("indent")) {
	indent = ''
}
if (exists("testing")) {
	testDat <- bfi %>% dplyr::select(dplyr::starts_with("BFIK_open_"))
  x = userfriendlyscience::scaleDiagnosis(testDat, 
                                          scaleReliability.ci = FALSE)
	testDat <- bfi %>% dplyr::select(dplyr::starts_with("BFIK_consc_"))
  x = userfriendlyscience::scaleDiagnosis(testDat, 
                                          scaleReliability.ci = TRUE)
}
```


`r indent` Reliability Indices

```{r}
coefs <- x$scaleReliability$output$dat %>% 
  tidyr::gather(index, estimate) %>% 
  dplyr::filter(index != "n.items", index != "n.observations") %>% 
  dplyr::mutate(index = stringr::str_to_title(
    stringr::str_replace_all(index,
      stringr::fixed("."), " ")))

cis <- coefs %>% 
  dplyr::filter(stringr::str_detect(index, " Ci ")) %>% 
  tidyr::separate(index, c("index", "hilo"), sep = " Ci ") %>% 
  tidyr::spread(hilo, estimate)
if (nrow(cis)) {
  cis <- cis %>% dplyr::rename(
    `Lower 95% CI` = .data$Lo, `Upper 95% CI` = .data$Hi
  )
}

coefs_with_cis <- coefs %>% 
  dplyr::filter(!stringr::str_detect(index, " Ci ")) %>% 
    dplyr::left_join(cis, by = "index") %>% 
    dplyr::mutate(index = dplyr::if_else(index == "Glb", "Greatest Lower Bound", .data$index)) %>% 
    dplyr::arrange(!stringr::str_detect(index, "Omega")) %>% 
    dplyr::select(Index = .data$index, Estimate = .data$estimate)


pander::pander(coefs_with_cis)
```

Positive correlations: `r x$scaleReliability$intermediate$cor.pos` out of `r x$scaleReliability$intermediate$cor.total`  (`r round(100 * x$scaleReliability$intermediate$cor.proPos)`%)


`r indent` Scatter matrix

```{r}
print(x$scatterMatrix$output$scatterMatrix)
x$scatterMatrix$output$scatterMatrix <- no_md()
```

<details><summary>Detailed output</summary>

```{r}
print(x)
```

</details>
