I'm trying to calculate interdaily stability as a feature for machine learning classification in Python. My data is for multiple days - I'm using this dataset (sample CSV). This data is sampled with minute frequency, i.e. we have 60 measurements per hour. The formula is:

So my approach is:
def interdaily_stability(df: pd.DataFrame) -> float:
X_mean = df["activity"].mean()
hourly_means = df.resample("H", on="timestamp").mean()["activity"].values
p = len(hourly_means)
numerator = (1/p) * np.sum(np.square((hourly_means - X_mean)))
denominator = df["activity"].var()
return numerator / denominator
- Is this formula right? In particular, is
pright? - In particular, am I calculating this right for multiple days? If not, how can I correct this?
I know that pyActigraphy exists, but the implementation there seems incorrect for my case, e.g. there data is first resampled with .resample("1H").sum(), and then grouped by by hour, minute and second (I don't even have such resolution).
I also tried translating the code from nparACT library in R, but I don't know R good enough: nparACT implementation.
