Skip to contents

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.

Inspect coverage before fitting

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.

fit <- eventsurvey(y ~ day, sample_data)
summary(fit)
#> Event-during-survey analysis
#> 
#> eventsurvey(formula = y ~ day, data = sample_data)
#> 
#> Settings
#>   Fit and forecast window: 6 periods
#>   Event period: exclude 
#>   Period schedule: observed 
#>   Calibration: estimand 
#>   Missing pre-event periods: 0
#>   Missing forecast periods: 0
#>   Final fit: 6 observed periods spanning 6 period(s) on the time scale
#>   Final forecast: 6 observed periods spanning 6 period(s) on the time scale
#>   Confidence level: 95 %
#> 
#> Automatic diagnostics
#>   [OK] Calendar coverage: No calendar periods are missing from the analysis span.
#>   [OK] Responses per period: The minimum observed-period sample size is 26.
#>   [OK] Variance information: Every observed period has an estimable within-period variance.
#>   [OK] Reference windows: 18 rolling pre-event reference windows calibrate the bias bound.
#>   [OK] Elapsed window spans: All fitting and forecasting windows span the requested number of calendar periods.
#> 
#> Window-average effect
#>     effect std_error conventional_low conventional_high bias_bound  conf_low
#>  0.2338301 0.3494136       -0.4510078         0.9186681  0.7864303 -1.848577
#>  conf_high n_windows n_reference
#>   2.435285        18         108
#> 
#> Period-specific effects
#>  relative_period observed counterfactual       effect std_error   conf_low
#>                1 4.075000       3.060427  1.014572993 0.2755797 -0.2032218
#>                2 3.650000       3.094517  0.555483138 0.3076257 -0.9105100
#>                3 3.225000       3.128607  0.096393283 0.3679333 -1.7663215
#>                4 3.235294       3.162697  0.072597546 0.4073448 -1.8353653
#>                5 3.205882       3.196786  0.009095926 0.4721175 -1.9326952
#>                6 2.885714       3.230876 -0.345161996 0.4961805 -2.3856433
#>  conf_high horizon bias_bound n_reference
#>   2.232368       2  0.4930164          18
#>   1.931914       3  0.6014881          18
#>   1.951732       4  0.8924199          18
#>   2.062067       5  0.8934478          18
#>   2.135153       6  0.8602366          18
#>   2.115669       7  0.9779732          18

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:

fit$estimate
#>      effect std_error conventional_low conventional_high bias_bound  conf_low
#> 1 0.2338301 0.3494136       -0.4510078         0.9186681  0.7864303 -1.848577
#>   conf_high n_windows n_reference
#> 1  2.435285        18         108
head(fit$days)
#>   relative_period observed counterfactual       effect std_error   conf_low
#> 1               1 4.075000       3.060427  1.014572993 0.2755797 -0.2032218
#> 2               2 3.650000       3.094517  0.555483138 0.3076257 -0.9105100
#> 3               3 3.225000       3.128607  0.096393283 0.3679333 -1.7663215
#> 4               4 3.235294       3.162697  0.072597546 0.4073448 -1.8353653
#> 5               5 3.205882       3.196786  0.009095926 0.4721175 -1.9326952
#> 6               6 2.885714       3.230876 -0.345161996 0.4961805 -2.3856433
#>   conf_high horizon bias_bound n_reference
#> 1  2.232368       2  0.4930164          18
#> 2  1.931914       3  0.6014881          18
#> 3  1.951732       4  0.8924199          18
#> 4  2.062067       5  0.8934478          18
#> 5  2.135153       6  0.8602366          18
#> 6  2.115669       7  0.9779732          18
head(fit$reference)
#>   fit_start forecast_period horizon     error
#> 1       -30             -23       2 0.4930164
#> 2       -30             -22       3 0.3818007
#> 3       -30             -21       4 0.1845068
#> 4       -30             -20       5 0.5145688
#> 5       -30             -19       6 0.4539506
#> 6       -30             -18       7 0.3505303
head(fit$windows)
#>   fit_start fit_end fit_span forecast_start forecast_end forecast_span
#> 1       -30     -25        6            -23          -18             6
#> 2       -29     -24        6            -22          -17             6
#> 3       -28     -23        6            -21          -16             6
#> 4       -27     -22        6            -20          -15             6
#> 5       -26     -21        6            -19          -14             6
#> 6       -25     -20        6            -18          -13             6

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.

plot(fit)

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