---
title: "Sub-group meta-analyses of comorbid diagnoses"
output:
  html_document:
    toc: true
    toc_depth: 4
    number_sections: true
    toc_float: 
      collapsed: false
date: "`r format(Sys.time(), '%d %B %Y')`"

author:
- "**Code:** Andrew W Brown, PhD^[Indiana University - Bloomington]"
- "Sara Lappan, PhD^[University of Alabama at Birmingham]"
- "Peter Hendricks, PhD^[University of Alabama at Birmingham]"
---
##`r diagnosis`

```{r echo=long, eval=TRUE, include=TRUE}

diag.out <- suppressMessages(tryCatch(plo.rma.mv(df = diagnosis.df,
                                                 varname = "Value",
                                                 continuous = TRUE,
                                                 title = paste(diagnosis),
                                                 profile = profile,
                                                 long = long),
                                      warning = function(w) return(w$message),
                                      error = function(e) e)
)
assign(paste0("diag",d,".out"), diag.out) #assign the output to an object named for diagnosis d
if(class(diag.out) == "character"){
  diag.table <- rbind(diag.table, t(c(diagnosis,diag.out,rep("",6)))) #report error in table
  print(diag.out)
} else {
  diag.table <- rbind(diag.table, cont.table(diag.out, outname))
  print(diag.out$model)
cat(paste("\nICC:", fmt4(diag.out$ICC)))
cat(paste("\nI^2.1", fmt1(diag.out$I2[1])))
cat(paste("\nI^2.2", fmt1(diag.out$I2[2])))
  header <- 7
  names(header) <- diagnosis
  kable(diag.out$prediction, caption = diagnosis) %>% 
    add_header_above(header = header, align = 'l')%>%
  kable_styling(full_width = F)
}
```

```{r eval=TRUE, echo=FALSE, results='asis'}
if(plots & class(diag.out)!= "character"){
  plo.reg(diag.out, "Value", paste(outname, "(%)"))
  cat("<p>**Figure:** Meta-regression for '",diagnosis,"'. The solid line represents the predicted dropout rate at the given predictor value; dashed lines represent the 95% CI; dotted lines represent the 95% Prediction Interval (PI). Points are proportional to the inverse variance of the individual dropout rates.</p>")
}
```
