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

View source: R/hbsae.R

CVareaR Documentation

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 of cv.glm from package boot.

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 to fSAE, fSAE.Area, or fSAE.Unit.

weight

if TRUE, 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 models
saeArea <- 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-validation

CVarea(saeArea, K=10, seed=1)  # 10-fold CV for area-level model
CVarea(saeUnit, K=10, seed=1)  # 10-fold CV for unit-level model


hbsae documentation built on March 18, 2022, 6:34 p.m.