# Finding the standard deviation for original and transformed data

I am writing a heart rate monitoring program for Arduino. The data collected is the interval between heart beats. Then average and standard deviation of intervals are calculated over a given amount of time. The standard deviation is important data for heart rate variability biofeedback.

Displaying the data as beats per minute is more meaningful then intervals in milliseconds. The formula for converting interval ($\frac{ms}{beat}$) to frequency ($\frac{beats}{min}$) is $\frac{60000}{interval}$. But that does not work when the standard deviation is plugged in as interval.

A possible workaround I found was determining the interval values for plus and minus 1 standard deviation form the mean, converting those to frequency values, then half the difference would be the standard deviation in terms of frequency.

Is this correct and is there a better way?

Suppose that heart rates $X$ in BPM are distributed $Norm(\mu_X = 75, \sigma_X = 4).$ The upper histogram below shows $n = 500$ heart rates simulated according to that distribution The curve is the density curve of $Norm(75, 4).$ The solid vertical blue lines are at $\mu - \sigma, \mu,$ and $\mu + \sigma.$ The dotted vertical red lines are at $\bar X - S_X, \bar X,$ and $\bar X + S_X,$ computed from my fake data. The sample values match the corresponding population values fairly well.

The lower histogram shows transformed values $Y = 60/X$ (seconds between beats). Notice that this histogram is markedly skewed to the right. This means that the standard deviation may not be a good measure of dispersion for my $Y$s. The solid vertical brown lines are derived from the transformed values $\bar Y - S_Y, \bar Y,$ and $\bar Y + S_Y.$ The dotted red lines are transforms of the dotted red lines in the top histogram: $60/(\bar X + S_X), 60/\bar X,$ and $60/(\bar X - S_X).$

In theory, there is no reason that the red and brown lines should match. In particular, $\bar Y$ is not the same thing as $60/\bar X,$ nor is $S_Y$ the same thing as $60/S_X.$ That is because the transformation from $X$ to $Y$ is not a linear transformation. In spite of that, at the scale of my fake data, these values match pretty well. I believe that explains your (ill-advised) workaround.

I see that another answer has appeared as I was messing around with graphs. It includes comments similar to ones that I was about to make: I totally agree (+1) with @SteveKass that you need to decide for which type of data (BPM or intervals between) the standard deviation is "important ... for judging heart rate variability." Whichever it is, you could compute your SDs directly for that type of data. And you should check what standard medical usage is in making your choice. I think it is very unlikely that SDs are appropriate for both the original and the reciprocal scale, but I wouldn't care to speculate for which scale SDs would be appropriate. (My modeling of BPMs as normal was a convenient choice for an illustration, not necessarily the truth.)

There is no guarantee that either 'BPM' or 'Time between beats' is normally distributed, or that getting 'approximately right' SDs by a fundamentally flawed method won't turn to disaster at some point.

No. This isn’t correct. The transformation between interval $I$ and frequency $f$ is nonlinear, and the interval of width two standard deviations about the average interval $\left[\hat I-\sigma_I,\hat I+\sigma_I\right]$ doesn’t transform to an interval that’s symmetric about the average frequency. What you did would work if the transformation between $f$ and $I$ were linear (like between °F and °C temperatures, for example).

If you want the standard deviation of the frequencies, you should compute the individual frequencies and find the standard deviation of those values.

I think it’s worth adding that something like the “standard deviation of the heart rate over the last $5$ minutes” isn’t necessarily a straightforward thing. A heart rate is usually computed over a longer timeframe than a single interval between two beats. Heart rate monitors typically display a moving average over many beats or over a fixed time interval, say over 20 beats or 15 seconds, maybe. The interval used for the moving average will affect the standard deviation, so be sure you know what it is you want to compute. If you’re assessing your result against known medical data, be sure you’re computing the same thing.