## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
library(simglm)

## ----framework-logo, echo=FALSE, out.width="160px", fig.align="right", fig.alt="Alternative power hex logo: a distribution of simulated estimates with a highlighted tail beyond an effect threshold"----
if (identical(Sys.getenv("IN_PKGDOWN"), "true")) {
  knitr::include_graphics("figures/simglm-hex-alternative-power.png")
}

## ----threshold-simulation-----------------------------------------------------
set.seed(321)

sim_arguments <- list(
  formula = y ~ 1 + x,
  fixed = list(
    x = list(var_type = "continuous", mean = 0, sd = 1)
  ),
  error = list(variance = 1),
  sample_size = 100,
  reg_weights = c(0, 0.3),
  model_fit = list(model_function = "lm"),
  extract_coefficients = TRUE,
  replications = 500,
  power = list(thresholds = list(x = c(0.2, 0.3, 0.4)))
)

simulation_results <- replicate_simulation(sim_arguments)

threshold_results <- compute_statistics(
  simulation_results,
  sim_arguments,
  power = FALSE,
  type_1_error = FALSE,
  precision = FALSE,
  alternative_power = TRUE
)

threshold_results[
  threshold_results$term == "x",
  c("term", "threshold", "alt_power", "replications")
]

