## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")

## -----------------------------------------------------------------------------
library(irtlink)

## -----------------------------------------------------------------------------
set.seed(123)
d <- sim_trend_data(n_groups = 3, N = 1000, I = 20, overlap = 1,
                    mu = c(0, 0.3, 0.5), sigma = c(1, 1.2, 1.5),
                    dif = "random", dif_pct = 1, dif_sd = 0.3)
str(d, max.level = 1)

## -----------------------------------------------------------------------------
cal <- calibrate(d)
cal

## -----------------------------------------------------------------------------
link <- link_groups(cal, approach = "chain", method = "mgm")
link$trend

## -----------------------------------------------------------------------------
link_groups(cal, approach = "chain", method = "mgm", ref = 2)$trend

## -----------------------------------------------------------------------------
linking_error(link, method = "jackknife")$le
linking_error(link, method = "sandwich_osw")$le

## -----------------------------------------------------------------------------
tr <- estimate_trend(d, calibration = "separate", approach = "chain",
                     link = "mgm", le = "sandwich_osw_bc")
round(tr$trend[, c("group", "mu", "sigma", "se", "le", "le_bc",
                   "te", "te_bc")], 3)

## -----------------------------------------------------------------------------
dif <- detect_dif(cal, method = "rmsd")
dif$flagged
head(dif$rmsd)

