---
title: "Creating triangulation datasets"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Creating triangulation datasets}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

**WARNING:** This page is still under construction

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

```{r setup}
library(triangulate)
library(dplyr)
```

## Introduction

This vignette demonstrates how to create a triangulation dataset using the triangulate package. We will manually construct a small example dataset and walk through the process of preparing it for triangulation, including appending bias/indirectness values and visualizing bias directions.

## Step 1: Create the example dataset

We define a small dataset of six studies, each with a different combination of bias/indirectness type and direction.

```{r}
example_data <- tibble(
  result_id = paste0("S", 1:6),
  study = paste("Study", 1:6),
  yi = c(-.2, .25, -.1, -.3, .1, .3),
  vi = round(runif(6, 0.01, 0.05), 3),
  d1j = rep("moderate", 6),
  d1t = c(rep("add", 2), rep("prop", 4)),
  d1d = c("Favours comparator", "Favours experimental",
          "Away from null", "Towards null",
          "Away from null", "Towards null")
)

example_data
```

## Step 2: Convert to long format

Triangulation requires domain-level assessments to be in long format. We use tri_to_long() to convert from wide to long form.

```{r}
example_long <- tri_to_long(example_data)
head(example_long)
```

## Step 3: Add absolute direction

Calculate the absolute direction of bias/indirectness based on type, direction, and position of the estimate relative to the null.

```{r}
example_abs <- tri_absolute_direction(example_long)
head(example_abs)
```

## Step 4: Append bias priors

Next, we append numerical prior values (mean and SD) corresponding to domain judgments using tri_append_bias().

```{r}
example_bias <- tri_append_bias(example_abs, dat_bias_values)
head(example_bias)
```
