sae: An R Package for Small Area Estimation

Abstract We describe the R package sae for small area estimation. This package can be used to obtain model-based estimates for small areas based on a variety of models at the area and unit levels, along with basic direct and indirect estimates. Mean squared errors are estimated by analytical approximations in simple models and applying bootstrap procedures in more complex models. We describe the package functions and show how to use them through examples.


Introduction
The growing demand for more timely and detailed information, together with the high cost of interviews often leads to an extensive exploitation of survey data. Indeed, many times survey data are used to produce estimates in smaller domains or areas than those for which the survey was originally planned. For an area with a small sample size, a direct estimator, based only on the sample data coming from that area, might be very unreliable. This sample size limitation prevents the production of statistical figures at the requested level and therefore restricts the availability of statistical information for the public or the particular user. In contrast, an indirect estimator for an area also uses external data from other areas so as to increase efficiency by increasing the effective sample size. Among indirect estimators, we find those based on explicit regression models, called model-based estimators. These estimators are based on assuming a relation between the target variable and some explanatory variables that is constant across areas. The common model parameters are estimated using the whole bunch of sample data, which often leads to small area estimators with appreciably better efficiency than direct estimators as long as model assumptions hold. Thus, these techniques provide statistical figures at a very disaggregated level without increasing the area-specific sample sizes and therefore without increasing the survey cost. The small area estimation (SAE) methods included in the R package sae have applications in many different fields such as official statistics, agriculture, ecology, medicine and engineering. For a comprehensive account of SAE techniques, see Rao (2003).
The R package sae is mainly designed for model-based small area estimation. Nevertheless, simple direct and indirect estimators are included for didactic purposes and to allow the user to do cross comparisons between the very simple indirect methods and the more advanced model-based methods. Model-based point estimators can be supplemented with their corresponding estimated mean squared errors (MSEs), which are computed using analytical approximations in some cases and bootstrap procedures in other cases.
Area level models are used to obtain small area estimators when auxiliary data are available only as area aggregates. The basic area level model is the Fay-Herriot (FH) model (Fay and Herriot, 1979). Small area estimates based on this model and analytical MSE estimates can be obtained using the functions eblupFH() and mseFH() respectively.
An extension of the basic FH model to the case of (unexplained) spatial correlation among data from neighboring areas is the spatial Fay-Herriot (SFH) model. The function eblupSFH considers the SFH model in which area effects are assumed to follow a simultaneous autoregressive process of order one or SAR(1) process. Small area estimates supplemented with analytical MSE estimates can be obtained using the function mseSFH(). Alternatively, parametric and non-parametric bootstrap MSE estimates for the small area estimators obtained from the SFH model are given by the functions pbmseSFH() and npbmseSFH() respectively.
A spatio-temporal Fay-Herriot (STFH) model can be used when data from several periods of time are available and there is also spatial correlation. Apart from the area effects following a SAR(1) process, the STFH model considered by function eblupSTFH() includes time effects nested within areas, following for each domain an i.i.d. autorregresive process of order 1 or AR(1). The function pbmseSTFH() gives small area estimates and parametric bootstrap MSE estimates.
When auxiliary information is available at the unit level, the basic small area estimators are those based on the nested error linear regression model of Battese et al. (1988), called hereafter BHF model. Function eblupBHF() gives estimates of small area means based on BHF model. Parametric bootstrap MSE estimates are obtained calling function pbmseBHF().
General small area parameters obtained as a nonlinear function of the response variable in the model, such as income-based poverty indicators, can be estimated under BHF model using function ebBHF(). Function pbmseebBHF() gives the corresponding parametric bootstrap MSE estimates.
The paper is structured as follows. First, we discuss the differences between design and model based inference and introduce the notation used throughout the paper. Then, we describe one by one the model-based SAE methods implemented in the package. For each method, we briefly describe the theory behind and the use of the functions, including suitable examples. Finally, we summarize other existing software for small area estimation.

Design versus model-based inference
In survey sampling, the population is a finite collection of distinguishable and countable units. The measurements of the target variable in the population units are assumed to be non-stochastic and the aim is to estimate characteristics of the population, i.e., functions of the population measurements of the study variable in the population units, which are consequently non-stochastic as well. A sample is simply a collection of population units and inference is typically carried out under the probability distribution induced by the random mechanism used to draw the sample, i.e., the sampling design. Thus, desirable properties of estimators such as unbiasedness are established in terms of averages over all possible samples.
In model-based inference, the term population refers simply to a random variable and, in the simplest case, the sample is a collection of independent variables distributed identically as the original random variable. The parameters of interest are characteristics of the probability distribution of the original random variable such as moments, which are assumed to be fixed under the frequentist setup.
In small area estimation, the subpopulations of interest are called indistinctly areas or domains. These areas are assumed to be finite although they are typically large. However, due to the lack of sample data within those areas, models are needed to link all areas through some common parameters so as to "borrow strength" from related areas and then to improve efficiency as long as model assumptions hold. Thus, model-based small area methods combine the finite population setup with the randomness of the measurements of the variable of interest in the population units, which are assumed to follow a regression model. Consequently, target quantities, defined as functions of the population measurements, are also random.

Notation
As mentioned above, here we consider a large but finite population U. This population is assumed to be partitioned into D mutually exclusive and exhaustive domains or areas U 1 , . . . , U D of sizes N 1 , . . . , N D . Let Y dj be the measurement of the variable of interest for individual j within area d and let y d = (Y d1 , . . . , Y dN d ) be the vector of measurements for area d. The target parameters have the form δ d = h(y d ), d = 1, . . . , D, for a known measurable function h. Particular target parameters of common interest are the domain means Estimation of the target parameters is based on a sample s drawn from the population U. Let s d be the subsample from domain U d of size n d , d = 1, . . . , D, where n = ∑ D d=1 n d is the total sample size. We will denote by r d = U d − s d the sample complement from domain d of size N d − n d , for d = 1, . . . , D.
Estimation of the area parameters δ d = h(y d ), d = 1, . . . , D, can be done using area or unit-level models. In area level models, the auxiliary information comes in the form of aggregated values of some explanatory variables at the domains, typically true area means. In contrast, unit-level models make use of the individual values of the explanatory variables.
The package sae contains functions that provide small area estimators under both types of models. Functions for point estimation based on area level models include eblupFH(), eblupSFH() and eblupSTFH(). Functions for unit-level data are eblupBHF() and ebBHF(). Functions for estimation of the usual accuracy measures are also included. Below we describe the assumed models and the use of these functions, including examples of use. The package sae depends on packages nlme (Pinheiro et al., 2013) and MASS (Venables and Ripley, 2002). The examples of these functions have been run under R version x64 3.1.3.

EBLUPs based on a FH model
A basic area level model is the Fay-Herriot (FH) model, introduced by Fay and Herriot (1979) to obtain small area estimators of median income in U.S. small places. This model is defined in two stages. Letδ DIR d be a direct estimator of δ d . In the first stage, we assume that, given δ d ,δ DIR d is an unbiased estimator of δ d ; more concretely, where ψ d is the sampling variance of the direct estimatorδ DIR d given δ d , assumed to be known for all d = 1, . . . , D. In a second stage, we assume that the area parameters δ d are linearly related with a p-vector x d of area level auxiliary variables as follows, δ d = x d β + u d , u d ind ∼ N(0, A), d = 1, . . . , D. (2) Model (2) is called linking model because it relates all areas through the common regression coefficients β, allowing us to borrow strength from all areas. Model (1) is called sampling model because it represents the uncertainty due to the fact that δ d is unobservable and, instead of δ d , we observe its direct estimator based on the sample,δ DIR d . Combining the two model components, we obtain the linear mixed modelδ where u d ind ∼ N(0, A), d = 1, . . . , D, and u d is independent of e d for all d. Normality is not needed for point estimation but it is required for the estimation of the mean squared error. Henderson (1975) obtained the best linear unbiased predictor (BLUP) of a mixed effect, i.e., a linear combination of the fixed and random effects β and u = (u 1 , . . . , u D ) T . The BLUP of δ d under FH model (3) is given byδ AIC and BIC are respectively obtained as Analogous formulas are applied in the remaining functions dealing with extensions of FH model, but using the corresponding log-likelihood. For functions based on BHF model, goodness-of-fit measures are those delivered by function lme() of the package nlme. A point estimateδ d of δ d must be supplemented with an uncertainty measure; typically, the mean squared error MSE( The MSE of the EBLUP under the basic FH model (3) can be estimated analytically using the large sample approximation obtained by Prasad and Rao (1990) for a moments estimator of A. For REML and ML fitting methods, the analytical MSE estimates were firstly obtained by Datta and Lahiri (2000) and for FH fitting method, by Datta et al. (2005).
Functions eblupFH() and mseFH() calculate respectively small area estimates and corresponding analytical MSE estimates under FH model. The calls to these functions are eblupFH(formula, vardir, method = "REML", MAXITER = 100, PRECISION = 0.0001, data) mseFH(formula, vardir, method = "REML", MAXITER = 100, PRECISION = 0.0001, data) Both functions require specification of the fixed part of FH model (3) through a usual R formula object, placing the vector of direct estimates on the left-hand side of formula and the desired area level covariates separated by "+" on the right-hand side. The formula automatically adds an intercept by default. These functions also require estimates of the sampling variances of the direct estimators in vardir. The direct estimates (left-hand side of formula) and their estimated variances (vardir) required in the area level functions can be previously obtained using the function direct() included in the package sae or using the R packages survey (Lumley, 2004(Lumley, , 2012 or sampling (Tillé and Matei, 2012) when the sampling design information is available. The default fitting method (method) is REML and it can be changed to FH and ML. Default maximum number of iterations (MAXITER) and convergence tolerance criteria (PRECISION) of the Fisher-scoring algorithm can be also modified. The last argument, data, can be used to specify a data object that contains the variables in formula and vardir as columns. The functions do not allow NA values because in area level models we do not consider areas with zero sample size.
The function eblupFH() returns a list with two objects: eblup, a vector with the EBLUPs for the areas, and fit, which includes all interesting output from the fitting process. The function mseFH() gives also the EBLUPs, but supplemented with their analytical MSE estimates. This function delivers a list with two objects: est, a list containing the EBLUPs and the results of the model fitting, and mse, a vector with the estimated MSEs.

EBLUPs based on a spatial FH model
In many practical applications, data from domains that are close to each other are correlated. One way to account for this correlation is by considering a spatial Fay-Herriot (SFH) model obtained by assuming that, in FH model given in (3), the vector u = (u 1 , . . . , u D ) of domain effects follows a first order simultaneous autoregressive, SAR(1), process, that is, where 0 k denotes a (column) vector of zeros of size k and I k is the k × k identity matrix. In (6), ρ 1 ∈ (−1, 1) is an unknown autorregression parameter and W is a D × D proximity matrix obtained by a row-wise standardization of an initial matrix with zeros on the diagonal and the remaining entries equal to one when the row domain is neighbor of the column domain, see e.g., Anselin (1988) and Cressie (1993).
The EBLUP under the SFH model (3) with area effects following (6) was obtained by Petrucci and Salvati (2006). The vector of EBLUPs for all areas are obtained with the function eblupSFH().  eblupSFH(formula, vardir, proxmat, method = "REML", MAXITER = 100, PRECISION = 0.0001, data) mseSFH(formula, vardir, proxmat, method = "REML", MAXITER = 100, PRECISION = 0.0001, data) pbmseSFH(formula, vardir, proxmat, B = 100, method = "REML", MAXITER = 100, PRECISION = 0.0001, data) npbmseSFH(formula, vardir, proxmat, B = 100, method = "REML", MAXITER = 100, PRECISION = 0.0001, data) Some of the arguments are exactly the same as in the functions for FH model. The output has also the same structure. Additional arguments are a proximity matrix (proxmat), whose elements are proximities or neighborhoods of the areas, i.e., a matrix with elements in [0,1], zeros on the diagonal and rows adding up to 1. Functions using bootstrap methods also require to specify the number of bootstrap replicates B. In order to achieve stable MSE estimates, a large number of bootstrap replicates B is required. By default B is set to 100 to save computing time but we strongly recommend to set B to values over 200. Bootstrap functions are based on random number generation and the seed for random number generation can be fixed previously using set.seed(). The fitting method (method) can be chosen between REML (default value) or ML.

Example 2. Mean surface area for grape production
We consider now synthetic data on grape production for 274 municipalities in the region of Tuscany (Italy). The data set grapes contains the following variables: grapehect, direct estimators of the mean surface area (in hectares) used for production of grape for each municipality, area, agrarian surface area (in hectares) used for production, workdays, average number of working days in the reference year and var, sampling variance of the direct estimators for each municipality. We calculate spatial EBLUPs of mean surface area used for grape production, based on a spatial FH model with area and workdays as auxiliary variables, together with analytical MSE estimates. The data set grapesprox contains the proximity matrix representing the neighborhood structure of the municipalities in Tuscany.
We first load the two data sets, grapes and grapesprox. Then we call the function mseSFH() that returns small area estimates and analytical MSE estimates, calculate CVs and finally collect the obtained results in a data frame: > data("grapes") > data("grapesprox") > SFH <-mseSFH(grapehect~area + workdays -1, var, grapesprox, data = grapes) The R Journal Vol. 7/1, June 2015 ISSN 2073-4859 CV q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q Direct EBLUP SFH Figure 2: EBLUPs based on the SFH model and direct estimates of mean surface area used for production of grape for each municipality (left). CVs of EBLUPs and direct estimators for each municipality (right). Municipalities are sorted by increasing CVs of direct estimators.
> cv.SFH <-100 * sqrt(SFH$mse) / SFH$est$eblup > results <-data.frame(DIR = grapes$grapehect, + cv.DIR = 100 * abs(sqrt(grapes$var) / grapes$grapehect), + eblup.SFH = SFH$est$eblup, cv.SFH) Figure 2 left shows the EBLUPs based on the SFH model and the direct estimates of mean surface area used for production of grape for each municipality. Figure 2 right shows the CVs of EBLUPs and direct estimators for each municipality, where municipalities are sorted by increasing CVs of direct estimators. Observe that the EBLUPs are again more stable and that CVs of EBLUPs are smaller for most municipalities, and the CV gains are remarkable for the municipalities in which direct estimators are very inefficient.

EBLUPs based on a spatio-temporal FH model
If area level data are available for several periods of time and for each area, the SFH model can be further extended to make use of this additional information. Consider that data are available for T time periods within each domain. Let δ dt be the target parameter in domain d at time period t and let δ DIR dt be a direct estimate of δ dt . The STFH model proposed by Marhuenda et al. (2013) extends the SFH model by including random effects for the time periods nested within domains as followŝ Here, the vector u = (u 1 , . . . , u D ) of area effects follows the SAR(1) process given in (6) and, for each area d, the vectors v d = (v d1 , . . . , v dT ) are i.i.d. following the first order autoregressive, AR(1), process v dt = ρ 2 v d,t−1 + 2dt , 2dt ∼ N(0, σ 2 2 ). Much more complex models than the AR(1) process are not typically considered in small area estimation because in practical applications the number of available time periods T is typically small. Moving average (MA) processes are not yet considered in the sae package. Marhuenda et al. (2013) give the EBLUP ofδ dt under the STFH model and provide a parametric bootstrap procedure for the estimation of the MSE of the EBLUP. EBLUPs for all areas and parametric bootstrap estimates can be obtained calling functions eblupSTFH() and pbmseSTFH() respectively. The calls to these functions are: The arguments of these functions are the same as for the SFH model with the exception that argument method is not used because currently only the REML fitting method has been implemented for the STFH functions. Additionally, we must specify the number of areas D and the number of periods of time T for each area. Note that these functions can be used only when data are available for all the T periods of time within each of the D domains. Data in formula and vardir must be sorted in ascending order by period of time for each domain. The argument model can be chosen between the default value ST (AR(1) time-effects within each domain) or value S (uncorrelated time effects within each domain). For the bootstrap method, again we recommend to take at least B=200 bootstrap replicates. Again, the output of these functions has the same structure as that of functions for FH model.

Example 3. EBLUPs based on a spatio-temporal FH model
In this example, we use the data set spacetime, which contains synthetic area level data for T = 3 periods of time for each of D = 11 areas. The data set contains the following variables: Area, area code, Time, period of time, X1 and X2, the auxiliary variables for each area and period of time, Y, direct estimates for each area and period of time and Var, sampling variances of the direct estimators. We calculate EBLUPs of the means for each area and period of time, based on the STFH model with proximity matrix given in the data set spacetimeprox, together with parametric bootstrap MSE estimates. We show the results only for the last period of time.
> data("spacetime") > data("spacetimeprox") > D <-nrow(spacetimeprox) # number of areas > T <-length(unique(spacetime$Time)) # number of time periods > set.seed(123) > STFH <-pbmseSTFH(Y~X1 + X2, D, T, vardir = Var, spacetimeprox, data = spacetime)     Figure 3 right shows the corresponding CVs. In this example, we can see that even with a very small number of areas D = 11 and periods of time T = 3 to borrow strength from, the EBLUPs follow closely direct estimates but are still slightly more stable and the CVs of EBLUPs are smaller for all areas.

EBLUPs based on BHF model
When auxiliary data are available at the unit level, unit-level models are likely to provide more efficient small area estimators than area level models, because they make use of the much richer information offered by microdata. Let the data for unit j in area d be (Y dj , x dj ), where x dj is the vector with the values of p auxiliary variables. The basic unit-level model is the nested error model introduced by Battese et al. (1988), given by Here, u d are area effects and e dj are individual errors, where u d and e dj are assumed to be independent with corresponding variances σ 2 u and σ 2 e , regarded as unknown parameters. The model defined in (7) is assumed for all units in the population and we consider that sample selection bias is absent and therefore sample units follow exactly the same model.
For the estimation of a linear parameter δ d = a d y d under BHF model, Royall (1970) derived the BLUP. As a particular case, for the small area mean Again, the BLUP ofȲ d depends on the vector θ = (σ 2 u , σ 2 e ) of unknown variance components. In practice, we calculate the EBLUP ofȲ d by replacing θ = (σ 2 u , σ 2 e ) by a consistent estimatorθ = (σ 2 u ,σ 2 e ) . Usual fitting methods for BHF model are also ML and REML. Letβ andû d =γ d (ȳ ds −x dsβ ) be the results of replacing θ byθ in the formulas ofβ andũ d , whereγ d =σ 2 u /(σ 2 u +σ 2 e /n d ). Then the EBLUP ofȲ d can be alternatively expressed aŝ where f d = n d /N d is the domain sampling fraction. Equation (8) shows that, for calculation of the EBLUP of a small area mean, apart from sample observations, we need the true totals or meansX d of the auxiliary variables in the population and the populations sizes N d of the areas.
For MSE estimation of the EBLUP given in (8) (7) and parametric bootstrap MSE estimates can be obtained from the functions eblupBHF() and pbmseBHF() respectively. The calls to these functions are: eblupBHF(formula, dom, selectdom, meanxpop, popnsize, method = "REML", data) pbmseBHF(formula, dom, selectdom, meanxpop, popnsize, B = 200, method = "REML", data) The fixed part of the model needs to be specified through the argument formula and the variable (vector or factor) identifying the domains must be specified in the argument dom. The variables in formula and dom can also be chosen from a data set specified in the argument data. These two functions allow selection of a subset of domains where we want to estimate by specifying the vector of selected domains in selectdom, which by default includes the list of all unique domains in dom. The population means of the auxiliary variables for the domains (meanxpop) and the population sizes of the domains (popnsize) are required arguments. REML (default) or ML fitting methods can be specified in argument method. The output of these functions has the same structure as that of FH functions. In these functions, the observations with NA values in formula or dom are ignored. These functions deliver estimates for areas with zero sample size, that is, for areas specified in selectdom without observations in formula, as long as these areas have elements in meanxpop. In this case, the function delivers the synthetic estimatorŶ EBLUP d =X dβ .

Example 4. County means of corn crop hectares
We consider data used in Battese et al. (1988) on corn and soy beans production in 12 Iowa counties, contained in the two data sets cornsoybean and cornsoybeanmeans. Data come from two different sources: the 1978 June Enumerative Survey of the U.S. Department of Agriculture and images of land observatory satellites (LANDSAT) during the 1978 growing season.
In these data sets, counties are the domains and sample segments are the units. The data set cornsoybean contains the values of the following variables for each sample segment within each county: County, county code, CornHec, reported hectares of corn from the survey in each sample segment within each county, SoyBeansHec, reported hectares of soy beans from the survey in each sample segment within county, CornPix, number of pixels of corn from satellite data, and SoyBeansPix, number of pixels of soy beans from satellite data.
In this example, we will calculate EBLUPs of county means of corn crop hectares based on BHF model, considering as auxiliary variables the number of pixels of corn and soy beans from the LANDSAT satellite images. See from (8) that the domain (county) means of the auxiliary variablesX d and the population sizes N d of the counties are required to obtain the EBLUPs based on BHF model. These county means are included in the data set cornsoybeanmeans. Concretely, this data set contains: SampSegments, number of sample segments in the county (sample size), PopnSegments, number of population segments in the county (population size), MeanCornPixPerSeg, county mean of the number of corn pixels per segment, and MeanSoyBeansPixPerSeg, county mean of the number of soy beans pixels per segment (county means of auxiliary variables).
First, we create the data frame Xmean containing the true county means of the auxiliary variables given in the columns named MeanCornPixPerSeg and MeanSoyBeansPixPerSeg from the data set cornsoybeanmeans. We also create the data frame Popn containing the county population sizes. In these two data frames, the first column must contain the domain (or county) codes. Although here counties in Xmean and Popn are sorted exactly in the same way, the functions for BHF model handle correctly the case in which the domains (whose codes are listed in the first column of both Xmean and Popn) are arranged differently: > data("cornsoybeanmeans") > Xmean <-data.frame(cornsoybeanmeans[, c("CountyIndex", "MeanCornPixPerSeg", + "MeanSoyBeansPixPerSeg")]) > Popn <-data.frame(cornsoybeanmeans[, c("CountyIndex", "PopnSegments")]) Next, we load the data set with the unit-level data and delete observation number 33 because it is an outlier, see Battese et al. (1988). Then we call the function pbmseBHF(), which gives the EBLUPs of the means of corn crop area and parametric bootstrap MSE estimates, choosing B=200 bootstrap replicates. Here, CornHec is the response variable and the auxiliary variables are CornPix and SoyBeansPix.
Note that the argument selectdom can be used to select a subset of the domains for estimation. > data("cornsoybean") > cornsoybean <-cornsoybean [-33, ] > set.seed (123)  Results show great similarity with those given in Battese et al. (1988) although the model fitting method and the MSE estimation procedure used here are different.

EB estimators of nonlinear parameters based on BHF model
Now consider that we wish to estimate a general nonlinear area parameter is the vector of measurements of the response variable in the units from area d. Rearranging the elements Y dj according to their membership to the sample s d or the sample complement r d , we can express y d as y d = (y ds , y dr ) , where y ds and y dr denote respectively the subvectors containing the sample and out-of-sample elements. When δ d = h(y d ) is nonlinear in y d , considering a linear predictor like the BLUP makes no sense; instead, we consider the best predictor, which minimizes the MSE without restrictions of linearity or unbiasedness. The best predictor is given byδ where the expectation is taken with respect to the distribution of y dr given y ds , with density f (y dr |y ds ). Under BHF model for Y dj given in (7), the distribution of y dr given y ds is normal with conditional mean vector and covariance matrix depending on the unknown parameters β and θ = (σ 2 u , σ 2 e ) . Even if this conditional distribution was completely known, the expected value in (9) would be still intractable for complex nonlinear parameters δ d = h(y d ) like some poverty indicators. For such cases, Molina and Rao (2010) propose to estimate the unknown model parameters by consistent estimatorŝ β andθ = (σ 2 u ,σ 2 e ) such as ML or REML estimators, and then obtaining the empirical best (EB) estimator of δ d by a Monte Carlo approximation of the expected value in (9). This process is done by first generating out-of-sample vectors y ( ) dr , = 1, . . . , L, for large L, from the (estimated) conditional distribution f (y dr |y ds ;β,θ). The second step consists of attaching, for each , the sample elements to the generated vector y ( ) dr , resulting in the full population vector (or census) y With the census y ( ) d , we then calculate the target quantity h(y ( ) d ) for each = 1, . . . , L. Lastly, we average the target quantity over the L simulations aŝ Note that the size of y dr is N d − n d , where N d is typically large and n d is typically small. Then, generation of y dr might be computationally cumbersome. However, the generation of large multivariate normal vectors can be avoided by exploiting the form of the conditional covariance obtained from model (7). It is easy to see that out-of-sample vectors y dr from the desired conditional distribution f (y dr |y ds ;β,θ) can be obtained by generating only univariate variables from the following model In some cases, the response variable in BHF model is a one-to-one transformation of the variable of interest, that is, Y dj = T(O dj ), where O dj are the measurements of the variable of interest in the population units. This situation often occurs in socio-economic applications. A good example is when O dj is a variable measuring welfare of individuals such as income, and the target parameter for each area is a poverty indicator such as the poverty incidence, also called at-risk-of-poverty rate. The poverty incidence is defined as the proportion of people with income O dj below the poverty line z, that is, The distribution of incomes O dj is typically severely skewed and therefore assuming BHF model for O dj with normally distributed random effects and errors is not realistic. Thus, we cannot obtain EB estimates of δ d based on BHF model for O dj as described above. However, a transformation Expressing the target area parameter δ d in terms of the actual model responses Y dj for area d as we can then compute the Monte Carlo approximation of the EB estimateδ EB d of δ d as indicated in (10).
Suitable transformations T() leading to normality can be found within the Box-Cox or power families. For a constant c and a power λ, the Box-Cox transformation is given by The power family is given by The log transformation is obtained in the two families setting λ = 0. MSE estimates of the EB estimators of δ d = h(y d ) under BHF model can be obtained using the parametric bootstrap method for finite populations introduced by González- Manteiga et al. (2008).
, based on BHF model for Y dj . Function pbmseebBHF() gives EB estimates together with parametric bootstrap MSE estimates. The calls to these functions are: ebBHF(formula, dom, selectdom, Xnonsample, MC = 100, data, transform = "BoxCox", lambda = 0, constant = 0, indicator) pbmseebBHF(formula, dom, selectdom, Xnonsample, B = 100, MC = 100, data, transform = "BoxCox", lambda = 0, constant = 0, indicator) In the left-hand side of the formula object, we must put the vector of observations of the original variables O dj . We can either select "Box-Cox" or "power" family of transformations for O dj through the argument transform. The constant c of the transformations is specified through the argument constant and the power is specified in lambda. This parameter is by default set to 0, which corresponds to log transformation for both families. Setting lambda equal to 1 and letting the default constant equal to 0 implies no transformation. Note that these functions assumes BHF model for the transformed variables Y dj = T(O dj ). In the argument indicator, we must provide the name of the R function that is applied to the untransformed variables O dj to obtain the target area parameter. For example, if the target parameters are the area medians of the original untransformed variables O dj , we must specify indicator=median regardless of the transformation taken.
The two above functions require the values of auxiliary variables for each out-of-sample unit (Xnonsample). Additionally, in argument MC we must specify the number of Monte Carlo samples L that we wish to use in the Monte Carlo approximation of the EB estimators given in Equation (10). These functions ignore the observations with NA values in formula or dom. They also deliver EB estimates for areas with zero sample size, that is, for the areas specified in selectdom without any observations in formula, as long as the values of the auxiliary variables for all the units in these areas are included in Xnonsample. In this case, the functions generate the out-of-sample elements Y ( ) dj from model (11) The function ebBHF() delivers a list of two objects: the first one is called eb and contains the EB estimates for each selected domain, and the second one is called fit, and contains a summary of the model fitting. The function pbmseebBHF() obtains the parametric bootstrap MSE estimates together with the EB estimates. It delivers a list with two objects. The first one, est, is another list containing itself two objects: the results of the point estimation process (eb) and a summary of the fitting process (fit). The second one, mse, contains a data frame with the estimated MSEs for each selected domain.

Example 5. Poverty mapping
In this example, we will illustrate how to estimate poverty incidences in Spanish provinces (areas). As given in Equation (12), the poverty incidence for a province is the province mean of a binary variable O dj taking value 1 when the person's income is below the poverty line z and 0 otherwise.
The data set incomedata contains synthetic unit-level data on income and other sociological variables in the Spanish provinces. These data have been obtained by simulation, with the only purpose of being able to illustrate the use of the package functions. Therefore, conclusions regarding the levels of poverty in the Spanish provinces obtained from these data are not realistic. We will use the following variables from the data set: province name (provlab), province code (prov), income (income), sampling weight (weight), education level (educ), labor status (labor), and finally the indicators of each of the categories of educ and labor.
We will obtain EB estimates of province poverty incidences based on BHF model for the variable income. Note that the EB method assumes that the response variable considered in BHF model is (approximately) normally distributed. However, the histogram of income appears to be highly rightskewed and therefore transformation to achieve approximate normality is necessary. We select the log transformation, which is a member of both Box-Cox and power family, taking λ = 0. For the constant c in these transformation families, we tried with a grid of values in the range of income. For each value of c in the grid, we fitted BHF model to log(income + c) and selected the value of c for which the distribution of residuals was approximately symmetric, see the residual plots in Figure 4. The resulting value of the constant was c = 3500.
The package functions dealing with EB method can estimate whatever domain target parameter as desired, provided this target parameter is a function of a continuous variable O dj whose transformation Y dj will act as response variable in BHF model. We just need to define the target parameter for the domains as an R function. The target parameter in this example is the poverty incidence, which is a function of the continuous variable income. Thus, we define the R function povertyincidence() as function of y=income, considering as poverty line z = 6557.143.
> povertyincidence <-function(y) { + result <-mean(y < 6557.143) + return (result) + } When estimating nonlinear parameters, the values of the auxiliary variables in the model are needed for each out-of-sample unit. Although we will use the sample data from all the provinces to fit the model, to save computation time here we will compute EB estimates and corresponding MSE estimates only for the 5 provinces with the smallest sample sizes. For these selected provinces, the data set Xoutsamp contains the values for each out-of-sample individual of the considered auxiliary variables, which are the categories of education level and of labor status, defined exactly as in the data set incomedata. Again, these data have been obtained by simulation.
Finally, we compute parametric bootstrap MSE estimates and calculate CVs of EB estimates. This process might be slow for a large number of bootstrap or Monte Carlo replicates B and MC respectively, large sample size or large number of auxiliary variables. Function pbmseebBHF() gives also EB estimates apart from MSEs: > set.seed(123) > pbmse.EB <-pbmseebBHF(income~educ1 + educ3 + labor1 + labor2, dom = prov, + selectdom = provincecodes, Xnonsample = Xoutsamp_AuxVar, + B = 200, MC = 50, constant = 3500, + indicator = povertyincidence, data = incomedata) Bootstrap procedure with B = 200 iterations starts. b = 1 ... b = 200 > pbcv.EB <-100 * sqrt(pbmse.EB$mse$mse) / abs(pbmse.EB$est$eb$eb) # compute CV Finally, in the data frame results.EB we collect the sample sizes, EB estimates and CVs of the poverty incidence for the 5 selected provinces.  (Schoch, 2011) contains functions for robust fitting of basic unit and area level models and prediction of area means. The current version does not allow for categorical independent variables. The JoSae package (Breidenbach, 2011) includes functions for the unit-level EBLUP (Battese et al., 1988) and generalized regression (GREG) estimators (Särndal, 1984) together with estimated variances. Only univariate unit-level models with a simple block-diagonal variance structure are supported. The hbsae package (Boonstra, 2012) can be used to obtain estimates based on unit and area level models, where the model fitting can be done by REML or a hierarchical Bayes procedure. In the last case, numerical integration is used to average over the posterior density for the between-area variance.
Recently, several R packages for SAE that are not included in the subsection Small Area Estimation have been developed. The mme package (Lopez-Vizcaino et al., 2014) includes functions for SAE under three different multinomial linear mixed models: a model with independent random effects for each category of the response variable, the same model with additional independent time effects, and the same model with correlated time effects. The saery package (Esteban et al., 2014) contains functions for obtaining EBLUPs and their MSEs based on the area-level model with time effects introduced by Rao and Yu (1994) using the REML fitting method. The sae2 package (Fay and Diallo, 2015) also offers functions for SAE under time-series area level models supporting univariate and multivariate applications. They provide EBLUPs based on the Rao-Yu model as well as a modified ("dynamic") version.
Other R software that is not available at CRAN includes the SAE package developed within BIAS project (BIAS, 2005), which provides the classical EBLUP and the spatial EBLUP of Petrucci and Salvati (2006). This project includes other methods based on Bayesian spatial models implemented in WinBUGS (Lunn et al., 2000). Preliminary (and not so user friendly) versions of some of the functions contained in the sae package described in this paper can be found in the website of the European project SAMPLE (SAMPLE, 2007).
In addition to R software, SAS provides procedures such as MIXED, IML and hierarchical Bayes MCMC, which fit unit and area level models and provide small area estimates together with estimated mean squared errors. See examples of use in Mukhopadhyay and McDowell (2011). Other SAS macros have been developed in the European project EURAREA (EURAREA, 2001). The software includes macros to calculate GREG estimators under a standard linear regression model, the regression synthetic estimator under two different models and the EBLUP using unit and area level models.

Summary
This paper presents the first R package that gathers most basic small area estimation techniques together with more recent and sophisticated methods, such as those for estimation under a FH model with spatial and spatio-temporal correlation or the methods for estimation of nonlinear parameters based on BHF model. The package contains functions for point estimation and also for mean squared error estimation using modern bootstrap techniques. The functions are described and their use is demonstrated through interesting examples, including an example on poverty mapping. Nowadays, we are developing new methods for small area estimation, which will be included in subsequent versions of the sae package.