Movatterモバイル変換


[0]ホーム

URL:


Version:1.2
License:GPL-3
Title:Hierarchical Bayesian Small Area Estimation
Type:Package
LazyLoad:yes
Encoding:UTF-8
Description:Functions to compute small area estimates based on a basic area or unit-level model. The model is fit using restricted maximum likelihood, or in a hierarchical Bayesian way. In the latter case numerical integration is used to average over the posterior density for the between-area variance. The output includes the model fit, small area estimates and corresponding mean squared errors, as well as some model selection measures. Additional functions provide means to compute aggregate estimates and mean squared errors, to minimally adjust the small area estimates to benchmarks at a higher aggregation level, and to graphically compare different sets of small area estimates.
Date:2022-03-03
Depends:R (≥ 2.15.2)
Imports:Matrix, methods
Suggests:mcmcsae, survey, knitr, hypergeo, testthat
RoxygenNote:7.1.2
NeedsCompilation:no
Packaged:2022-03-04 20:06:23 UTC; hbta
Author:Harm Jan Boonstra [aut, cre]
Maintainer:Harm Jan Boonstra <hjboonstra@gmail.com>
Repository:CRAN
Date/Publication:2022-03-05 15:40:13 UTC

A package for hierarchical Bayesian small area estimation.

Description

Package hbsae provides functions to compute small area estimates based on thebasic unit-level and area-level models. The models are fit and small area estimates arecomputed in a hierarchical Bayesian way, using numerical integration.

Details

The main function that does most of the computational work isfSAE.Unit.FunctionfSAE is provided as a more convenient interface tofSurvReg,fSAE.Area andfSAE.Unit.


Compute area-level cross-validation measure for sae objects.

Description

This function computes a cross-validation measure defined at the area level.It can be used, for example, to compare the predictive ability of area and unit-level models.The code is based in part on that ofcv.glm from packageboot.

Usage

CVarea(  sae,  weight = TRUE,  cost = function(y, yhat, w) sum(w * (y - yhat)^2)/sum(w),  K = 10L,  method = "hybrid",  seed)

Arguments

sae

object of class sae, resulting from a call tofSAE,fSAE.Area, orfSAE.Unit.

weight

ifTRUE, use weights inversely proportional to the MSEs of y - yhat in the cost function.

cost

cost function to be used. Defaults to a quadratic cost function.

K

K in K-fold cross-validation. Specifies in how many parts the dataset should be divided.

method

method used to refit the model. One of "HB", "hybrid" (default) or "REML", in the order of slow to fast.

seed

random seed used in selecting groups of areas to leave out in K-fold cross-validation.

Value

The computed area-level cross-validation measure.

Examples

d <- generateFakeData()# compute small area estimates based on area-level and unit-level modelssaeArea <- fSAE(y0 ~ x + area2, data=d$sam, area="area", popdata=d$Xpop,                type="area", silent=TRUE, keep.data=TRUE)saeUnit <- fSAE(y0 ~ x + area2, data=d$sam, area="area", popdata=d$Xpop,                type="unit", silent=TRUE, keep.data=TRUE)# compare area and unit-level models based on area-level cross-validationCVarea(saeArea, K=10, seed=1)  # 10-fold CV for area-level modelCVarea(saeUnit, K=10, seed=1)  # 10-fold CV for unit-level model

Compute aggregates of small area estimates and MSEs.

Description

Compute aggregates of small area estimates and MSEs.

Usage

aggr(x, R)

Arguments

x

sae object.

R

aggregation matrix, M x r matrix where M is the number of areas and rthe number of aggregate areas; default is aggregation over all areas.

Value

Object of classsae with aggregated small area estimates and MSEs.

See Also

sae-class

Examples

d <- generateFakeData()# compute small area estimatessae <- fSAE(y0 ~ x + area2, data=d$sam, area="area", popdata=d$Xpop)# by default aggregate over all areasglobal <- aggr(sae)EST(global); RMSE(global)# aggregation to broad area# first build aggregation matrixM <- d$Xpop[, c("area22", "area23", "area24")] / d$Xpop[, "(Intercept)"]M <- cbind(1 - rowSums(M), M); colnames(M)[1] <- "area21"est.area2 <- aggr(sae, M)EST(est.area2); RMSE(est.area2)COV(est.area2)  # covariance matrix

Benchmark small area estimates.

Description

Benchmark small area estimates to conform to given totals at aggregate levels.

Usage

bench(x, R, rhs, mseMethod = "no", Omega, Lambda)

Arguments

x

sae object to be benchmarked. As an alternative, a list can be supplied with at least componentsNarea witharea population sizes andest with small area estimates. In the latter case argumentOmega cannot be left unspecified.

R

restriction matrix, M x r matrix where r is the number of restrictions and M the number of areas; default is a single constraint on the population total.Note thatR acts on the vector of area totals, not the vector of means.

rhs

r-vector of benchmark totals corresponding to the restrictions represented by (the columns of)R.

mseMethod

if"no", MSEs are not updated, if"exact", constraints are treated as independent information(exact identities by default), and if"model", the squared differences between original and benchmarked estimates are added to the MSEs.

Omega

M x M matrix\Omega in objective function, see details. By default this is the covariancematrix of the small area estimates.

Lambda

r x r matrix\Lambda in objective function, see details. By specifyingLambdait is possible to impose 'soft' constraints, i.e. constraints that need to hold only approximately.

Details

This function adjusts the small area estimatesEST(x), denoted byx_0, to

x_1 = x_0 + \Omega R_N (R_N' \Omega R_N + \Lambda)^{-1} (t - R_N' x_0)\,,

where

The adjusted or benchmarked small area estimates minimize the expectation of the loss function

L(x_1, \theta) = (x_1 - \theta)' \Omega^{-1} (x_1 - \theta) + (R_N' x_1 - t)' \Lambda^{-1} (R_N' x_1 - t)

with respect to the posterior for the unknown small area means\theta.

Optionally,MSE(x) is updated as well. IfmseMethod="exact" the covariance matrix is adjusted fromV_0 to

V_1 = V_0 - V_0 R_N (R_N' \Omega R_N + \Lambda)^{-1} R_N' V_0\,,

and ifmseMethod is"model" the adjusted covariance matrix is

V_1 = V_0 + (x_1 - x_0) (x_1 - x_0)'\,.

The latter method treats the benchmark adjustments as incurring a biasrelative to the best predictor under the model.

Value

An object of classsae with adjusted estimates.

References

G.S. Datta, M. Ghosh, R. Steorts and J. Maples (2011). Bayesian benchmarking with applications to small area estimation. TEST 20(3), 574-588.

Y. You, J.N.K. Rao and P. Dick (2004). Benchmarking Hierarchical Bayes Small Area Estimatorsin the Canadian Census Undercoverage Estimation. Statistics in Transition 6(5), 631-640.

See Also

sae-class

Examples

d <- generateFakeData()# compute small area estimatessae <- fSAE(y0 ~ x + area2, data=d$sam, area="area", popdata=d$Xpop)# calibrate to overall population totalsae.c <- bench(sae, rhs=sum(d$mY0*sae$Narea))plot(sae, sae.c)

Fit a linear model with random area effects and compute small area estimates.

Description

This function prepares the (unit-level) input data and calls one of the lower level functionsfSurvReg,fSAE.Area orfSAE.Unitto compute survey regression, area-level model or unit-level model small area estimates. Area-level model estimates are computed by first computing survey regression estimates and using these as input forfSAE.Area.

Usage

fSAE(  formula,  data,  area = NULL,  popdata = NULL,  type = "unit",  model.direct = NULL,  formula.area = NULL,  contrasts.arg = NULL,  remove.redundant = TRUE,  redundancy.tol = 1e-07,  sparse = FALSE,  ...)

Arguments

formula

model formula, indicating response variable and covariates.

data

unit-level data frame containing all variables used informula,area andformula.area arguments.These variables should not contain missing values.

area

name of area indicator variable indata; ifNULL, no random effects are used in the model.

popdata

data frame or matrix containing area population totals for all covariates. The rows should correspond to areasfor which estimates are required.Column names should include those produced bymodel.matrix(formula, data, contrasts.arg), up to permutations of the names in interactions.A column named '(Intercept)' is required and should contain the area population sizes.Ifpopdata isNULL, only the model fit is returned.

type

type of small area estimates: "direct" for survey regression, "area" for area-level model, "unit" for unit-level model estimates.Iftype is "data" then only the data including the model matrix and population means are returned.

model.direct

if type="area", this argument can be used to specify by means of a formula the covariates to use for the computation of the initial survey regression estimates.If unspecified, the covariates specified byformula are used both at the unit level (for the initial estimates) and at the area level (for the area-level model estimates).

formula.area

if type="unit", this is an optional formula specifying covariates that should be used at the area level.These covariates should be available inpopdata.

contrasts.arg

list for specification of contrasts for factor variables. Passed tomodel.matrix.

remove.redundant

ifTRUE redundant columns in the design matrix are removed. A warning is issued ifthe same redundancy does not show also in the corresponding population totals. In the case of thearea-level model there may still be redundancy at the area level.

redundancy.tol

tolerance for detecting linear dependencies among the columns of the design matrix. Also used as tolerance in the check whether the design matrix redundancy is shared by the population totals.

sparse

ifTRUEsparse.model.matrix (packageMatrix) is used to compute the covariate design matrix. This can be efficientfor large datasets and a model containing categorical variables with many categories.

...

additional arguments passed tofSAE.Unit orfSurvReg.

Value

An object of classsae containing the small area estimates, their MSEs, and the model fit. Iftype is "data" a list containingthe model matrix, response vector, area indicator, area population sizes and matrix of population means is returned.

See Also

sae-class

Examples

d <- generateFakeData()# model fitting only(fit <- fSAE(y0 ~ x + area2, data=d$sam, area="area"))# model fitting and small area estimation, unit-level modelsaeHB <- fSAE(y0 ~ x + area2, data=d$sam, area="area", popdata=d$Xpop,              silent=TRUE)saeHB  # print a summaryEST(saeHB)  # small area estimatesRMSE(saeHB)  # error estimatesstr(saeHB)plot(saeHB, list(est=d$mY0), CI=2)  # compare to true population means# unit-level model with REML model-fit instead of Bayesian approachsaeREML <- fSAE(y0 ~ x + area2, data=d$sam, area="area", popdata=d$Xpop,                method="REML", silent=TRUE)plot(saeHB, saeREML)  # compare# basic area-level modelsaeA <- fSAE(y0 ~ x + area2, data=d$sam, area="area", popdata=d$Xpop,             type="area")plot(saeHB, saeA)# SAE estimates based on a linear unit-level model without area effectssaeL <- fSAE(y0 ~ x + area2, data=d$sam, area="area", popdata=d$Xpop,             method="synthetic")plot(saeHB, saeL)# model-based estimation of overall population mean without area effectsest.global <- fSAE(y0 ~ x + area2, data=d$sam, area=NULL,                   popdata=colSums(d$Xpop), method="synthetic")EST(est.global); RMSE(est.global)# no model fitting or estimation, but return design matrix, variable of interest,#   area indicator, area population sizes and matrix of population meansdat <- fSAE(y0 ~ x + area2, data=d$sam, area="area", popdata=d$Xpop,            type="data")str(dat)

Compute small area estimates based on the basic area-level model.

Description

This function returns small area estimates based on the basic area-level model, also known as the Fay-Herriot model.It callsfSAE.Unit to carry out the computations.

Usage

fSAE.Area(est.init, var.init, X, x, ...)

Arguments

est.init

m-vector of initial estimates, where m is the number of in-sample areas.

var.init

m-vector of corresponding variance estimates.

X

M x p matrix of area-level covariates (typically population means), where M is the number of areas for which estimates are computed.If missing, a column vector of ones of the same length asest.init is used, corresponding to a model with an intercept only.The M areas may or may not equal the m areas for which initial estimates are provided. For example, estimatesfor out-of-sample areas, for which no initial estimates are available, are computed as long as the correspondingrows of auxiliary means are inX. It is also possible to compute estimates only for a subset of sample areas,see the help for argumentx.

x

an optional m x p matrix with auxiliary area-level covariates to be used for fitting the model,where the rows correspond to the components ofest.init.If the M areas corresponding to the rows ofX do not contain all m areas corresponding toest.init,x must be provided separately in order to be able to fit the model.

...

additional arguments passed tofSAE.Unit. For example, passingan M-vectorNarea with area population sizes (along with the matrixX ofpopulation means) allows to compute aggregates of the small area estimates. See thedocumentation of functionfSAE.Unit for a description of other possible arguments.

Value

An object of classsae containing the small area estimates and MSEs, the model fit, and model selection measures.

References

R.E. Fay and R.A. Herriot (1979). Estimates of Income for Small Places: An Application of James-Stein Procedures to Census Data.Journal of the American Statistical Association 74(366), 269-277.

J.N.K. Rao and I. Molina (2015). Small Area Estimation. Wiley.

See Also

sae-class

Examples

d <- generateFakeData()# first compute input estimates without "borrowing strength" over areassae0 <- fSAE(y0 ~ x + area2, data=d$sam, area="area", popdata=d$Xpop,             type="direct", keep.data=TRUE)# compute small area estimates based on the basic area-level model#   using the above survey regression estimates as inputsae <- fSAE.Area(EST(sae0), MSE(sae0), X=sae0$Xp)EST(sae)  # estimatesRMSE(sae)  # standard errors

Compute small area estimates based on the basic unit-level model.

Description

This is the function that carries out most of the computational work. It computes small area estimates based on the basic unit-level model, also known as theBattese-Harter-Fuller model, although it is also called byfSurvReg andfSAE.Area to compute survey regressionor area-level model small area estimates. By default, Hierarchical Bayes estimates are computed, using fast one-dimensionalnumerical integration to average over the posterior density for the ratio of between and within area variance. This way, the small area estimatesand MSEs account for the uncertainty about this parameter. Besides hierarchical Bayes, REML and hybrid methods are supported.These methods use the REML estimate or posterior mean of the variance ratio, respectively, as a plug-in estimate. Both methods do not account for uncertainty about thisparameter. Synthetic estimates are computed by setting the variance ratio to zero.

Usage

fSAE.Unit(  y,  X,  area,  Narea = NULL,  Xpop = NULL,  fpc = TRUE,  v = NULL,  vpop = NULL,  w = NULL,  wpop = NULL,  method = "HB",  beta0 = rep(0, ncol(X)),  Omega0 = Diagonal(n = ncol(X), x = 0),  nu0 = 0,  s20 = 0,  prior = function(x) rep.int(1L, length(x)),  CV = prod(dim(X)) < 1e+06,  CVweights = NULL,  silent = FALSE,  keep.data = FALSE,  full.cov = nrow(Xpop) < 1000L,  lambda0 = NULL,  rel.int.tol = 0.01,  ...)

Arguments

y

response vector of length n.

X

n x p model matrix.

area

n-vector of area codes, typically a factor variable with m levels, where m is the number of in-sample areas.

Narea

M-vector of area population sizes, where M is the number of areas for which estimates are required.There should be a one-to-one correspondence with the rows ofXpop.This argument is required unlessXpop=NULL orfpc=FALSE.

Xpop

M x p matrix of population means. IfXpop is not provided, only the model fit is returned.

fpc

whether a finite population correction should be used. Default isTRUE.

v

unit-level variance structure, n-vector. Defaults to a vector of 1s. In some cases it might be usefulto take v proportional to the sampling probabilities.

vpop

population area means of v, M-vector. Defaults to a vector of 1s. Not used whenfpc isFALSE.

w

area-level variance structure, m-vector. Defaults to a vector of 1s.

wpop

area-level variance structure, M-vector. Defaults to a vector of 1s.Only components ofwpop corresponding to out-of-sample areas are actually used.

method

one of "HB", "hybrid", "REML", "synthetic", "survreg", "BLUP" where"HB" (default) does the full hierarchical Bayes computation, i.e. numerical integration over the posterior density for the between area variance parameter,"hybrid" computes the Best Linear Unbiased Predictor (BLUP) with the posterior mean for the variance parameter plugged in,"REML" computes the BLUP with the restricted maximum likelihood estimate of the variance parameter plugged in,"synthetic" computes synthetic estimates where the between area variance is set to 0, and"survreg" computes survey regression estimates where the between area variance approaches infinity."BLUP" computes BLUP estimates with the value provided forlambda0 as a fixed plug-in value for the ratio of between and within area variance.Only method "HB" takes uncertainty about the between-area variance into account.

beta0

mean vector of normal prior for coefficient vector.

Omega0

inverse covariance matrix of normal prior for coefficient vector. Default priorcorresponds to the (improper) uniform distribution.

nu0

degrees of freedom parameter for inverse gamma prior for residual (within-area) variance. Default is 0.

s20

scale parameter for inverse gamma prior for residual (within-area) variance. Default is 0.

prior

prior density for the ratio lambda = between-area-variance / within-area variance. This should be a (vectorized) function that takesa vector lambda and returns a vector of prior density values at lambda. The density does not have to be normalized. The default isthe (improper) uniform prior. The within-area variance and lambda are assumed independent a priori.

CV

whether (an approximation to the) leave-one-out cross-validation measure should be computed. As thisrequires the computation of a dense matrix the size ofX, thedefault is to setCV toFALSE if the size ofX is largerthan a certain lower bound.

CVweights

n-vector of weights to use for CV computation.

silent

ifFALSE, plot the posterior density for the variance ratio.

keep.data

ifTRUE return the input data (y,X,area,Xpop).This is required input for the cross-validation functionCVArea.

full.cov

ifTRUE compute the full covariance matrix for the small area estimates.The computed correlations do not account for uncertainty about the variance ratio.

lambda0

optional starting value for the ratio of between and within-area variance used in the numerical routines.Ifmethod="BLUP" then this value will instead be used as a fixed plug-in value.

rel.int.tol

tolerance for the estimated relative integration error (default is 1 percent).A warning is issued if the estimated relative error exceeds this value.

...

additional control parameters passed to functionintegrate.

Details

The default Hierarchical Bayes method uses numerical integration (as provided by functionintegrate) to computesmall area estimates and MSEs. The model parameters returned, such as fixed and random effects, are currently not averaged over theposterior distribution for the variance ratio. They are evaluated at the posterior mean of the variance ratio.

Value

An object of classsae containing the small area estimates and MSEs, the model fit, and model selection measures.

References

G.E. Battese, R.M. Harter and W.A. Fuller (1988).An Error-Components Model for Prediction of County Crop Areas Using Survey and Satellite Data.Journal of the American Statistical Association, 83(401), 28-36.

G.S. Datta and M. Ghosh (1991). Bayesian Prediction in Linear Models: Applications to Small Area Estimation.The Annals of Statistics 19(4), 1748-1770.

J.N.K. Rao and I. Molina (2015). Small Area Estimation. Wiley.

See Also

sae-class

Examples

d <- generateFakeData()# generate design matrix, variable of interest, area indicator and population datadat <- fSAE(y0 ~ x + area2, data=d$sam, area="area", popdata=d$Xpop,            type="data")# compute small area estimates based on the basic unit-level modelsae <- fSAE.Unit(dat$y, dat$X, dat$area, dat$Narea, dat$PopMeans)EST(sae)  # estimatesRMSE(sae)  # standard errors

Compute small area estimates based on the survey regression estimator.

Description

This function computes survey regression estimates as a special case of unit-level model small area estimates with a (relatively) very large value for the between-area variancebut without including area effects in the model fit. The model assumes a single overall variance parameter, so that the resulting estimated variances are not area-specific but smoothed.Varying inclusion probabilities may be taken into account by including them in the model, e.g. as an additional covariate,and/or as model variance structure by specifying arguments v and vpop, seefSAE.Unit. The resulting estimates may be used as input estimates for area-level model small area estimation.

Usage

fSurvReg(y, X, area, Narea, Xpop, removeEmpty = TRUE, ...)

Arguments

y

response vector of length n.

X

n x p model matrix.

area

n-vector of area codes, typically a factor variable with m levels, where m is the number of in-sample areas.

Narea

M-vector of area population sizes.

Xpop

M x p matrix of population means.

removeEmpty

whether out-of-sample areas should be removed from the results. IfFALSE these areas are retained in the vectors of estimates,but they will have (relatively) very large standard errors.

...

optional arguments v and vpop passed tofSAE.Unit.

Value

An object of classsae containing the survey regression small area estimates and their estimated variances.

References

G.E. Battese, R.M. Harter and W.A. Fuller (1988).An Error-Components Model for Prediction of County Crop Areas Using Survey and Satellite Data.Journal of the American Statistical Association, 83(401), 28-36.

J.N.K. Rao and I. Molina (2015). Small Area Estimation. Wiley.

See Also

sae-class

Examples

d <- generateFakeData()# generate design matrix, variable of interest, area indicator and population datadat <- fSAE(y0 ~ x + area2, data=d$sam, area="area", popdata=d$Xpop,            type="data")sae <- fSurvReg(dat$y, dat$X, dat$area, dat$Narea, dat$PopMeans)EST(sae)  # estimatesRMSE(sae)  # standard errors

Generate artificial dataset for demonstration and testing purposes.

Description

Generate artificial dataset for demonstration and testing purposes.

Usage

generateFakeData(  M = 50,  meanNarea = 1000,  sW = 100,  sB = 50,  sBx = 0.5,  samplingFraction = 0.1)

Arguments

M

number of areas.

meanNarea

mean number of population units per area.

sW

within area standard deviation.

sB

between area standard deviation.

sBx

random slope standard deviation.

samplingFraction

sampling fraction used to draw a random sample from the population units.

Value

List containing sample (sam), population totals (Xpop), and true population means for fourtarget variables (mY0, mY1, mY2, mY3).


Plot method for objects of class sae.

Description

This function plots small area estimates with error bars.Multiple sets of estimates can be compared. The default ordering of the estimatesis by their area population sizes.This method uses a plot function that is adapted from functioncoefplot.default of packagearm.

Usage

## S3 method for class 'sae'plot(  ...,  n.se = 1,  est.names,  sort.by = NULL,  decreasing = FALSE,  index = NULL,  maxrows = 50L,  maxcols = 6L,  type = "sae",  offset = 0.1,  cex.var = 0.8,  mar = c(0.1, 2.1, 5.1, 0.1))

Arguments

...

sae objects,dc_summary objects (output by thesummary method forsimulation objects of packagemcmcsae), or lists.The first object must be asae object.In case of a list the componentsused are those with nameest for point estimates,sefor standard error based intervals orlower andupper forcustom intervals. Instead ofdc_summary objects matrix objects arealso supported as long as they contain columns named "Mean" and "SD" as dodc_summary objects. Named parameters of other types that do not match anyother argument names are passed to lower-level plot functions.

n.se

number of standard errors below and above the point estimatesto use for error bars. By default equal to 1. This only refers to theobjects of classdc_summary andsae.

est.names

labels to use in the legend for the components of the... argument

sort.by

vector by which to sort the coefficients, referring to the first object passed.

decreasing

ifTRUE, sort in decreasing order (default).

index

vector of names or indices of the selected areas to be plotted.

maxrows

maximum number of rows in a column.

maxcols

maximum number of columns of estimates on a page.

type

"sae" for small area estimates (default), "coef" forcoefficients, "raneff" for random effects.

offset

space used between plots of multiple estimates for the samearea.

cex.var

the fontsize of the variable names, default=0.8.

mar

a numerical vector of the form c(bottom, left, top, right) whichgives the number of lines of margin to be specified on the four sides ofthe plot.


Plot method for objects of classweights.

Description

Plot method for objects of classweights.

Usage

## S3 method for class 'weights'plot(  x,  log = FALSE,  breaks = "Scott",  main = "Distribution of weights",  xlab = if (log) "log(weight)" else "weight",  ylab = "frequency",  col = "cyan",  ...)

Arguments

x

object of classweights as returned by functionuweights.

log

whether to log-transform the weights.

breaks

breaks argument of functionhist. Default is "Scott".

main

main title of plot.

xlab

x-axis label.

ylab

y-axis label.

col

colour.

...

additional arguments passed tohist.

See Also

uweights,summary.weights


Print method for objects of class sae.

Description

Print method for objects of class sae.

Usage

## S3 method for class 'sae'print(x, digits = max(3L, getOption("digits") - 3L), ...)

Arguments

x

object of classsae.

digits

number of digits to display.

...

additional arguments passed toprint.default.


S3 class for the fitted model and SAE outcomes.

Description

FunctionsfSAE,fSurvReg,fSAE.Area andfSAE.Unitreturn an object of classsae. It contains information on the model fit as well as thesmall area estimates, error estimates and a few model selection measures.The functions listed below extract the main components from an object of classsae.

EST(x, type="sae", tot=FALSE)

return the vector of small area estimates ofsae object x. Alternatively,withtype "coef" or "raneff" fixed or random effect estimates are returned. If 'tot=TRUE' and 'type="sae"' estimatesfor area population totals instead of means are returned.

MSE(x, type="sae", tot=FALSE)

return the vector of mean squared errors ofsae object x. Alternatively,withtype "coef" or "raneff" MSEs of fixed or random effects are returned. If 'tot=TRUE' and 'type="sae"' MSEsfor area population totals instead of means are returned.

SE(x, type="sae", tot=FALSE)

extract standard errors, i.e. square roots of MSEs.

RMSE(x, type="sae", tot=FALSE)

alias for SE(x, type="sae", tot=FALSE)

relSE(x, type="sae")

extract relative standard errors.

COV(x)

extract the covariance matrix for the small area estimates.

COR(x)

extract the correlation matrix for the small area estimates.

coef(x)

coef method forsae objects; returns vector of fixed effects.

vcov(x)

vcov method forsae objects; returns covariance matrix for fixed effects.

raneff(x, pop)

return vector of random effects. Ifpop=TRUE returns a vector for predicted areas (zero for out-of-sample areas), otherwise a vector for in-sample areas.

raneff.se(x, pop)

return vector of standard errors for random effects.

residuals(x)

residuals method forsae objects; returns a vector of residuals.

fitted(x)

fitted method forsae objects; returns a vector of fitted values.

se2(x)

extracts within-area variance estimate.

sv2(x)

extracts between-area variance estimate.

wDirect(x, pop)

extract vector of weights of the survey regression components in the small area estimates. Ifpop=TRUE returns a vector for predicted areas (zero for out-of-sample areas), otherwise a vector for in-sample areas.

synthetic(x)

extract vector of synthetic estimates.

CV(x)

extract leave-one-out cross-validation measure.

cAIC(x)

extract conditional AIC measure.

R2(x)

extract unit-level R-squared goodness-of-fit measure.

Other components include

relErrM,relErrV

relative numerical integration errors in estimates and MSEs, formethod "HB".

Examples

d <- generateFakeData()# compute small area estimatessae <- fSAE(y0 ~ x + area2, data=d$sam, area="area", popdata=d$Xpop)coef(sae)  # fixed effectsraneff(sae)  # random effectssv2(sae)  # between-area variancese2(sae)  # within-area variancecAIC(sae)  # conditional AIC

Summary method for objects of classweights.

Description

Summary method for objects of classweights.

Usage

## S3 method for class 'weights'summary(object, ...)

Arguments

object

object of classweights as returned by functionuweights.

...

not used.

See Also

uweights,plot.weights


Compute unit weights underlying the small area estimates or their aggregate.

Description

The small area estimates can be interpreted as weighted sums of the response variable. This function computes the weightscorresponding to the aggregated small area estimates or the weights corresponding to a specific small area estimate. Theweights applied to the response variable need not exactly reproduce the Hierarchical Bayes estimate since the latteris averaged over the posterior distribution for the variance ratio whereas the weights are evaluated at the posterior mean.Under the default prior for the fixed effects, the weights applied to the design matrix reproduce the corresponding population numbers.

Usage

uweights(x, areaID = NULL, forTotal = FALSE)

Arguments

x

sae object.

areaID

if left unspecified (NULL), weights corresponding to the overall (aggregated) estimate are returned.Otherwise weights that reproduce the estimate for a specific area are returned.

forTotal

ifFALSE weights will be divided by the corresponding population size.

Value

An object of classweights.

See Also

summary.weights,plot.weights

Examples

d <- generateFakeData()# compute small area estimatessae <- fSAE(y0 ~ x + area2, data=d$sam, area="area", popdata=d$Xpop,            method="hybrid", keep.data=TRUE)# compute unit weightsw <- uweights(sae, forTotal=TRUE)summary(w)  # summary statisticsplot(w)  # histogram of weights# checksall.equal(sum(w * sae$y), sum(EST(sae) * sae$Narea))all.equal(colSums(w * as.matrix(sae$X)), colSums(sae$Xp * sae$Narea))

[8]ページ先頭

©2009-2026 Movatter.jp