Skip to contents

For motif M5 with an observed context variable (C_t -> X_t and C_t -> R_t), complete adjacent pairs are reweighted by the stabilized weight \(w_t = P(R_t = 1 \mid x_{t-1}) / P(R_t = 1 \mid c_t, x_{t-1})\) so that the context-marginal transition kernel is recovered (the observed-context case of the recoverability results in Yu, 2026). Both response models are probit regressions fitted on all prompts whose predecessor was answered (the response indicator is always observed), with person-specific intercepts absorbed by including the person's observed response rate as an offset-like covariate when propensity = "person".

Usage

fit_ipw(
  data,
  vars,
  context = "C",
  id = "id",
  time = "time",
  day = NULL,
  R = "R",
  propensity = c("common", "person"),
  pairs = NULL
)

Arguments

data

Long data frame with one row per scheduled prompt.

vars

Names of the state columns.

context

Name(s) of the observed context column(s).

id, time

Names of the person and prompt-index columns.

day

Optional name of a day column; pairs are formed only within a day (the overnight gap is not a lag-1 transition).

R

Name of the response-indicator column (0/1, no NA). If the default name is not among the columns of data, a prompt counts as answered when all vars are non-missing; any other name must exist.

propensity

"common" or "person" (adds the person's response rate on other prompts as a covariate of the response model).

pairs

Optional precomputed result of make_pairs.

Value

An object of class c("ipw_fit", "pairs_fit"): a

fit_pairs object (weighted) with the additional elements

response_model (the fitted denominator probit model, a

glm) and ess (the effective number of pairs); the weights are in weights. The weights are exact only when the context is serially independent; under a persistent context the pair selection through

\(R_{t-1}\) depends on \(C_{t-1}\), and covariate adjustment (fit_pairs(covariates = )) is preferable.

See also

fit_pairs with covariates for covariate adjustment, which is preferable under a persistent context.

Examples

# the context is recorded in column C
sim <- simulate_ema(N = 40, n_prompts = 30, motifs = "M5", seed = 1)
f <- fit_ipw(sim$data, sim$vars, context = "C")
f
#> Within-person VAR(1) from 644 complete adjacent pairs, 40 persons (half-panel jackknife) 
#> Lagged coefficients Phi (rows = outcome at t, columns = predictor at t-1):
#>           NegA   PosA Stress Fatigue
#> NegA     0.361 -0.029  0.132   0.044
#> PosA    -0.146  0.324 -0.003  -0.022
#> Stress   0.151  0.000  0.469   0.098
#> Fatigue -0.039 -0.134  0.012   0.265
#> Contemporaneous partial correlations (innovations):
#>           NegA   PosA Stress Fatigue
#> NegA     1.000 -0.205  0.262   0.041
#> PosA    -0.205  1.000 -0.071   0.062
#> Stress   0.262 -0.071  1.000   0.132
#> Fatigue  0.041  0.062  0.132   1.000
#> Between-person means (dynamics-recovered): 2.654 3.987 2.86 2.989 
f$ess / f$n_pairs
#> [1] 0.9512087
summary(f$response_model)$coefficients
#>                Estimate Std. Error   z value     Pr(>|z|)
#> (Intercept)  1.10199245 0.25218087  4.369849 1.243322e-05
#> x1           0.08431421 0.04740970  1.778417 7.533541e-02
#> x2          -0.07422786 0.03980777 -1.864658 6.222941e-02
#> x3          -0.08471442 0.04572846 -1.852554 6.394637e-02
#> x4           0.06511775 0.04357451  1.494400 1.350711e-01
#> c1          -0.94542769 0.09914082 -9.536210 1.481474e-21