Skip to contents

An event-during-survey design arises when an event occurs while a survey is already collecting responses. The observed post-event outcome is available, but its no-event counterpart is not. The central task is therefore to extrapolate the pre-event path and compare it with what was observed after the event.

Install the current version

These examples use version 0.4.2, with daily calibration followed by aggregation for period averages.

install.packages("remotes")
remotes::install_github("yhoriuchi/eventsurvey", ref = "v0.4.2")
packageVersion("eventsurvey")

The installation is pinned to the v0.4.2 release for reproducibility.

1. Prepare respondent-level data

Each row of the data frame or tibble should be a respondent. The outcome must be numeric, and time must be an integer-like numeric variable, a Date, or a POSIXt. The package includes the ready-to-use sample_data dataset so the full workflow can be run without private research data or a separate simulation step.

library(eventsurvey)
head(sample_data)
#>   day y
#> 1 -30 1
#> 2 -30 1
#> 3 -30 2
#> 4 -30 1
#> 5 -30 1
#> 6 -30 2

In this dataset, y is a simulated five-category survey response coded from 1 (lowest) to 5 (highest), and day is the interview day relative to the event: negative values are before the event, 0 is the event day, and positive values are after the event. Only these observed variables are included. The no-event counterfactual and event effects are quantities to be estimated, not columns supplied to eventsurvey().

2. Estimate the effect

The formula contains the outcome and time variables. By default, event_time = 0, event_day = "exclude", and window = 6. The model always uses estimand-specific calibration. It uses the final six observed pre-event periods, skips the event period, and forecasts the first six observed post-event periods. The rolling pre-event exercises fit six observed periods and match the actual elapsed forecast horizons of the final analysis. With daily observations, this preserves the omitted Day 0. On sparse schedules, only complete windows with those forecast offsets are used.

Use untransformed column names, with time first: outcome ~ time or outcome ~ time + covariate1 + covariate2. For example, y ~ day + group adds a baseline group covariate when the data contain it. See Covariate Adjustment for a complete example. Formulas such as log(y) ~ day, y ~ I(day^2), and y ~ day * group are rejected because formula transformations, nonlinear time terms, and interactions are not supported. If a substantively meaningful transformed outcome is needed, create it as a clearly named numeric column before fitting; the resulting effect is measured in that column’s units.

fit <- eventsurvey(y ~ day, sample_data)
fit
#> Event-during-survey estimate
#> Formula: y ~ day
#> Window: 6 periods | average-calibration references: 108 
#> Period schedule: observed | missing pre/forecast periods: 0 / 0 
#> Calibration: estimand 
#> Average effect: 0.234
#> Honest 95% CI: [-1.849, 2.435]
#> Diagnostics: 0 of 5 checks need review

The fitted object automatically checks calendar coverage, responses per period, variance information, the number of rolling reference windows, and elapsed fitting and forecasting spans. summary(fit) and the HTML report show each check as OK or Review. A Review flag is descriptive: it does not change the estimate or automatically invalidate the analysis. See Understanding Automatic Diagnostics for examples of every check and guidance on responding to a Review status.

For a one-command workflow, pipe the fitted analysis to eventsurvey_report(). Without a filename, the package creates a temporary self-contained HTML report. The default open = interactive() opens that report automatically in an interactive session such as the RStudio console, but not in Rscript, tests, continuous integration, or other batch runs. The HTML file is created either way. Set open = TRUE or open = FALSE to override this behavior.

eventsurvey(y ~ day, sample_data) |>
  eventsurvey_report()

To keep the report, provide an output filename:

eventsurvey(y ~ day, sample_data) |>
  eventsurvey_report("eventsurvey-report.html")

The printed interval is the honest bounded-misspecification-error interval. It is generally wider than the conventional interval because it allows the post-event extrapolation to be wrong by as much as the worst comparable pre-event forecast.

Estimate the average effect over five days

The package uses estimand-specific calibration for each daily effect, matching reference errors by elapsed forecast horizon. For a period average, it first calibrates each day, then aggregates with equal day weights:

fit_five <- eventsurvey(
  y ~ day, sample_data,
  window = 5,
  event_day = "exclude", schedule = "consecutive"
)
fit_five$estimate
#>      effect std_error conventional_low conventional_high bias_bound  conf_low
#> 1 0.1389318  0.397998         -0.64113         0.9189936  0.7943862 -2.106989
#>   conf_high n_windows n_reference
#> 1  2.366161        20         100
fit_five$days
#>   relative_period observed counterfactual     effect std_error   conf_low
#> 1               1 4.075000       3.191286  0.8837136 0.3096824 -0.5221436
#> 2               2 3.650000       3.265295  0.3847051 0.3578621 -1.2806272
#> 3               3 3.225000       3.339304 -0.1143035 0.4309656 -2.1862949
#> 4               4 3.235294       3.413312 -0.1780180 0.4864801 -2.3047757
#> 5               5 3.205882       3.487321 -0.2814383 0.5634330 -2.4843832
#>   conf_high horizon bias_bound n_reference
#> 1  2.289571       2  0.6013410          20
#> 2  1.942846       3  0.6633091          20
#> 3  1.834562       4  0.9095128          20
#> 4  1.980992       5  0.9138400          20
#> 5  2.069912       6  0.8839281          20
fit_five$average_components
#>   relative_period observed counterfactual     effect std_error   conf_low
#> 1               1 4.075000       3.191286  0.8837136 0.3096824 -0.7749409
#> 2               2 3.650000       3.265295  0.3847051 0.3578621 -1.5954857
#> 3               3 3.225000       3.339304 -0.1143035 0.4309656 -2.5515721
#> 4               4 3.235294       3.413312 -0.1780180 0.4864801 -2.6859021
#> 5               5 3.205882       3.487321 -0.2814383 0.5634330 -2.9270455
#>   conf_high horizon bias_bound n_reference
#> 1  2.542368       2  0.6013410          20
#> 2  2.224023       3  0.6633091          20
#> 3  2.161151       4  0.9095128          20
#> 4  2.372253       5  0.9138400          20
#> 5  2.531009       6  0.8839281          20

This targets Days 1–5 and fits Days -5 through -1. Consecutive mode ensures that five observed periods really are five calendar days. The standard error includes covariance from the shared pre-event regression. The average honest interval uses daily calibration at significance level alpha / 5 before averaging endpoints (Bonferroni); the displayed daily intervals use alpha. The same procedure works with covariates and eventsurvey_summary(). See Methodology and Assumptions for the derivation.

3. See what was extrapolated

plot(fit, type = "counterfactual")

Dark points are observed daily means. The gray line is the fitted pre-event trend and its continuation. Open points mark the forecast no-event means; blue vertical gaps are the day-specific estimates.

plot(fit, type = "effects")

4. Inspect the forecasting diagnostic

plot(fit, type = "diagnostics")

Every line is one rolling fit. Its points show the errors for the six forecast target dates. With daily observations and an excluded Day 0, these are elapsed horizons two through seven after the last fitting day. These are not placebo treatment effects; they are direct checks of the same extrapolation task used after the event.

Event-day conventions

By default, relative period 0 is excluded because respondents interviewed during the event period often have ambiguous exposure. Forecasting therefore begins with the first observed period after the event. Include period 0 only when the event timing and fieldwork make its exposure status defensible.

fit_including_event <- eventsurvey(
  y ~ day, sample_data,
  event_time = 0, window = 6,
  event_day = "include"
)

fit_hidden <- eventsurvey(
  y ~ day, sample_data,
  event_time = 0, window = 6,
  event_day = "include",
  report_event_day = FALSE
)

The second alternative retains the event period in the window-average estimate but suppresses its day-specific display; use it only when that estimand is substantively intended. These choices should follow the survey’s fieldwork and event timing, not whichever result is most favorable. Under the default exclusion rule with daily observations, the diagnostic also skips one period between each rolling fit and its forecasts. The interface requires at least 2 * window + 1 observed pre-event periods. Sparse schedules may need more history to supply a complete matching window.

Also see