From http://www.psych.mcgill.ca/misc/fda/

“But what is unique about functional data is the possibility of also using information on the rates of change or derivatives of the curves. We use slopes, curvatures, and other characteristics made available because these curves are intrinsically smooth, and we can use this information in many useful ways.”

]]>It’s a very convenient way to generate interpretable nonlinear models (even linear odes give simple nonlinear functions).

Is this what some people call ‘functional data analysis’?

]]>At least, that’s why *I* would find something like this potentially more useful than fitting with splines.

Lauer et al. (1995) ]]>

A version of this kind of thing, but describing a broken/bent power-law, was defined by Lauer et al. (1995) for the purposes of fitting galaxy radial surface-brightness profiles (it’s known in the community as the “Nuker law”, for somewhat obscure reasons):

http://adsabs.harvard.edu/abs/1995AJ….110.2622L

And I came up with an equivalent for broken exponentials (for a similar purpose):

http://adsabs.harvard.edu/abs/2008AJ….135…20E

But it’s nice to have the “broken-linear” version available, especially with such a clear explanation of how it was constructed; I can already see a use for it in a paper I’m working on….

]]>Ultimately the answer should depend on the application, but I like to use logit as a default because I’m used to logit so I think I kind of understand it.

]]>P.S. This comments section is an excellent illustration of why WordPress comments are broken.

]]>log1pexp = function(x){if(x > 30) return(x) else return(log(1+exp(x)))} ]]>

log1pexp 30){return(x)}else{return(log(1+x))}}

]]>a0+a1(x-x0)+a2*(2/Pi)*(ArcTan(x-x0)-(1/2)log(1+(x-x0)^2)).

The two slopes are a1-a2 and a1+a2. If you’re not too picky about having exactly straight asymptotes, you can drop the log and make the function look a little prettier. I don’t know whether such a function has any advantages. I’ve never used it.

]]>log(1+exp(x)) ~ x for large x, so let’s just call x = 30 large since exp(30) is about 10^13 and double floats have about 15 digits of accuracy. so we’ll define log1pexp that does log(1+exp(x))

log1pexp 30){return(x)} else {return log(1+exp(x))}}

then use log1pexp to do your calculation.

]]>`ggsave`

is awesome, especially compared to the mess of base graphics output to file and rescaling issues.
]]>real logistic_hinge(real x, real x0, real a, real b0, real b1, real delta) { real xdiff = x - x0; return a + b0 * xdiff + (b1 - b0) * delta * log1p_exp(xdiff / delta); }

The value of `x - x0`

is computed once and reused (helps improve autodiff speed, but not a big deal). This form is so common that we have a specialized form of the log sum of exponentials for it (follow link for explanation of why log-sum-exp is arithmetically stable).

P.S. It’s markdown all the way down—WordPress uses its own kind of ad hoc styling and you can also throw in HTML and use their terrible image formatting GUI. The knitr HTML and LaTeX output can be customized. But I don’t know of any decently laid out knitr formats.

P.P.S. WordPress is a disaster for editing user comments, as you can see above—there’s no way for users to preview them and make sure they’re right, so users post, see the mess, try to correct, and repeat (see above). This comment would’ve been a series of comments if I’d had to create it as a user.

P.P.P.S. This would be more efficient if we built in a C++ function with analytic derivatives, but it won’t be bad as written above.

]]>ggsave(“foo.png”) should do it too ]]>

gg <- ggplot2::ggplot(data = mydata, mapping = aes(x = x, y = y)) + ggplot2::geom_line()

grDevices::png("gg.png", width = mywidth, height = myheight, units = 'in', res = 300)

gg

dev.off()

gg <- ggplot2::ggplot(data = mydata, mapping = aes(x = x, y = y)) + ggplot2::geom_line()

grDevices::png(gg, ""gg.png", width = mywidth, height = myheight, units = 'in', res = 300)

E.g.,

gg <- ggplot2::ggplot(data = mydata, mapping = aes(x = x, y = y)) + ggplot2::geom_line()

png(gg, ""gg.png", width = mywidth, height = myheight, units = 'in', res = 300)

I followed the link and, yes, they use log(1 + exp(x)), which is exactly the same model as what I proposed. Just to be clear, I should emphasize that in my above post I was not claiming any originality on this one; I just found it convenient to have the derivation, code, and graphs all in one place.

]]>(It turns out that E(|Z + x|) = x*(2*normal_cdf(x) + 1) + 2*normal_pdf(x).)

]]>I’d like a function that’s easy to write and with all continuous derivatives. I don’t particularly want a curving part that goes all the way to zero outside a finite interval.

The above post is all about modeling a single hinge. When there are a lot of knots, I could see a spline making more sense. As you know from a recent post, I’m a big fan of splines too.

]]>