I am having trouble to compute the autocorrelation for different lags in a categorical time series. For instance, consider 3 possible categories: classA, classB and classC, and a vector x representing the series:
x <- c('classA', 'classB', 'classA', 'classC', 'classC', ...)
R contains the beautiful acf function, that computes the autocorrelation for different lags in a vector. Nevertheless the acf computes the Pearson correlation, which is (as far as I know) only suitable for continuous variables.
My first idea is to use the Cramer's V measure (available here) to compute the autocorrelation using something like
cv.test(x, lag(x,1)), where the
lag(x,1) function lags the x vector by 1, and then repeat the process for different lags. The problem is that I am not sure if this is the best approach, or even if this idea is correct.
Could you folks give-me some guidance about how to compute this autocorrelation?