indexCalculationPerBSunit: Weighted Average per BSunit of Scaled Indicator Observations

View source: R/indexCalculationPerBSunit.R

indexCalculationPerBSunitR Documentation

Weighted Average per BSunit of Scaled Indicator Observations

Description

Calculates, for each unit in a set of BSunits, a sample of nsim draws from the distribution of the Nature index or a thematic index.

Usage

indexCalculationPerBSunit(
  ICunits = NULL,
  BSWeights = NULL,
  scaledBootmat = NULL,
  nsim = NULL
)

Arguments

ICunits

numeric BSunit x indicator matrix describing the occurrence of indicators in BSunits. NAs in a column should represent BSunits where the indicator is not observed.

BSWeights

A numeric BSunit x indicator matrix x, where rowSums(x,na.rm = TRUE) = rep(1,nrow), with weights for all indicators observed in each BSunit and NAs elsewhere.

scaledBootmat

numeric nObs x nsim matrix with nsim bootstrap samples from each of nObs scaled indicator observations.

nsim

integer - number of bootstrap simulations.

Details

indexCalculationPerBSunit draws a sample of size nsim from the distribution of the Nature index or a thematic index for each unit in a set of BSunits. Each draw is a weighted average of a bootstrap sample of corresponding draws from the distributions of a set of indicator observations.

Weights are entered per BSunit x indicator combination. For each indicator observation the delineation of the corresponding ICunit must be provided in the input.

Value

A BSunit x nsim numeric matrix, where each row contains nsim draws from the BSunit's index distribution.

Note

Indices are calculated for a set of BSunits, while scaled indicator observations refer to indicator specific ICunits that may vary in geographical extent among indicators, and will in general not correspond to single BSunits. Thus, indexCalculationPerBSunit needs input about the spatial extent of ICunits in terms of which BSunits they include.

Author(s)

Bård Pedersen

See Also

Index calculations and associated terminology are explained in the vignette NatureIndexCalculation.
Functions calculateIndex, calculateBSunitWeights, and scaleObsMat.

Examples

## Not run: 
# Calculate a thematic index for each BSunit based on the themeData set for 2019

# Preparing bootstrap sample as input to indexCalculationPerBSunit:
bootmat <- sampleObsMat(ICunitId = themeData$indicatorValues[["2019"]]$ICunitId,
                        value = themeData$indicatorValues[["2019"]]$expectedValue,
                        distrib = themeData$indicatorValues[["2019"]]$distributionFamilyName,
                        mu = themeData$indicatorValues[["2019"]]$distParameter1,
                        sig = themeData$indicatorValues[["2019"]]$distParameter2,
                        customDistribution = themeData$indicatorValues[["2019"]]$customDistribution,
                        imputations = NULL,
                        obsMethod = "sample",
                        obsType = "tradObs",
                        nsim = 10)
refmat <- sampleObsMat( ICunitId = themeData$referenceValues$ICunitId,
                        value = themeData$referenceValues$expectedValue,
                        distrib = themeData$referenceValues$distributionFamilyName,
                        mu = themeData$referenceValues$distParameter1,
                        sig = themeData$referenceValues$distParameter2,
                        customDistribution = themeData$referenceValues$customDistribution,
                        imputations = NULL,
                        obsMethod = "constant",
                        obsType = "tradObs",
                        nsim = 10)
scaleVec <- themeData$indicatorValues[["2019"]]$scalingModel
names(scaleVec) <- themeData$indicatorValues[["2019"]]$ICunitId
scaleVec <- scaleVec[dimnames(bootmat)[[1]]]
scaledBootmat <- scaleObsMat(bootmat = bootmat,
                        refmat = refmat,
                        scalingModel = scaleVec)

# BSunit weights as input to indexCalculationPerBSunit:
BSWeights <- calculateBSunitWeights(ICunits = themeData$ICunits,
                                    indicators = themeData$indicators$name,
                                    fids = FALSE,
                                    tgroups = FALSE)
# Calculate index for each BSunit
indices <- indexCalculationPerBSunit(ICunits = themeData$ICunits,
                                     BSWeights = BSWeights,
                                     scaledBootmat = scaledBootmat,
                                     nsim = 10)

## End(Not run)


NINAnor/NIcalc documentation built on Oct. 26, 2023, 9:37 a.m.