How to split a time series into "day" and "night" intervals? I have measured a lot of daily activity of people, with data for one person looking like in this image:

I would now like to automatically estimate the time when this person wakes up, and more generally, extract one coherent interval from (in this image) around 5:00am to 10:00pm as the "active" interval, i.e. where this person is awake.
The following line is the per-time-point standard deviation for one person, which shows the clearest separation from day and night so far.

I have brainstormed a few ideas, like tree stumps, something similar to HPD intervals, Hidden Markov Models, or k-means of the y values. But none would result in exactly one coherent interval of higher activity.
What methods would you suggest to split the day up into two intervals using this data?
I'm not even sure if it's better to work with the set of raw days, or the single line of standard deviations (the means have a similar shape but are not so well separated).
 A: You can use changepoint analysis. I have used with the changepoint package in R. There are several algorithms available (not sure that it would matter computationally, but it will for available parameters). More important would be the parameter selection.
I'll suppose that your data is in a data frame called dat and that you have columns for personid, time and activity. I'm assuming you want to automatically determine this interval for each person, and you would need to aggregate it to mean activity by person and time.
changepoint has 3 different functions you may want to try. One will look for changes according to mean, one according to variance, and one according to both. I'd suggest some trial and error to see which one most consistently gives the type of result you expect. Then you would end up with something like:
cpt.mean(data,method="BinSeg",Q=2)

This will search for changepoints on the mean only using the BinSeg method. You could also use the SegNeigh method. These both give you the Q parameter, which is the maximum number of changepoints. You want this to be 2 (with SegNeigh, you would specify 3 to mean the maximum number of segments). You need a break in the morning when they wake, and a break in the evening when they rest.
If you use the other methods available (I believe the default is PELT) you may end up with many more changepoints with data that looks like this. Hopefully with the limit, your biggest changes for most people will be wake up and sleep times.
