1
$\begingroup$

Let us say I have two sets of time varying series as shown below:

a <- c(895,0,0,0,0,832,0,3084,0,434,0,0,0,0,853,0,3727,0,513,0,0,0,0,1248,0,3704,0,646,0,0,0,0,2066,0,5500,0,424,0,0,0,0,1069,0)
b <- c(234,0,0,0,0,521,0,1683,0,152,0,0,0,0,740,0,3242,0,355,0,0,0,0,1117,0,3047,0,443,0,0,0,0,832,0,3213,0,326,0,0,0,0,1235,0)

Here, each value represents the number of times a person has listened to a song. Also, the data is daily which means if the first value (a[1] = 895) is for 10th Feb then the last value will be for 25th Mar.

I want to find out whether a or b is trending more and by what margin, so if I have let say another series c then I can arrange them in the trending order for example c > a > b . Is there a statistical approach to do this.

$\endgroup$
2
$\begingroup$

You need to use decompose function. I assumed frequency =7.

> a <- c(895,0,0,0,0,832,0,3084,0,434,0,0,0,0,853,0,3727,0,513,0,0,0,0,1248,0,3704,0,646,0,0,0,0,2066,0,5500,0,424,0,0,0,0,1069,0)
> b <- c(234,0,0,0,0,521,0,1683,0,152,0,0,0,0,740,0,3242,0,355,0,0,0,0,1117,0,3047,0,443,0,0,0,0,832,0,3213,0,326,0,0,0,0,1235,0)
> n=length(a)
> a.ts=ts(a,frequency =7)
> a.component=decompose(a.ts)
> 
> b.ts=ts(b,frequency =7)
> b.component=decompose(b.ts)

Looking at decomposition for a

> plot(a.component)

enter image description here

Looking at decomposition for b

> plot(b.component)

enter image description here

Comparing the trends:

> plot(1:n,a.component$trend,type="l",ylim=c(100,1150),ylab="Trend",xlab="Time")
> points(1:n,b.component$trend,type="l",col="blue",lwd=2)
> legend("topleft",lty=rep(1,2),lwd=c(1,2),col=c("black","blue"),legend=c("Trend for a", "Trend for b"))

enter image description here

$\endgroup$
  • $\begingroup$ That is good, as I can see which one is trending but how do I a parameter whose value determine which is trending more as I have something around 1M time series sequences $\endgroup$ – Ankit Apr 8 '14 at 6:32
  • $\begingroup$ Will fitting a Linear Regression model help here? or are there any other options as well ? $\endgroup$ – Ankit Apr 8 '14 at 6:33
  • $\begingroup$ You have too many zeros in your time series data. Basically you have count time series with excess zeros. So maybe Package 'ZIM' in R can help. I don't think linear regression helps in this case. $\endgroup$ – Stat Apr 8 '14 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.