# How to analyze data which might come from a few normal distribution concatenate together in order?

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?

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")


# 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

• You appear to be asking to identify a changepoint. Do the threads with that tag help? – whuber Nov 20 '13 at 14:57
• @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. – colinfang Nov 20 '13 at 15:01
• 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. – whuber Nov 20 '13 at 15:03

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.

• 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. – colinfang Nov 21 '13 at 11:47
• And I don't get why PELT would tend to give some very small intervals see my updates – colinfang Nov 21 '13 at 11:50
• 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. – adunaic Feb 2 '14 at 20:19