This is just a technical followup to my previous post. I decided I don’t like wapply() for smoothing after all; it seems to be too dependent on the number of data points. So now I’m using a normal-density weighted average of points within a 95% confidence interval of about one hour—that is, I’m smoothing each point with every other point weighted by how close together they occurred, with the majority of the weight going to points within 30 minutes of each other.

The R code looks like this:

smooth <- function(time, y, sigma=900) sapply(min(time):max(time), function(t) sum(y*dnorm(time, t, sigma)))

sm <- smooth(d2$ZTIME-min(d2$ZTIME)+1, d2$ZINTENSITY)

And the smoothed plot looks like this:

The red line is a rough indicator of being awake—I was awake when the curve goes above that line.

### Like this:

Like Loading...