---
title: "Getting Started with SQUIRE"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Getting Started with SQUIRE}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

```{r setup}
library(SQUIRE)
```

## Introduction

SQUIRE (Statistical Quality-Assured Integrated Response Estimation) provides a structured workflow for biological parameter estimation that combines statistical validation with systematic testing of constraint configurations.

## Basic Usage

Here's a simple example using synthetic germination data:

```{r example, eval=FALSE}
# Generate example data
set.seed(123)
germination_data <- data.frame(
  time = rep(0:7, times = 12),
  treatment = rep(c("Control", "Inhibitor", "Promoter"), each = 32),
  replicate = rep(rep(1:4, each = 8), times = 3),
  response = c(
    # Control: normal germination
    rnorm(32, mean = rep(seq(0, 80, length.out = 8), 4), sd = 3),
    # Inhibitor: reduced germination
    rnorm(32, mean = rep(seq(0, 60, length.out = 8), 4), sd = 3),
    # Promoter: enhanced germination
    rnorm(32, mean = rep(seq(0, 95, length.out = 8), 4), sd = 3)
  )
)

# Run SQUIRE analysis
results <- SQUIRE(
  data = germination_data,
  treatments = c("Control", "Inhibitor", "Promoter"),
  control_treatment = "Control",
  verbose = FALSE
)

# Check results
if (results$optimization_performed) {
  print("Optimization was performed. Parameter estimates:")
  print(results$parameters$parameter_matrix)
} else {
  print(paste("Optimization not performed:", results$validation_results$reason))
}
```

## Understanding the Workflow

SQUIRE follows a three-step process:

### Step 1: Statistical Validation
- Tests for significant treatment effects using ANOVA
- Calculates effect sizes
- Only proceeds if effects are statistically significant

### Step 2: Constraint Configuration Testing
- Systematically tests combinations of:
  - **T**: Log-scale constraints
  - **P**: Positive domain constraints
  - **E**: Euclidean (unconstrained) parameters
- Selects the configuration that best fits the data

### Step 3: Geometry-Aware Optimization
- Applies the selected constraints during optimization
- Uses GALAHAD for trust-region methods
- Returns parameter estimates for each treatment

## Interpreting Results

The results include:

- **optimization_performed**: Whether optimization proceeded (based on validation)
- **validation_results**: Statistical test results and p-values
- **parameters**: Matrix of optimized parameters for each treatment
- **galahad_settings**: The constraint configuration used

## Applications

SQUIRE is designed for:

- Germination studies
- Growth curve analysis
- Enzyme kinetics
- RT-QuIC kinetic analysis
- Dose-response studies

Any time-series biological data with treatment comparisons can benefit from SQUIRE's systematic approach to parameter estimation.
