# 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?

• Start with forming a question. What interests you? Nov 3 '15 at 16:31
• Question is now in the text Nov 4 '15 at 8:31
• In general, you cannot test differences between averages without information on variation around averages. In this case, you want to compare families of curves, which is quite an advanced problem, studied under headings like functional data analysis. There are many other methods such as fitting sinusoids to each individual and looking for patterns in the coefficients. This problem starts easily (you can plot the data) and gets much more difficult very quickly. You're the researcher but a split at 67 seems quite arbitrary to me: I would want to know ages of all patients. Nov 4 '15 at 8:59
• Hi @NickCox I have information on variation around averages. Those are represented in the 95% confidence intervals that you can see in the picture. I know that significant hourly differences between >67 and <67 are determined as hours with non-overlapping confidence bands, but I was looking for a rigorous statistical test (with p etc..). Regarding the split at 67 it is OK for my problem. Nov 4 '15 at 9:03
• Not trying to be negative, but how would MANOVA cope with cycles? It's fundamental that 1 am follows midnight. Nov 4 '15 at 10:50

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.

• Interesting, thanks. I don't want to criticize but what can we do now with that?
– Ben
Jan 23 '20 at 6:17
• @Ben I mean, having a model and asking "what can we do with it" is kind of putting the cart before the horse. We should always ask "what do I want to accomplish" and then select the model to help achieve that. In this case, OP wanted to know the affect of being >=69, so this model could be used to estimate that effect. Jan 23 '20 at 15:23
• Yes, sure, but how? I mean there are two curves now, how can I use them to get the effect resp. the significance of it? I guess it's not just their difference?
– Ben
Jan 24 '20 at 7:33
• @Ben the models can be summarized, much like a linear model object. I mention that in the last paragraph. Jan 24 '20 at 9:01
• Alright, didn't see. Thanks! So in dumb speaking, I will look at the summaries and note any differences in significances (or maybe something else, whatever I'm interested in)?
– Ben
Jan 24 '20 at 9:14

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.

• Doing many tests risks a type one error. A model controlling for age would be more appropriate in this case. Jan 23 '20 at 3:55