The sensor-gap test: does an always-observed sensor differ at skipped prompts?
Source:R/tests_informative.R
sensor_gap_test.RdRegresses a passive-sensor channel at prompt \(t\) on the state at
\(t-1\) and the response indicator at \(t\), within person, over all
prompts whose predecessor was answered. Under the recoverable motifs the
coefficient of \(R_t\) is zero, including under M1 + M3 (no collider is
conditioned on, because the sensor is always observed). Under
self-censoring the gap identifies the direction of the tilt and, through
calibrate_delta, its magnitude.
Usage
sensor_gap_test(
data,
vars,
sensor = "S",
id = "id",
time = "time",
day = NULL,
R = "R",
se = NULL,
B = 500,
seed = NULL
)Arguments
- data
Long data frame with one row per scheduled prompt.
- vars
Names of the state columns.
- sensor
Name of the sensor column.
- 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 ofdata, a prompt counts as answered when allvarsare non-missing; any other name must exist.- se
"cluster"(cluster-robust by person with \(t(G-1)\) and \(F(q, G-1)\) reference distributions; the default when there are at least 10 persons) or"dayblock"(block bootstrap that resamples person-day blocks with replacement; the default with fewer than 10 persons; requiresday).- B
Number of bootstrap resamples for
se = "dayblock".- seed
Optional seed for the bootstrap (the caller's random-number state is restored).
Value
A one-row data frame of class c("sensor_gap_test",
"data.frame") with the columns coef_R (coefficient of
\(R_t\)), se, z and p, and the attributes
loading (the regression coefficients of the sensor on the state
variables, estimated within person from answered prompts), n (the
number of prompts used) and se (the method used). It has a
print method.
Examples
sim <- simulate_ema(N = 40, n_prompts = 30, motifs = "M2", delta = -1, sensor_cor = 0.6, seed = 1)
sg <- sensor_gap_test(sim$data, sim$vars, sensor = "S")
sg
#> Sensor-gap test: S_t ~ X_{t-1} + R_t (within person), 870 prompts with answered predecessor
#> coefficient of R_t: -0.830 (SE 0.093), z = -8.91, p = 6.08e-11 [SE: cluster]
#> sensor loading on states (answered prompts): 0.635 0.007 -0.008 -0.017
attr(sg, "loading")
#> NegA PosA Stress Fatigue
#> 0.635273000 0.007027500 -0.008433486 -0.017089419
# under a recoverable mechanism the gap is null
sim1 <- simulate_ema(N = 40, n_prompts = 30, motifs = "M1", sensor_cor = 0.6, seed = 1)
sensor_gap_test(sim1$data, sim1$vars, sensor = "S")
#> Sensor-gap test: S_t ~ X_{t-1} + R_t (within person), 870 prompts with answered predecessor
#> coefficient of R_t: -0.230 (SE 0.090), z = -2.55, p = 0.0147 [SE: cluster]
#> sensor loading on states (answered prompts): 0.651 0.039 0 0.003