The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

Package {p2distance}


Type: Package
Title: Welfare's Synthetic Indicator
Version: 1.0.2
Date: 2026-08-24
Description: The welfare's synthetic indicator provides an ideal tool for measuring multi-dimensional concepts such as welfare, development, living standards, etc. It enables information from the various indicators to be aggregated into a single synthetic measure. The method was proposed by Pena (1977, ISBN:9788426001788) and further developed by Zarzosa and Somarriba (2012) <doi:10.1007/s11205-012-0005-0>.
License: GPL-2 | GPL-3 [expanded from: GPL]
LazyLoad: yes
URL: https://github.com/ajpelu/p2distance, https://ajpelu.github.io/p2distance/
BugReports: https://github.com/ajpelu/p2distance/issues
Encoding: UTF-8
RoxygenNote: 8.0.0
Config/Needs/website: rmarkdown
Suggests: cranlogs, dplyr, ggplot2, lubridate, tidyr
NeedsCompilation: no
Packaged: 2026-09-07 11:38:20 UTC; ajpelu
Author: Antonio J. Pérez-Luque ORCID iD [aut, cre], Ricardo Moreno [ctb], Ramón Pérez-Pérez [aut], Francisco J. Bonet-García [ctb]
Maintainer: Antonio J. Pérez-Luque <ajpelu@gmail.com>
Repository: CRAN
Date/Publication: 2026-09-15 11:50:02 UTC

p2distance: Welfare's Synthetic Indicator

Description

The welfare's synthetic indicator (see references) provides an ideal tool for measuring multi-dimensional concepts such as welfare, development, living standards, etc. It enables information from various indicators to be aggregated into a single synthetic measure. This synthetic indicator, also called P_2 distance, overcomes several limitations of other traditional approaches, such as Principal Component Analysis (PCA) or Data Envelopment Analysis (DEA), and offers good statistical properties, allowing both inter-spatial and inter-temporal comparisons.

Details

The main function of the package is p2distance().

Author(s)

Maintainer: Antonio J. Pérez-Luque ajpelu@gmail.com (ORCID)

Authors:

Other contributors:

References

Peña, J. B. (1977). Problemas de la medición del bienestar y conceptos afines (una aplicación al caso Español). Madrid: INE.

Peña, J. B. (2009). La medición del bienestar social: una revisión crítica. Estudios de Economía Aplicada, 27(2), 299-324.

Somarriba, N. (2008). Aproximación a la medición de la calidad de vida en la Unión Europea. Doctoral Thesis. University of Valladolid.

Zarzosa, P. (1992). Aproximación a la medición del bienestar social, estudio de la idoneidad del indicador sintético Distancia P2. Doctoral Thesis. University of Valladolid.

Zarzosa, P. (1996). Aproximación a la medición del Bienestar social. Valladolid: Universidad de Valladolid.

See Also

Useful links:


Load a CSV file into a matrix object

Description

Reads a text file and converts it into the matrix object expected by p2distance().

Usage

loadCSVtoP2distance(
  path,
  header = TRUE,
  sep = "\t",
  dec = ".",
  quote = "\"",
  na.strings = "NA",
  fileEncoding = "",
  encoding = "unknown"
)

Arguments

path

The path of the file from which the data are to be read. Each row of the table appears as one line of the file.

header

A logical value indicating whether the file contains the names of the variables as its first line.

sep

The field separator character.

dec

The character used in the file for decimal points.

quote

The set of quoting characters. To disable quoting altogether, use quote = "".

na.strings

A character vector of strings to be interpreted as NA values.

fileEncoding

Character string: if non-empty, declares the encoding used in the file so the character data can be re-encoded. See the "Encoding" section of ?file.

encoding

Encoding to be assumed for input strings.

Details

The first column of the file is used to set the row names of the resulting matrix (typically the name of each spatial entity), and is then removed from the data itself. Internally this uses utils::read.table() to read the file.

Value

A matrix containing the data from the CSV file, ready to be passed to p2distance().

See Also

p2distance()


Make a reference vector

Description

A reference vector must be defined for each partial indicator so as to compare different spatial entities. This vector is used by p2distance() (as the base reference) to calculate the distance of each spatial entity from this reference base. It is common to use the minimum value as the base reference (see references).

Usage

makeReferenceVector(X, reference_vector_function = min)

Arguments

X

A data frame or matrix with n rows (entities) and m columns (variables).

reference_vector_function

Function used to build the reference vector. Common choices are min, max, mean, median, etc. See apply() for details. min is the default.

Value

A vector with the reference value (base reference) for each variable. Its length equals the number of variables.

References

Peña, J. B. (1977). Problemas de la medición del bienestar y conceptos afines (una aplicación al caso Español). Madrid: INE.

Peña, J. B. (2009). La medición del bienestar social: una revisión crítica. Estudios de Economía Aplicada, 27(2), 299-324.

Somarriba, N. (2008). Aproximación a la medición de la calidad de vida en la Unión Europea. Doctoral Thesis. University of Valladolid.

Zarzosa, P. (1992). Aproximación a la medición del bienestar social, estudio de la idoneidad del indicador sintético Distancia P2. Doctoral Thesis. University of Valladolid.

See Also

p2distance()

Examples

## Create a data frame of 3 variables (indicators) for 6 entities (rows)
dat <- data.frame(
  x1 = c(10, 12, 13, 14, 12, 11),
  x2 = c(40, 51, 61, 68, 34, 44),
  x3 = c(0.43, 0.41, 0.39, 0.55, 0.60, 0.38)
)

## Calculate the reference vector using the minimum value of each variable
makeReferenceVector(dat, reference_vector_function = min)


Welfare's synthetic indicator (P2 distance)

Description

Calculates the P_2 distance synthetic indicator for a set of variables. This is the main function of the package.

Usage

p2distance(
  matriz,
  reference_vector = NULL,
  reference_vector_function = min,
  iterations = 20,
  umbral = 1e-04
)

Arguments

matriz

A matrix with spatial entities in rows and variables in columns.

reference_vector

Optional. A reference vector defined for each partial indicator, used to compare different spatial entities.

reference_vector_function

Optional. Function used to build the reference vector when reference_vector is not supplied. min is the default; other common choices are max, mean, median, etc. See makeReferenceVector() for details.

iterations

Maximum number of iterations for the computational process until convergence is reached.

umbral

The algorithm stops when the difference between two consecutive iterations is lower than this threshold.

Details

The P_2 distance, also called DP2, is used to measure welfare in quality-of-life applications, to build environmental quality indexes, and more generally to aggregate multiple partial indicators (variables) into a single measure that allows spatial entities to be compared. For a spatial entity r, the P_2 distance is defined as:

DP_{2}=\sum^{n}_{i=1}\left\lbrace\left(\frac{d_{i}}{\sigma_{i}}\right)\left(1-R^{2}_{i,i-1,i-2,\ldots,1}\right)\right\rbrace

with R^{2}_{1}=0, where d_{i}=|x_{ri}-x_{*i}|, with the reference base X_{*}=(x_{*1},x_{*2},\ldots,x_{*n}), and:

The numerical value of the DP2 index has no meaning by itself, but it is useful for comparing the state of different spatial entities in terms of welfare, environmental conditions, etc.

Value

A list with the following elements:

References

Ivanovic, B. (1974). Comment établir une liste des indicateurs de developpment. Revue de Statistique Appliquée, 22(2), 37-50.

Montero, J. M., Chasco, C., & Larraz, B. (2010). Building an environmental quality index for a big city: a spatial interpolation approach combined with a distance indicator. Journal of Geographical Systems, 12, 435-459.

Peña, J. B. (1977). Problemas de la medición del bienestar y conceptos afines (una aplicación al caso Español). Madrid: INE.

Peña, J. B. (2009). La medición del bienestar social: una revisión crítica. Estudios de Economía Aplicada, 27(2), 299-324.

Zarzosa, P. (1996). Aproximación a la medición del Bienestar social. Valladolid: Universidad de Valladolid.

Zarzosa, P., & Somarriba, N. (2012). An assessment of social welfare in Spain: Territorial analysis using a synthetic welfare indicator. Social Indicators Research. doi:10.1007/s11205-012-0005-0

See Also

makeReferenceVector(), loadCSVtoP2distance()

Examples

## Calculate a welfare indicator for 27 European countries
data(welfare)
welfare <- as.matrix(welfare)

ind <- p2distance(welfare, reference_vector_function = min, iterations = 20)

## Examine the results
ind$p2distance
ind$iteration
ind$variables_sort
ind$correction_factors
ind$cor.coeff
ind$discrimination.coefficient

## Plot of the P2 distance indicator for European countries
barplot(ind$p2distance, beside = TRUE, col = "white", space = .3,
  ylab = "P2 distance", ylim = c(0, 20),
  names.arg = rownames(ind$p2distance), las = 3, cex.names = 0.8)


Welfare indicators of European countries

Description

Quality of life indicators (welfare indicators) for 27 countries of the European Union during the 2002-2007 period. For each variable (i.e. indicator), both its definition and the year it refers to are given. The data come from EurLIFE, an interactive database on quality of life in Europe (see Source).

Usage

data(welfare)

Format

A data frame with 27 rows and 20 columns:

Details

These quality of life indicators come from different sources (Standard Eurobarometer Surveys, European Quality of Life Surveys, Eurostat, European Foundation for the Improvement of Living and Working Conditions) collated by EurLIFE.

Source

EurLIFE database. Interactive database on quality of life in Europe. European Foundation for the Improvement of Living and Working Conditions (Eurofound). Accessed 20 Feb 2012.

References

Somarriba, N., & Peña, B. (2009). Synthetic Indicators of Quality of Life in Europe. Social Indicators Research, 94, 115-133.

Examples

data(welfare)

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.