Hi all,

I'm analyzing time-series data, one of the variables I want to study is the autocorrelation. In the process of getting the data ready for analyses, I'm experiencing some difficulties.

My goal: one single continuous value per participant representing the autocorrelation of the participant at hand.

I have +-200 participants in my dataset, with 20 completed (repeated) measurements ('ratings') each. I know I can use the ACF-function to calculate autocorrelation, but I was wondering whether there is a way (or function) to manipulate the data in such way I can calculate the autocorrelation for each of the participants without needing to make a separate dataframe for each participant. I.e. without having to do the following 200 times

df = long dataframe with all measurements (ratings) of the participants

PIDENT 1

d<-subset(df, pid == "a")

d<-acf(d$rating, plot = FALSE, lag.max=1)

d

Autocorrelations of series ‘d$rating’, by lag

0 1

1.000 0.495

ac<-data.frame(pid="a", ac=d[["acf"]][2, ,1])

ac

pid ac

1 a 0.495

PIDENT 2

d<-subset(df, pid == "b")

d<-acf(d$rating, plot = FALSE, lag.max=1)

d

Autocorrelations of series ‘d$rating’, by lag

0 1

1.000 -0.250

ac2<-data.frame(pid="b", ac=d[["acf"]][2, ,1])

d2

pid ac

1 b -0.250

ac<-rbind(ac, ac2)

ac

pid ac

1 a 0.495

2 b -0.250

Hope you can help me!

Kind regards,

Rose