\documentclass[a4paper]{article}
%\usepackage[square, sort]{natbib}
\usepackage{fullpage}
\usepackage{amsmath}
\input{defs.tex}
\parindent0pt

\title{What to expect -- an \texttt{R} vignette for \texttt{expectreg}}
\author{Fabian Sobotka, Thomas Kneib, Sabine Schnabel, Paul Eilers}


\usepackage{Sweave}

%%\VignetteIndexEntry{expectreg introduction}
%%\VignetteDepends{expectreg}

\begin{document}
\maketitle

\begin{abstract} \texttt{expectreg} is an \texttt{R} package for estimating expectile curves from 
univariate and multivariate data. Expectile curves are a valuable least squares alternative to 
quantile regression which is based on linear programming techniques. \texttt{expectreg} provides a 
number of functions for different approaches taken to estimate expectiles investigated since their 
introduction in \cite{NeweyPowell1987} using asymmetric least squares.  \end{abstract} 

\section{Overview}
This section offers an overview over the functions implemented in \texttt{expectreg}. It assumes that the
user already installed the package successfully.

<<print=FALSE>>=
library(expectreg)
@
<<eval=FALSE, results=hide>>=
help(package = "expectreg")
data(package = "expectreg")
@
will give you a short overview about the available help files of the package as well as the data that will
be provided with \texttt{expectreg}. The package includes the following functions:

\begin{table}[ht]
\begin{tabular}{ll}
\texttt{rb}& Creates bases for a regression based on covariates\\
\texttt{demq} & Density of a special distribution developed by Roger Koenker \cite{KoenkerSolution}\\
\texttt{ebeta} & Expectiles of the beta distribution\\
\texttt{eemq} & Expectiles of a special distribution developed by Roger Koenker\\
\texttt{enorm} & Expectiles of the normal distribution \\
\texttt{eunif} & Expectiles of the uniform distribution \\
\texttt{expectreg.boost} & Expectile regression using boosting \\
\texttt{expectreg.ls} & Expectiles regression of additive models \\
\texttt{expectreg.qp} & Expectile sheets with monotonicity constraints \\
\texttt{pemq}& Distribution function for a special distribution developed by Roger Koenker\\
\texttt{qemq}& Quantile function for a special distribution developed by Roger Koenker\\
\texttt{quant.boost} & Quantile regression using boosting\\
\texttt{remq}& Random variable generated from a special distribution developed by Roger Koenker\\
\end{tabular}
\end{table}

\section{Expectiles in a nutshell}

\subsection{Introduction to expectiles using LAWS}
Asymmetric least squares or least asymmetrically weighted squares (LAWS) is a weighted generalization of
ordinary least squares (OLS) estimation. LAWS minimizes
\begin{eqnarray*} \label{ALS.goal}
    S &=& \sum_{i=1}^n w_i(p) (y_i - \mu_i(p))^2,
\end{eqnarray*}
with
  \begin{eqnarray}\label{weights}
    w_i(p) = \left\{
    \begin{array}{ll}
    p & \mbox{    if    } y_i > \mu_i(p)\\
    1-p & \mbox{    if    } y_i \le \mu_i(p)\\
    \end{array}
   \; \;, \right.
  \end{eqnarray}
where $y_i$ is the response and $\mu_i(p)$ is the population expectile for different values of
an asymmetry parameter $p$ with $0<p<1$. The model is fitted by alternating between weighted
regression and recomputing weights until convergence (when the weights do not change anymore).
Equal weights ($p=$~$0.5$) give a convenient starting point.

For the expectile curve $\mu(p)$ several choices for the functional form are possible. 
The original proposal in \cite{NeweyPowell1987} favored a linear model. We suggest a more
flexible functional form for the expectile curve. \cite{SchnabelEilers} proposed to model
expectile curves with $P-$splines. Other types such as other splines, markov random field or other
options are also possible (see \cite{Sobotka:2010}).

\subsection{Expectile bundle model}

In theory it is not possible that expectile curves cross, but in estimation practise
it is often encountered due to sampling variation. The expectile bundle model is a location-scale 
type of model that allows for the simultaneous estimation of a set of expectiles. By its construction
crossing over of curves is not possible.

In the expectile bundle model the
expectiles $\mu(x,p)$ are defined by
\begin{eqnarray}\label{bundledef}
\mu(x, p) &=& t(x) + c(p)s(x)
\end{eqnarray}
where $t(x)$ is a common smooth trend of all expectile curves specified by a $P$-spline. $c(p)$
is the asymmetry function of the bundle describing the spread, i.e. the set of standardized
expectiles. $s(x)$ represents the local width of the expectile bundle and is also formulated as a $P$-spline.
The estimation procedure consists of two steps. In Step 1 the common trend $t(x)$ is estimated. Then in step
 2 we use the detrended response $y-t(x)$ to estimate $s(x)$ and $c(p)$ in an iterative procedure.

The expectiles bundle model is explained in more detail in \cite{SchnabelEilersPaper3Submitted}.

\subsection{Restricted regression quantiles}
In \cite{He1997} proposed a version of restricted regression quantiles to avoid the crossing of quantile
curves. His model for computing non-parametric conditional quantile functions takes the following form
\[ y = f(x)+s(x)e.\] \cite{He1997} takes a three-step procedure where he determines
first the conditional median function and then in a second
step estimate the smooth non-negative amplitude function. The third step consists of the step wise
calculation of the ``asymmetry factor'' $c_{\alpha}$ for each $\alpha-$quantile curve separately.

\subsection{Expectile and quantile estimation using boosting}
\begin{enumerate}
 \item Initialize all model components as $\fhatvec_j^{[0]}(\zvec)\equiv\nullvec$, $j=1,\ldots,r$. Set the iteration index to $m=1$.
 \item Compute the current negative gradient vector $\uvec$ with elements
\[
 u_i=-\left.\frac{\partial}{\partial \eta}\rho(y_i, \eta)\right|_{\eta=\hat{\eta}^{[m-1]}(\zvec_i)}, \quad i=1,\ldots,n.
\]
 \item Choose the base-learner $\gvec_{j^*}$ that minimizes the $L_2$-loss, i.e. the best-fitting function according to
 \[
 j^* = \argmin_{1\le j\le r}\sum_{i=1}^n(u_i-\hat{g}_{j}(\zvec)_i)^2
 \]
 where $\ghatvec_j=\mS_j\uvec$.
 \item Update the corresponding function estimate to $\fhatvec^{[m]}_{j^*} = \fhatvec^{[m-1]}_{j^*} + \nu \ghatvec_{j^*}$,
 where $\nu\in(0,1]$ is a step size. For all remaining functions set $\fhatvec_j^{[m]}=\fhatvec_j^{[m-1]}$, $j\neq j^*$.
 \item Increase $m$ by one. If $m<m_\text{stop}$ go back to step 2., otherwise terminate the algorithm.
\end{enumerate}
For expectile regression, the empirical risk is given the asymmetric least squares criterion (\ref{ALS.goal}) and the appropriate loss function 
is defined as $\rho(y,\eta) = w(\tau)(y - \eta_\tau)^2$. The corresponding negative gradient is therefore obtained as
\[
 u_i = 2w_i(\tau)(y_i-\eta_i).
\]


\section{Example and available data}
Expectile estimation can be used in a almost any type of situation where one is interested in estimating
smooth curves in non-central parts of the data under consideration. The data provided with the package are

<<eval=FALSE, results=hide>>=
data(india)
data(dutchboys)
@

\texttt{india} consists of a data sample of 4000 observations with 6 variables from
a 'Demographic and Health Survey' about malnutrition of children in India. Data set only contains 1/10 of
the observations and some basic variables to enable first
analyses. Details are given in \cite{IndiaTechReport}.

\texttt{dutchboys} contains data from the Fourth Dutch growth study and includes
6848 observations on 10 variables. More information can be found in \cite{Buuren}.

\subsection{Basic examples}

The basic function \texttt{expectreg.ls} can be used to estimate 11 expectiles
curves for different levels of asymmetry parameter $p$. The results are shown in the following graph.

<<eval=FALSE, results=hide>>=
data(dutchboys)
@     
<<eval=FALSE, results=hide>>=
exp.l <- expectreg.ls(dutchboys[,3] ~ rb(dutchboys[,2],"pspline"),smooth="acv")
@

\begin{center}
\begin{figure}[ht]
\includegraphics[width=10cm]{figures/dutchbsp_laws.pdf}
\caption{Expectile curves estimated using \texttt{expectreg.ls}}
\end{figure}
\end{center}

Due to the large number of observations in the data set crossing of curves is already unlikely to happen.
Nevertheless we apply also the expectile bundle model implemented in \texttt{expectile.bundle} to
this example.

<<eval=FALSE, results=hide>>=
exp.b <- expectreg.ls(dutchboys[,3] ~ rb(dutchboys[,2],"pspline"),smooth="none",estimate="bundle")
@

\begin{center}
\begin{figure}[ht]
\includegraphics[width=10cm]{figures/dutchbsp_bundle.pdf}
\caption{Expectile curves estimated using \texttt{expectreg.ls} with bundle estimate}
\end{figure}
\end{center}

Additionally we analyze the data with the algorithm proposed in \cite{He1997} implemented in 
\texttt{expectile.restricted}.

<<eval=FALSE, results=hide>>=
exp.r <- expectreg.ls(dutchboys[,3] ~ rb(dutchboys[,2],"pspline"),smooth="schall",estimate="restricted")
@

\begin{center}
\begin{figure}[ht]
\includegraphics[width=10cm]{figures/dutchbsp_rest.pdf}
\caption{Expectile curves estimated using \texttt{expectreg.ls} with restricted estimate}
\end{figure}
\end{center}


\subsection{Applied boosting}

<<eval=FALSE, results=hide>>= 
exp.boost <- expectreg.boost(hgt ~ bbs(age,df=5,degree=2),dutchboys,mstop=rep(500,11)) 
@ 

\begin{center}
\begin{figure}[ht]
\includegraphics[width=10cm]{figures/dutchbsp_boost.pdf}
\caption{Expectile curves estimated using \texttt{expectreg.boost}}
\end{figure}
\end{center}

%\bibliographystyle{genetics}

\newcommand{\noopsort}[1]{}
\begin{thebibliography}{5}
\expandafter\ifx\csname natexlab\endcsname\relax\def\natexlab#1{#1}\fi

\bibitem[{{\sc {\noopsort{Buuren}}Van~Buuren} and {\sc
  Fredriks}(2001)}]
  {Buuren}
{\sc {\noopsort{Buuren}}Van~Buuren, S.}, and {\sc A.~M. Fredriks}, 2001 Worm
  plot: A simple diagnostic device for modeling growth reference curves.
\newblock Statistics in Medicine {\bf 20}: 1259--1277.

%\bibitem[{{\sc Fenske} {\em et~al.\/}(2009){\sc Fenske}, {\sc Kneib} and {\sc
%  Hothorn}}]{IndiaTechReport}

\bibitem[{{\sc Fenske} {\em et~al.\/}(2009)}]{IndiaTechReport}
{\sc Fenske, N.}, {\sc T.~Kneib}, and {\sc T.~Hothorn}, 2009 Identifying risk
  factors for severe childhood malnutrition by boosting additive quantile
  regression.
\newblock Techical Report~52, University of Munich.

\bibitem[{{\sc He}(1997)}]{He1997}
{\sc He, X.}, 1997 Quantile curves without crossing.
\newblock The American Statistician {\bf 51}: 186--192.

\bibitem[{{\sc Koenker}(1992)}]{KoenkerSolution}
{\sc Koenker, R.}, 1992 When are expectiles percentiles? (solution).
\newblock Economic Theory {\bf 9}: 526--527.

\bibitem[{{\sc Newey} and {\sc Powell}(1987)}]{NeweyPowell1987}
{\sc Newey, W.~K.}, and {\sc J.~L. Powell}, 1987 Asymmetric least squares
  estimation and testing.
\newblock Econometrica {\bf 55}: 819--847.

%\bibitem[{{\sc Schnabel} and {\sc Eilers}(2009{\natexlab{a}})}]{Schnabel_21_5}
%{\sc Schnabel, S.~K.}, and {\sc P.~H.~C. Eilers}, 2009{\natexlab{a}} {An
%  analysis of life expectancy and economic production using expectile frontier
%  zones}.
%\newblock Demographic Research {\bf 21}: 109--134.

\bibitem[{{\sc Schnabel} and {\sc Eilers}(2009)}]{SchnabelEilers}
{\sc Schnabel, S.~K.}, and {\sc P.~H.~C. Eilers}, 2009{\natexlab{b}} Optimal
  expectile smoothing.
\newblock Computational Statistics and Data Analysis {\bf 53}: 4168--4177.

\bibitem[{{\sc Schnabel} and {\sc
  Eilers}(2010)}]{SchnabelEilersPaper3Submitted}
{\sc Schnabel, S.~K.}, and {\sc P.~H.~C. Eilers}, 2010 Non crossing expectiles
  and quantiles.
\newblock Journal for Computational and Graphical Statistics (Submitted).

\bibitem[{{\sc Sobotka} and {\sc
  Kneib}(2010)}]{Sobotka:2010}
{\sc Sobotka, F.}, and {\sc T. Kneib}, 2010 Geoadditive Expectile Regression.
\newblock Computational Statistics and Data Analysis, doi: 10.1016/j.csda.2010.11.015.

\end{thebibliography}

\end{document}
