---
title: "Complete Example Workflow"
description: "Follow a complete analysis from data inspection through estimates, plots, and sensitivity checks."
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Complete Example Workflow}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", fig.width = 7, fig.height = 4.2)
```

This example follows the recommended sequence: inspect fieldwork, declare the
analysis, fit once, examine diagnostics, and report both the estimate and the
assumptions that support it. All main results below use the default
estimand-specific calibration.

```{r}
library(eventsurvey)
```

## Inspect coverage before fitting

```{r coverage}
fit_preview <- eventsurvey(y ~ day, sample_data)
plot(fit_preview, type = "daily")
```

The point size shows the number of respondents in a period. The default
supports sparse fieldwork by forming windows from observed survey periods.
It retains the actual dates in trend fitting and forecasting and reports any
unobserved dates rather than silently compressing a Friday-to-Monday gap.

## Prespecify the forecasting operation

We use six days for both fitting and forecasting. The default skips the event
period, so each pre-event reference exercise reproduces the same one-period
gap. With 30 pre-event days, the package can reproduce this task in
`30 - 2 * 6 = 18` rolling windows, each with six forecast errors.

```{r}
fit <- eventsurvey(y ~ day, sample_data)
summary(fit)
```

The printed summary reports missing pre-event and forecast periods and the
elapsed spans of the final fitting and forecasting windows. The object also
keeps inspectable data frames rather than only formatted output:

```{r}
fit$estimate
head(fit$days)
head(fit$reference)
head(fit$windows)
```

## Interpret the two intervals

`conventional_low` and `conventional_high` treat the linear extrapolation as
correct. `conf_low` and `conf_high` are the main honest interval. They combine
sampling uncertainty with the bounded misspecification assumption. The
`bias_bound` is the mean of the daily matching-horizon bias bounds.
The average honest interval aggregates daily intervals computed at significance
level `alpha / window` (Bonferroni). Its components are in
`fit$average_components`; ordinary daily results remain pointwise.

```{r counterfactual}
plot(fit)
```

```{r diagnostics}
plot(fit, type = "diagnostics")
```

## Minimum reporting checklist

A transparent analysis should report:

1. the event time and how within-period exposure was classified;
2. the outcome and fieldwork time variable;
3. the fit/forecast window and why it was chosen;
4. coverage and sample sizes across periods;
5. the rolling forecast errors and bias bound;
6. the window-average and period-specific estimates with honest intervals;
7. sensitivity to substantively plausible window lengths; and
8. limitations of event exogeneity and respondent-timing assumptions.

## Also see

- [Getting Started](getting-started.html) for the shortest package workflow.
- [Reading an HTML Report](reading-html-reports.html) for interpretation of the
  report produced from a fitted analysis.
- [Methodology and Assumptions](methodology.html) for the estimand,
  counterfactual restriction, and honest interval.
