Package 'designpower'

Title: Design Power Analysis Tools
Description: Tools for iterative power analysis and design optimization using simulation and adaptive sampling strategies.
Authors: Thierry Onkelinx [aut, cre] (ORCID: <https://orcid.org/0000-0001-8804-4216>, affiliation: Research Institute for Nature and Forest (INBO)), Research Institute for Nature and Forest (INBO) [cph, fnd] (ROR: <https://ror.org/00j54wy13>)
Maintainer: Thierry Onkelinx <[email protected]>
License: GPL-3
Version: 0.0.2
Built: 2026-06-02 09:21:49 UTC
Source: https://github.com/inbo/designpower

Help Index


Find Optimal Design

Description

Iteratively search for optimal design parameters using adaptive simulation.

Usage

find_power(
  design,
  design_digits,
  opti,
  sim_power,
  extra_args = list(),
  power = 0.9,
  alpha = 0.1,
  filename = "power.duckdb"
)

Arguments

design

List. Initial design parameters.

design_digits

Named numeric. Precision (number of decimal places) for each parameter. The names must match those in design.

opti

Character. Name of parameter to optimize.

sim_power

Function. Simulation function (should accept design and n_sim).

extra_args

List. Optional additional arguments passed to sim_power. Defaults to an empty list.

power

Numeric. Target power (default 0.9).

alpha

Numeric. Significance level (default 0.1).

filename

Character. Path to DuckDB database file.

Details

Uses DuckDB to store simulations and gradually refines design parameters to achieve target power.

Value

Numeric vector. The optimized parameter value and confidence range.

Examples

## Not run: 
find_power(
  design = list(trend = -0.03, n_site = 20, n_year = 12),
  design_digits = c(trend = 4, n_site = 0, n_year = 0),
  opti = "trend",
  sim_power = sim_power,
  extra_args = list()
)

## End(Not run)

Simple Power Simulation

Description

A basic example of a power simulation function.

Usage

sim_power(
  design = list(trend = -0.03, n_year = 12, n_sample = 20),
  n_sim = 100,
  intercept = 2,
  sigma_error = 0.1
)

Arguments

design

A named list with design parameters:

  • trend: The true trend parameter

  • n_year: Number of years

  • n_sample: Number of samples per year

n_sim

Integer. Number of simulations.

intercept

Numeric. Intercept of the model.

sigma_error

Numeric. Standard deviation of the error term.

Details

Simulates data under a simple model and returns p-values.

Value

A data frame with columns:

  • p: P-values from simulations

  • trend: Estimated trends

Examples

## Not run: 
sim_power(
  design = list(trend = -0.03, n_year = 12, n_sample = 20),
  n_sim = 10
)

## End(Not run)