1
$\begingroup$

For example, I have a series of values for example like the following:

data <- c(rnorm(10000,40,1500),rnorm(9000,-35,1400),rnorm(11000,30,1300))

I don't know the mean, don't know the sd of my data, and am particularly interested in the "sign of the mean" of my data (I can do a t-test but most often it is not significant, and even if it is, it only tells half of the story), and would be better to know if it changes over time. (how ever, I believe the data is not a time series, i.e. consecutive data points are independent of each other). But, I also doubt that my data might have different baseline distributions (assumed normal) at different time stages.

So, what is a standard way of analysing such data? You can see the sd of my data is quite big. Do I have to pretend it is a time series and decompose it to see the trend?

df <- data.frame(x=1:30000, data=data)
ggplot(df, aes(x=x)) + geom_bar(aes(y=cumsum(data)), width=1, stat="identity")

This is the graph of cumulative values of the data. Can we tell if it is from one normal distribution, or several normal distributions with different means and variances? If it is possible, what assumptions do I have to make?

enter image description here

Compared to this:

data <- rnorm(30000, 3, 1800)
df <- data.frame(x=1:30000, data=data)
ggplot(df, aes(x=x)) + geom_bar(aes(y=cumsum(data)), width=1, stat="identity")

enter image description here

Update:

I guess that changepoint package in R is good enough

> a <- cpt.meanvar(data=c(rnorm(10000,40,1500),rnorm(9000,-35,1400),rnorm(11000,30,1300)), method="BinSeg")
> summary(a)
Changepoint type      : Change in mean and variance 
Method of analysis    : BinSeg 
Test Statistic  : Normal 
Type of penalty       : SIC with value, 20.61791 
Maximum no. of cpts   : 5 
Changepoint Locations : 10264 19013 

> b <- cpt.meanvar(data=rnorm(30000, 3, 1800), method="BinSeg")
> summary(b)
Changepoint type      : Change in mean and variance 
Method of analysis    : BinSeg 
Test Statistic  : Normal 
Type of penalty       : SIC with value, 20.61791 
Maximum no. of cpts   : 5 
Changepoint Locations :  

PELT would give some small intervals thought I had penalty to include the number of change points.

> a <- cpt.meanvar(penalty="SIC1",data=c(rnorm(10000,40,1500),rnorm(9000,-35,1400),rnorm(11000,30,1300)), method="PELT")
> summary(a)
Changepoint type      : Change in mean and variance 
Method of analysis    : PELT 
Test Statistic  : Normal 
Type of penalty       : SIC1 with value, 30.92686 
Maximum no. of cpts   : Inf 
Changepoint Locations : 10049 18984 18987 
> 
> a <- cpt.meanvar(penalty="SIC1",data=c(rnorm(10000,40,1500),rnorm(9000,-35,1400),rnorm(11000,30,1300)), method="PELT")
> summary(a)
Changepoint type      : Change in mean and variance 
Method of analysis    : PELT 
Test Statistic  : Normal 
Type of penalty       : SIC1 with value, 30.92686 
Maximum no. of cpts   : Inf 
Changepoint Locations : 8810 8814 18962 
$\endgroup$
  • $\begingroup$ You appear to be asking to identify a changepoint. Do the threads with that tag help? $\endgroup$ – whuber Nov 20 '13 at 14:57
  • $\begingroup$ @whuber I haven't come across the concept of "changepoint"... so there is no tag.. but if you think it is relevant, you can add it. $\endgroup$ – colinfang Nov 20 '13 at 15:01
  • $\begingroup$ Although the term may be new to you (which is why I mentioned it), it is not new to this community. The tag exists: you can add it yourself or access it through the link in my comment. You can also use our search capability. $\endgroup$ – whuber Nov 20 '13 at 15:03
1
$\begingroup$

Please be careful when using the Binary Segmentation flag in the changepoint package. If you are not familiar with changepoints then you may not be aware that this gives an approximate solution to the changepoint search - meaning that a more accurate segmentation may exist. I would advise using method='PELT' as this provides an exact search approach and thus the most accurate segmentation.

You should also be aware that for changes in mean it is hard to detect a change if (mu_1-mu_2)/sigma < 0.7. By hard I mean that the likelihood ratio test has power less than 0.8.

$\endgroup$
  • $\begingroup$ Actually I was more stupid than you image. I had thought BinSeg is Segment Neighbourhoods so it is exact... However, it seems in the example case in the post Binary Segmentation is superior to PELT in my test. $\endgroup$ – colinfang Nov 21 '13 at 11:47
  • $\begingroup$ And I don't get why PELT would tend to give some very small intervals see my updates $\endgroup$ – colinfang Nov 21 '13 at 11:50
  • $\begingroup$ This is more a question of penalty choice, especially in your example where there are long periods between changes and the length of your data is relatively large. The SIC (in particular) is a greedy penalty, especially when n is larger than 1,000. Whilst there is not an "optimal" penalty I would advocate penalties that include a term based on segment length. The next release of the changepoint package will include this type of penalty. $\endgroup$ – adunaic Feb 2 '14 at 20:19

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.