## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 7,
  fig.height = 4.5,
  message = FALSE,
  warning = FALSE
)
library(speccurvieR)

## -----------------------------------------------------------------------------
data(bottles)
names(bottles)

## -----------------------------------------------------------------------------
s <- sca(y = "Salnty", x = "T_degC",
         controls = c("O2Sat", "ChlorA", "NO2uM", "SiO3uM"),
         data = bottles, progress_bar = FALSE)

dim(s)
s[1:3, c("coef", "se", "p", "sig.level")]

## -----------------------------------------------------------------------------
s_formula <- sca(Salnty ~ T_degC + O2Sat + ChlorA + NO2uM + SiO3uM,
                 data = bottles, progress_bar = FALSE)

## -----------------------------------------------------------------------------
plot_curve(s, title = "Effect of temperature on salinity")

## -----------------------------------------------------------------------------
plot_rmse(s)
plot_control_distributions(s)

## -----------------------------------------------------------------------------
plot_influence(s)

## -----------------------------------------------------------------------------
plot_coef_fit(s)

## -----------------------------------------------------------------------------
se_compare(formula = "Salnty ~ T_degC + ChlorA", data = bottles,
           types = c("iid", "HC0", "HC3"))

## -----------------------------------------------------------------------------
result <- sca_test(y = "Salnty", x = "T_degC",
                   controls = c("O2Sat", "ChlorA", "NO2uM"),
                   data = bottles, n_permutations = 199, seed = 1,
                   keep_curves = TRUE, progress_bar = FALSE)
result

## ----fig.height = 3-----------------------------------------------------------
plot_sca_test(result)

## -----------------------------------------------------------------------------
plot_sca_test_specs(result)

## -----------------------------------------------------------------------------
result_fwer <- sca_test(y = "Salnty", x = "T_degC",
                        controls = c("O2Sat", "ChlorA", "NO2uM"),
                        data = bottles, null_type = "freedman_lane",
                        n_permutations = 499, seed = 1, keep_curves = TRUE,
                        progress_bar = FALSE)
as.data.frame(result_fwer, what = "specs")

## -----------------------------------------------------------------------------
plot_sca_test_specs(result_fwer)

## -----------------------------------------------------------------------------
result_fwer <- sca_minp(result_fwer, method = "step_down")
result_fwer

## -----------------------------------------------------------------------------
tidy(result)

## -----------------------------------------------------------------------------
sca_table(result)

## -----------------------------------------------------------------------------
sca_report(result)

