Skip to contents

eventsurvey() accepts a data frame or tibble with one respondent per row. Prepare a numeric outcome and one equally spaced time variable before fitting.

All estimation examples below use estimand-specific calibration. ## Formula requirements

Use one outcome column, put time first, and optionally add baseline covariates:

fit <- eventsurvey(outcome ~ time, data = survey_data)
adjusted <- eventsurvey(outcome ~ time + age + education, data = survey_data)

Both sides of the formula must be untransformed column names. The following specifications are intentionally rejected:

eventsurvey(log(outcome) ~ time, survey_data) # transformed in formula
eventsurvey(outcome ~ I(time^2), survey_data) # nonlinear time term
eventsurvey(outcome ~ time * group, survey_data) # interaction

This restriction keeps the fitted model additive and linear in time. Numeric covariates enter linearly; factors, character, and logical columns are categorical. Ordered factors are treated as unordered. To analyze a substantively justified transformation of the outcome, create an explicit numeric column first and use its name in the formula. The package does not currently support nonlinear time trends or interactions. Covariates must represent characteristics unaffected by the event. See Covariate Adjustment.

Period-level input remains time-only: use eventsurvey_summary(period_mean ~ time, data = period_data) with simple column names. Counts, means, and outcome variances are insufficient for respondent-level covariate adjustment.

Dates

library(eventsurvey)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

dat <- sample_data |>
  mutate(interview_date = as.Date("2026-06-15") + day)
fit <- eventsurvey(y ~ interview_date, dat,
  event_time = as.Date("2026-06-15"), window = 6
)

For timestamps, the package converts POSIXt values to calendar dates. Normalize time zones and decide how interviews spanning midnight should be classified before analysis.

Event-period exposure

The default event_day = "exclude" omits relative period 0 from the forecast window and begins estimation with the first observed period after the event. This is the safer choice when a period combines respondents interviewed before and after the event or when exact within-period interview timing is unknown.

Use event_day = "include" only when period-0 respondents can defensibly be classified as exposed. If period 0 belongs in the window-average estimand but should not appear as a day-specific result, also set report_event_day = FALSE. Record the rule and its substantive justification before comparing results.

Outcomes and missingness

Binary outcomes coded 0/1, ordered survey responses coded with numeric values such as 1–5, and continuous outcomes can be analyzed when their period means are substantively meaningful. The estimator reports differences in those original coded units: for example, changes in proportions on a 0–1 outcome (multiply by 100 for percentage points) or scale-point changes on a 1–5 outcome. A factor or character response must first be recoded deliberately; for an ordinal item, interpreting means assumes that the chosen numerical spacing is meaningful. Recode special missing values to NA. Rows with missing outcome, time, or included covariates are omitted with a warning; report that decision and the resulting daily counts. Adjusted models require at least two complete responses in each pre-event and forecast period and identifiable coefficients in every fitting window. Use the same complete-case sample when comparing adjusted and time-only fits.

Sparse and irregular fieldwork

By default, rolling windows contain consecutive observed survey periods. The package detects unobserved dates before and after the event, retains the actual time values in every trend, and reports both the gaps and each window’s elapsed span. It does not interpolate outcomes for dates with no respondents.

Inspect these diagnostics directly:

fit$settings$missing_pre_periods
#> integer(0)
fit$settings$missing_forecast_periods
#> integer(0)
fit$settings$fit_span
#> [1] 6
fit$settings$forecast_span
#> [1] 6
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

When the design requires uninterrupted calendar days, request strict checking:

strict_fit <- eventsurvey(y ~ day, dat,
  event_time = 0, window = 6,
  schedule = "consecutive"
)

Strict mode stops and lists missing pre-event periods. Do not remove a date merely because its outcome is unusual. Restrictions should follow fieldwork operations or a prespecified design rule.

See Sparse Survey Schedules for a complete simulation comparing uninterrupted and irregular fieldwork, including fitted counterfactuals and gap diagnostics.

Also see