Skip to contents

eventsurvey_summary() is a primary estimation interface for data frames or tibbles stored at the survey-period level. Use it when respondent records cannot be shared, are unnecessarily large for the task, or have already been reduced to a count, mean, and sample variance for each observed survey period.

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

Choose the function that matches the data

Data available Function Required input
One row per respondent eventsurvey() Outcome and interview period
One row per observed period eventsurvey_summary() Period mean, count, sample variance, and period

With a time-only formula, both functions use the same linear extrapolation, rolling forecast diagnostics, bias bound, and interval construction. They return the same eventsurvey object class, so the same summary() and plot() methods apply.

Required period-level structure

The summary data must have exactly one row for every observed survey period and four quantities:

  1. The period or interview date.
  2. The outcome mean in that period.
  3. The number of non-missing outcome observations, n.
  4. The ordinary within-period sample variance, using denominator n - 1.

Do not replace an unobserved date with a fabricated zero-count row or an interpolated outcome. A date without respondents remains absent. The schedule argument determines whether the analysis treats the observed periods as the schedule or requires consecutive calendar periods.

From respondent records to period summaries

The following example first estimates from respondent records and then from their period-level sufficient statistics. Both main fits use the default estimand-specific calibration.

respondents <- sample_data

daily <- respondents |>
  group_by(day) |>
  summarise(
    mean = mean(y),
    n = n(),
    variance = var(y),
    .groups = "drop"
  )

head(daily)
#> # A tibble: 6 × 4
#>     day  mean     n variance
#>   <int> <dbl> <int>    <dbl>
#> 1   -30  1.65    40    0.644
#> 2   -29  1.92    38    0.723
#> 3   -28  1.71    31    0.613
#> 4   -27  1.69    36    0.675
#> 5   -26  1.69    42    0.707
#> 6   -25  1.78    32    0.822

The respondent-level call is:

fit_respondents <- eventsurvey(
  y ~ day,
  data = respondents
)

With the conventional column names n and variance, the corresponding period-level call is equally concise:

fit_daily <- eventsurvey_summary(
  mean ~ day,
  data = daily
)

Use n = another_count_column or variance = another_variance_column when the summary columns have different names. Likewise, supply event_time explicitly when the time variable is not coded relative to an event at zero.

For this time-only model, correctly constructed summaries preserve all information used by the estimator:

all.equal(fit_respondents$estimate, fit_daily$estimate)
#> [1] TRUE
all.equal(fit_respondents$days, fit_daily$days)
#> [1] TRUE

This equivalence applies only to the time-only model. Adding period averages of respondent covariates does not recover their within-period relationship with the outcome or the uncertainty in overlapping adjusted fits. For covariate adjustment, use respondent-level eventsurvey(); see Covariate Adjustment.

Inspect and plot the result

The result has the same structure and methods as a respondent-level fit.

fit_daily
#> Event-during-survey estimate
#> Formula: mean ~ 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_daily)
#> Event-during-survey analysis
#> 
#> eventsurvey_summary(formula = mean ~ day, data = daily)
#> 
#> 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
plot(fit_daily, type = "counterfactual")

plot(fit_daily, type = "effects")

Sparse periods and single responses

The default schedule = "observed" supports irregular survey schedules. The package keeps the actual time values in estimation, reports missing dates, and reports the elapsed span of the rolling windows. Use schedule = "consecutive" when every calendar period must be observed.

When a period has one response, its sample variance is undefined and may be recorded as NA. The package retains its mean and count and uses the pooled within-period variance for the sampling-uncertainty calculation. Such a period should be treated as diagnostically fragile rather than as strong standalone population evidence.

Published summary-data example

The bundled published_examples object contains daily sufficient statistics for the Epifanio, Giani, and Ivandic application.

data(published_examples)
privacy <- published_examples |>
  filter(grepl("privacy", outcome))

fit_privacy <- eventsurvey_summary(
  mean ~ day,
  data = privacy,
  n = n,
  variance = variance,
  event_time = 0,
  window = 5,
  event_day = "include",
  report_event_day = FALSE,
  schedule = "observed"
)

fit_privacy$estimate
#>       effect std_error conventional_low conventional_high bias_bound  conf_low
#> 1 -0.1501581 0.1081799       -0.3621869        0.06187065  0.6227724 -1.437534
#>   conf_high n_windows n_reference
#> 1  1.137217         6          30

Also see