Statistical differences between two hourly patterns I have 2 groups of subjects, namely:


*

*Subjects that are younger than 67

*Subjects that are older than 67


Each subject of each group wears a sensor that estimates the metabolic equivalent of tasks (METs) during a day (this measure represents how active the subject is during the day...it is similar to the energy expenditure).
For each patient I compute the average METs at each hour that means that each patient is represented by a time series with 24 data points.
In the picture you can find the hourly average METS for each group of subjects together with the 95% confidence intervals. This picture represents the hourly pattern of the 2 groups.
Is there a statistical test in order to compare (and emphasize differences between) the 2 hourly patterns?
The question is:
How can I show (using a statistical test) that there are significant differences between the hourly pattern of people older than 67 and younger than 67?

 A: This is an old question, but has no accepted answer, so let me offer my own.
Here is some data that, while not being exactly like yours, is close enough for our purposes.

Because the data are non-linear, I think a GAM might work well here.  I'll use the mgcv library to first fit a simple gam which uses a smooth for time and an additive effect for age group (here labeled g).
Model Code:
model = gam(y ~ s(t) + g, data = d)


Let's take a look at the predictions.

Model looks ok, maybe the tail ends could be problematic.  Let's fit a smooth which varies by group
model = gam(y ~ s(t, by = g), data = d)


Let's take a look at predictions

Ehhh... maybe we needed that additive effect.  Finally, let's fit a model which varies by group, but also has an additive effect
model = gam(y ~ s(t, by = g) + g, data = d)



I think that is the best fit we are going to get.  I should add that since this data is technically cyclical, we should pass bs = 'cc' to use cyclic cubic regression.   The model has a summary functionality which looks a lot like the lm summary, complete with hypothesis tests.  The tests for the fixed effects are similar to a linear model, but the null hypothesis for the smooths is a bit more complicated. Gavin Simpson, who is like The GAM Guy so far as I am concerned, has an excellent run down of the gam summary table here.
A: Why don't you split into few time bands of 2h duration, say 00:04, 04:06, etc. and for each band you apply a two-sample t-test for each band. You didn't mention how many patients for each group, but if they are only few a t-test should do the work. Then you will get a p-value and a confidence interval for each time band. You can reject the null hypothesis only if you can reject for all bands and use the largest p-value as p-value for the whole population.
