  The scaling function $F(s)$ in detrended fluctuation analysis (DFA) scales as
$F(s)\sim s^{H}$ for stochastic processes with Hurst exponents $H$. We prove
this scaling law for both stationary stochastic processes with $0<H<1$, and
non-stationary stochastic processes with $1<H<2$. For $H<0.5$ we observe that
using the asymptotic (power-law) auto-correlation function (ACF) yield
$F(s)\sim s^{1/2}$. We also show that the fluctuation function in DFA is equal
in expectation to: i) A weighted sum of the ACF ii) A weighted sum of the
second order structure function. These results enable us to compute the exact
finite-size bias for signals that are scaling, as well as studying DFA for
signals that do not have power-law statistics. We illustrate this with
examples, where we find that a previous suggested modified DFA will increase
the bias for signals with Hurst exponents $H>1$. As a final application of the
new theory, we present an estimator $\hat F(s)$ that can handle missing data in
regularly sampled time series without the need for interpolation schemes. Under
mild regularity conditions, $\hat F(s)$ is equal in expectation to the
fluctuation function $F(s)$ in the gap-free case.
