\HeaderA{ei.reg}{Ecological regression}{ei.reg}
\keyword{models}{ei.reg}
\begin{Description}\relax
Estimate an ecological regression using least squares.
\end{Description}
\begin{Usage}
\begin{verbatim}
ei.reg(formula, data, ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{formula}] An R formula object of the form \code{cbind(c1, c2, ...)
    \textasciitilde{} cbind(r1, r2, ...)}
\item[\code{data}] data frame containing the variables specified in \code{formula}
\item[\code{...}] Additional arguments passed to \code{\LinkA{lm}{lm}}. 
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
For \eqn{i \in 1,\ldots,C}{}, C regressions of the form
\code{c\_i \textasciitilde{} cbind(r1, r2, ...)} are performed.

These regressions make use of the accounting identities
and the constancy assumption, that \eqn{\beta_{rci} =
\beta_{rc}}{} for all \eqn{i}{}.

The accounting identities include
\Itemize{
\item[--] defining the population cell fractions
\eqn{\beta_{rc}}{} such that \eqn{\sum_{c=1}^{C} \beta_{rc}
=  1}{} for every \eqn{r}{}
\item[--] \eqn{\sum_{c=1}^{C} \beta_{rci}  =  1}{} for \eqn{r = 1, \ldots, R}{} and \eqn{i = 1, \ldots,
n}{}
\item[--] \eqn{T_{ci} = \sum_{r=1}^R \beta_{rci}X_{ri}}{} for \eqn{c = 1,\ldots,C}{} and \eqn{i =
1\ldots,n}{}
}

Then regressing \deqn{T_{ci} = \beta_{rc} X_{ri} + \epsilon_{ci}}{} for \eqn{c = 1,\dots,C}{}
recovers the population parameters \eqn{\beta_{rc}}{} when the
standard linear regression assumptions apply, including
\eqn{E[\epsilon_{ci}] = 0}{} and
\eqn{Var[\epsilon_{ci}] = \sigma_c^2}{} for
all \eqn{i}{}.
\end{Details}
\begin{Value}
A list containing 
\begin{ldescription}
\item[\code{call}] the call to \code{ei.reg}
\item[\code{coefficients}] an \eqn{R \times C}{} matrix of estimated
population cell fractions
\item[\code{se}] an \eqn{R \times C}{} matrix of standard errors
for \code{coefficients}.
\item[\code{cov.matrices}] A list of the \eqn{C}{} scaled variance-covariance
matrices for each of the ecological regressions
\end{ldescription}
\end{Value}
\begin{Author}\relax
Olivia Lau \textless{}\email{olivia.lau@post.harvard.edu}\textgreater{} and Ryan T. Moore \textless{}\email{rtm@wustl.edu}\textgreater{}
\end{Author}
\begin{References}\relax
Leo Goodman. 1953. ``Ecological Regressions and the Behavior of Individuals.''
\emph{American Sociological Review} 18:663--664.
\end{References}

