Hacking Sleep, part 1.5

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.

This entry was posted in Modeling and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s