Skip to contents

eventsurvey() extrapolates the pre-event outcome trend into a short post-event window. It uses rolling pre-event forecasts to bound possible misspecification and constructs an honest confidence interval using the union–intersection method.

Usage

eventsurvey(
  formula,
  data,
  event_time = 0,
  window = 6L,
  event_day = c("exclude", "include"),
  report_event_day = TRUE,
  alpha = 0.05,
  schedule = c("observed", "consecutive")
)

Arguments

formula

A two-sided formula outcome ~ time or outcome ~ time + covariate1 + covariate2, using distinct, untransformed column names. The outcome is numeric and the first right-hand term is time.

data

A data frame or tibble with one row per respondent.

event_time

The event period, in the same scale and class as the time variable. Defaults to 0, which is appropriate when time is coded relative to the event. Supply the event date or period explicitly when using an absolute time scale.

window

Integer length of both the final pre-event fitting window and the post-event forecast horizon. Must be at least 2.

event_day

Whether the event period is excluded so forecasting begins one period later ("exclude", the default) or included in the forecast horizon ("include"). Exclusion is the safer default because exposure is often ambiguous for respondents interviewed during the event period.

report_event_day

If FALSE, an included event period remains in the window-average estimate but is omitted from the printed day-specific results and plots. This argument applies only when event_day = "include".

alpha

Significance level for confidence intervals.

schedule

How rolling fitting and forecasting windows are formed. The default, "observed", forms fitting and forecasting windows from ordered periods containing responses and supports sparse survey schedules. "consecutive" requires every period on the time scale to be represented. In either mode, models use the actual time values rather than compressing gaps.

Value

An object of class eventsurvey containing the window-average estimate, honest and conventional intervals, day-specific results, individual reference forecast errors, rolling-window diagnostics, automatic checks, daily summaries, and analysis settings. average_components contains all target days (including an included but hidden event day), with honest intervals at level 1 - alpha / window used for the average interval. inference$day_covariance contains the sampling covariance matrix in target-day order. estimate$n_reference counts all daily reference contrasts used in aggregation. The days table includes each day's std_error, elapsed horizon, estimated bias_bound, and n_reference. Covariate-adjusted fits also contain reference covariance components in inference, counterfactual_path, and model_diagnostics. Respondent data are not stored.

Details

The formula must contain untransformed column names for one numeric outcome and one time variable, for example support ~ interview_date. Binary outcomes coded 0/1, ordered responses coded with numeric values such as 1–5, and continuous outcomes are supported when their period means are substantively meaningful. Factor and character outcomes must first be deliberately recoded as numeric. Time may be an integer-like numeric variable, a Date, or a POSIXt value. Add covariates after time, for example support ~ interview_date + age + education. Time must be the first term. Only additive, untransformed columns are supported; interactions and nonlinear time terms are not supported. Numeric covariates enter linearly; factors, character columns, and logical columns enter as categorical indicators (ordered factors are treated as unordered).

With covariates, respondent-level OLS is fitted separately in every rolling and final pre-event window. Predictions are averaged over the covariates of respondents in each forecast period. Use only pre-event characteristics that cannot be affected by the event. The estimand averages the effects for each forecast period's respondent population, weighting periods equally. Adjustment does not automatically identify an effect for a fixed population when survey composition changes.

Covariate-adjusted uncertainty uses stacked respondent influence functions, centered within periods and corrected by n / (n - 1). This accounts for estimated covariate means, coefficient uncertainty, and shared observations across overlapping fits. It conditions on period counts and assumes independent respondents, allowing heterogeneous variances. Intervals are asymptotic and additionally require the bounded forecast-misspecification assumption. Every used period must contain at least two complete responses, and every fitting window must have full column rank and positive residual degrees of freedom. Missing outcome, time, or covariates cause complete-case omission with a warning. Covariates do not guarantee better forecasts or narrower intervals; inspect rolling errors and choose the specification without using post-event outcomes. Both interfaces always use estimand-specific calibration. Each reference window fits window observed pre-event periods and forecasts at the same elapsed offsets as the final analysis. All forecast dates must be observed before the event; no matching windows produces an error. Estimand-specific calibration uses reference errors at the same elapsed forecast horizon for each day. Absolute daily population bias must not exceed the largest absolute matching population reference error. Sampling uncertainty in reference errors and their covariance with the daily effect estimate enter each interval. Displayed daily intervals are pointwise. For the window average, daily effects and daily bias bounds are averaged with equal weights, after calibration. The average honest interval averages daily endpoints computed at significance level alpha / window (Bonferroni), giving conservative joint coverage before aggregation. The conventional average standard error includes cross-day covariance induced by the shared pre-event fit. Reference errors are not averaged across days before calibration.

Every fitted object contains automatic diagnostics. A check receives "Review" status when calendar periods are missing, any observed period has fewer than 10 responses, a within-period variance must be pooled, fewer than five rolling reference windows are available, or an observed-period window spans more calendar periods than requested. These descriptive flags do not alter estimates or invalidate an analysis.

See also

vignette("automatic-diagnostics", package = "eventsurvey") for examples of every automatic check and guidance on Review statuses.

Examples

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
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
set.seed(42)
dat <- sample_data
dat$age <- rnorm(nrow(dat), mean = 45, sd = 12)
dat$y <- dat$y + 0.2 * (dat$age - 45)
adjusted <- eventsurvey(y ~ day + age, dat)
adjusted
#> Event-during-survey estimate
#> Formula: y ~ day + age
#> Covariates: age 
#> Window: 6 periods | average-calibration references: 108 
#> Period schedule: observed | missing pre/forecast periods: 0 / 0 
#> Calibration: estimand 
#> Average effect: 0.238
#> Honest 95% CI: [-1.813, 2.376]
#> Diagnostics: 0 of 5 checks need review