This function calculates for a given dependent variable the value of that variable at lag timesteps earlier in the time series of an experiment.
lags.fnc(dat, time="Trial", group = "Subject", depvar = "RT", lag=1)
A vector with the values of the dependent variable at the specified lag. The by-group mean is substituted for the first lag timestep(s), for which there is/are no preceding value(s) for the dependent variable.
A data frame with (minimally) a grouping factor, an time index for successive trails/events, and a behavioral measure
A grouping factor such as Subject
A sequential time index measure such as Trial
number in an
experimental list
The dependent variable, usually a chronometric measure such as RT
The lag for which previous values are to be extracted
R. H. Baayen
acf.fnc
if (FALSE) {
dfr = data.frame(Subject=c(rep("a", 5), rep("b", 5)),
Trial = c(rep(1:5,2)),
RT = rnorm(10, 500, 40))
dfr$prevRT = lag.fnc(dfr, time="Trial", group="Subject", depvar="RT")
dfr
}
Run the code above in your browser using DataLab