neighbors {pricelevels} | R Documentation |
Price matrix characteristics
Description
A price matrix or price tableau typically consists of prices for multiple products and regions.
Function is.connected()
checks if all regions in the price matrix are connected either directly or indirectly by some bridging region. neighbors()
divides the regions into groups of connected regions. connect()
is a simple wrapper of neighbors()
, connecting some price data by relying on the group with the maximum number of observations. comparisons()
derives the amount of bilateral (or pairwise) comparisons that could be computed for each of those groups of regions. sparsity()
indicates the sparsity of the price matrix.
Usage
is.connected(r, n)
neighbors(r, n, simplify=FALSE)
connect(r, n)
comparisons(r, n, ngbs=NULL)
sparsity(r, n, useable=FALSE)
Arguments
r , n |
A character vector or factor of regional entities |
simplify |
A logical indicating whether the results should be simplified to a factor of group identifiers ( |
ngbs |
Either |
useable |
A logical indicating whether only observations should be taken into account that could be used for interregional comparisons ( |
Details
Following World Bank (2013, p. 98), a "price tableau is said to be connected if the price data are such that it is not possible to place the countries in two groups in which no item priced by any country in one group is priced by any other country in the second group".
Value
Function is.connected()
prints a single logical indicating the connectedness while connect()
returns a logical vector of the same length as the input vectors. neighbors()
gives a list or vector of connected regions. sparsity()
returns a single numeric showing the sparsity of the price matrix. comparisons()
outputs a data.table with the following variables:
group_id | group identifier | |
group_members | regions belonging to that group | |
group_size | number of regions belonging to that group | |
total | number of (non-redundant) regional pairs that could be computed, following the formula R*(R-1)/2 |
|
direct | number of regional pairs that traces back to direct connections, e.g. when two regions have priced the same product | |
indirect | number of regional pairs that traces back to indirect connections, e.g. when two regions are connected via a third bridging region | |
n_obs | number of observations containing interregional information | |
Author(s)
Sebastian Weinand
References
World Bank (2013). Measuring the Real Size of the World Economy: The Framework, Methodology, and Results of the International Comparison Program. Washington, D.C.: World Bank.
Examples
### connected price data:
set.seed(123)
dt1 <- rdata(R=4, B=1, N=3)
dt1[, sparsity(r = region, n = product)]
dt1[, is.connected(r = region, n = product)] # true
dt1[, neighbors(r = region, n = product, simplify = TRUE)]
dt1[, comparisons(r = region, n = product)]
### non-connected price data:
dt2 <- data.table::data.table(
"region" = c("a","a","h","b","a","a","c","c","d","e","e","f",NA),
"product" = c(1,1,"bla",1,2,3,3,4,4,5,6,6,7),
"price" = runif(13,5,6),
stringsAsFactors = TRUE)
dt2[, is.connected(r = region, n = product)] # false
with(dt2, neighbors(r=region, n=product))
dt2[, comparisons(region, product)]
# note that the region-product-combination [NA,7] is dropped
# from the output, while [a,2] and [e,5] are not included in
# the calculation of 'n_obs' as both are not useable in terms
# of regional price comparisons. also sparsity() takes this
# into account, if wanted:
dt2[, sparsity(region, product, useable=TRUE)]
dt2[, sparsity(region, product)]
# connect the price data:
dt2[connect(r=region, n=product),]