lagged.response.model | R Documentation |
By default, the model fitted by store
does not take serial dependence into account.
A sinple way to rectify this is to add y_{i,j-1}, the previous value of the response,
as a predictor in the model. While this device models serial dependence, it has
limitations:
The first observation for each subject must be omitted.
The resulting model treats the lagged response as continuous,
which is at odds with general store
approach of treating both
response and predictors as ordinal.
The model assumes a constant effect of the lagged response,
without regard to unequal lags as in, e.g., the thoughts
data set.
The example below illustrates how to include lagged response as a predictor.
Prince P. Osei and Philip T. Reiss
Osei, P. P. and Reiss, P. T. (2022). Ordinal state-trait regression for intensive longitudinal data. Under revision.
## Not run: require(dplyr) data(thoughts) thoughts$lagp <- lag(thoughts$pleasant.) thoughts$lagsub <- lag(thoughts$Subject) thoughts$lagday <- lag(thoughts$DAY) summ <- thoughts %>% group_by(Subject, DAY) %>% summarize(medp=median(pleasant., na.rm=TRUE)) thoughts <- left_join(thoughts, summ) thoughts$newday <- with(thoughts, lagsub!=Subject | lagday!=DAY) thoughts$newday[1] <- TRUE thoughts$lagp[thoughts$newday==TRUE] <- thoughts$medp[thoughts$newday==TRUE] mod <- store(pleasant.~stressed., data=thoughts, id="Subject") mod_lag <- store(pleasant.~stressed., data=thoughts, id="Subject", covt="lagp") ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.