## -----------------------------------------------------------------------------
library(leunbachR)
set.seed(1234) # for reproducibility of bootstrap results

## -----------------------------------------------------------------------------
d3a_path <- system.file("extdata", "data3a.csv", package = "leunbachR")
d3a <- read.delim(d3a_path, sep = ";")
head(d3a)

## -----------------------------------------------------------------------------
fit <- leunbach_ipf(d3a, verbose = FALSE)

## -----------------------------------------------------------------------------
summary(fit)

## -----------------------------------------------------------------------------
print(fit)

## -----------------------------------------------------------------------------
orb <- analyze_orbits(fit)
summary(orb)
print(orb)

## -----------------------------------------------------------------------------
plot(orb)
plot(orb, type = "significant")

## -----------------------------------------------------------------------------
get_orbit(orb, total_score = 5)

## -----------------------------------------------------------------------------
leunbach_equate(fit, direction = "1to2")

## -----------------------------------------------------------------------------
boot <- leunbach_bootstrap(fit, n_cores = 4, verbose = TRUE, nsim = 100)

## -----------------------------------------------------------------------------
print(boot)

## -----------------------------------------------------------------------------
get_equating_table(boot)

## -----------------------------------------------------------------------------
write.csv(get_equating_table(boot),
          file = file.path(tempdir(), "eqtable.csv"),
          row.names = FALSE)

## -----------------------------------------------------------------------------
d1_path <- system.file("extdata", "data1.csv", package = "leunbachR")
d1 <- read.delim(d1_path, sep = ";")
head(d1)

## -----------------------------------------------------------------------------
fit_ab <- leunbach_ipf(d1[,c(1,2)])
fit_bc <- leunbach_ipf(d1[,c(2,3)])

## -----------------------------------------------------------------------------
indirect1 <- leunbach_indirect_equate(fit_ab, fit_bc,
                                     direction_ab = "1to2",
                                     direction_bc = "1to2")
print(indirect1)

## -----------------------------------------------------------------------------
id1table <- indirect1[["equating_table"]]

## -----------------------------------------------------------------------------
boot_indirect1 <- leunbach_indirect_bootstrap(fit_ab, fit_bc,
                                             direction_ab = "1to2",
                                             direction_bc = "1to2",
                                             nsim = 100,
                                             verbose = TRUE, n_cores = 4)

## -----------------------------------------------------------------------------
print(boot_indirect1)
summary(boot_indirect1)

## -----------------------------------------------------------------------------
indirect_table <- get_indirect_equating_table(boot_indirect1)
indirect_table
write.csv(indirect_table,
          file = file.path(tempdir(), "indirect_table.csv"),
          row.names = FALSE)

## -----------------------------------------------------------------------------
plot(boot_indirect1, type = "equating")

## -----------------------------------------------------------------------------
plot(boot_indirect1, type = "see")

