Skip to contents

Generates a data set from the fitted VAR(1) with the fitted person means and (when the fit has person-specific intercepts) response intercepts, both resampled jointly with replacement so that the association between a person's level and propensity is preserved, and the probit self-censoring model at the fit's sensitivity value and calibrated intercept. An optional burden term lowers the propensity after a skipped prompt.

Usage

simulate_from_fit(fit, N, n_prompts, days = NULL, kappa_R = 0, seed = NULL)

Arguments

fit

A tilt_fit (or a plain pairs_fit, which is treated as a fit at delta = 0).

N

Number of persons.

n_prompts

Number of prompts per person (called T in the archived versions 0.2.x of the package).

days

Optional number of prompts per day; adds a day column and restarts the burden term at the first prompt of each day.

kappa_R

Burden term: probit drop in the response propensity at a prompt whose predecessor (within the day) was skipped.

seed

Optional seed; the caller's random-number state is restored.

Value

A long data frame with id, time, optional day,

R (1 = answered) and the state columns (NA at skipped prompts), in the format accepted by every estimator of the package.

Examples

sim <- simulate_ema(N = 30, n_prompts = 20, motifs = "M2", seed = 1)
f <- fit_tilt(sim$data, sim$vars, delta = -1)
d <- simulate_from_fit(f, N = 30, n_prompts = 20, seed = 2)
mean(d$R)
#> [1] 0.6916667
head(d)
#>   id time R     NegA     PosA   Stress    Fatigue
#> 1  1    1 1 3.145954 3.481060 2.994701 -0.2465739
#> 2  1    2 0       NA       NA       NA         NA
#> 3  1    3 0       NA       NA       NA         NA
#> 4  1    4 1 3.187597 3.887987 4.704407  0.3447670
#> 5  1    5 1 2.764360 3.631541 2.358398 -1.1249661
#> 6  1    6 1 3.276797 3.203032 3.412900 -2.1979386
# with a day structure and a burden term
d2 <- simulate_from_fit(f, N = 30, n_prompts = 20, days = 5, kappa_R = 1, seed = 2)
fatigue_check(d2, day = "day")
#> Fatigue check over 480 consecutive prompts
#>   response rate after an answered prompt: 0.822; after a skipped prompt: 0.287; difference 0.535 (person-mean difference 0.309)
#>   response rate by study quarter: 0.62 0.64 0.66 0.647