A policy portfolio is a collection of simple assessments of the presence or absense of state intervention in a specific area (Target) using a concrete state capacity (Instrument). How specific or general the area is, is up to the researcher. How broad or restricted is the collection of assessments is also up to the researcher (Adam, Knill, and Fernandez-i-Marín 2017). Using policy portfolios as objects of analysis allows political science to standardize comparitive policy analysis by providing a common ground of policy intervention, and represents a first step of comparing state intervention in different fields of public life.
The package has two sorts of families of functions to deal with policy portfolios. One set is intended to facilitate the management of portfolio data, either coming from external sources or once it has been treated in
R. The second set of functions is intended to facilitate the analysis and visualization of policy portfolio data.
This document requires the following packages:
library(dplyr) library(tidyr) library(ggplot2)
Structure and characteristics
The input data required for the package to work with is a tidy dataset (Wickham 2014), where every observation is a row and every variable is a column. This makes the data easy to manipulate, model and visualize.
Two fake dataset to show the possibilities of the package has been created, and they can be accessed using the
There are two portfolios, one in the energy sector (
P.energy) and one in the education sector (
P.education). The energy one looks like follows:
## # A tibble: 12,375 x 6 ## Country Sector Year Instrument Target covered ## <fct> <fct> <int> <fct> <fct> <dbl> ## 1 Syldavia Energy 2020 Instrument 11 Target 16 0 ## 2 Syldavia Energy 2021 Instrument 11 Target 16 0 ## 3 Syldavia Energy 2022 Instrument 11 Target 16 0 ## 4 Syldavia Energy 2023 Instrument 11 Target 16 0 ## 5 Syldavia Energy 2024 Instrument 11 Target 16 0 ## 6 Syldavia Energy 2025 Instrument 11 Target 16 0 ## 7 Syldavia Energy 2026 Instrument 11 Target 16 0 ## 8 Syldavia Energy 2027 Instrument 11 Target 16 0 ## 9 Syldavia Energy 2028 Instrument 11 Target 16 0 ## 10 Syldavia Energy 2029 Instrument 11 Target 16 0 ## # … with 12,365 more rows
library(PolicyPortfolios) data(PolicyPortfolio) P.energy
P.energy is a tidy data frame (a tibble) that contains 12,375 rows and 6 variables. 5 of the variables are markers of the case, and only one (“covered”) is in fact actual data. It indicates whether in the corresponding observation (defined by “Country”, “Sector”, “Year”, “Instrument” and “Target”) there is policy intervention (1) or not (0).
In this case, the
P.energy dataset contains several countries and traces them over several years:
##  "Syldavia" "Borduria" "San Theodoros"
##  2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030
The portfolio is in fact the combination of a two-dimensional space composed by policy Targets (“Target”) and the policy Instruments (“Instruments”) than can be used to address such targets.
##  "Target 16" "Target 17" "Target 18" "Target 19" "Target 20" ##  "Target 21" "Target 22" "Target 23" "Target 24" "Target 25" ##  "Target 26" "Target 27" "Target 28" "Target 29" "Target 30" ##  "Target 31" "Target 32" "Target 33" "Target 34" "Target 35" ##  "Target 36" "Target 37" "Target 38" "Target 39" "Target 40"
##  "Instrument 11" "Instrument 12" "Instrument 13" "Instrument 14" ##  "Instrument 15" "Instrument 16" "Instrument 17" "Instrument 18" ##  "Instrument 19" "Instrument 20" "Instrument 21" "Instrument 22" ##  "Instrument 23" "Instrument 24" "Instrument 25"
The variable “Sector” is only introduced to be able to compare policy sectors. Only policy sectors with the same combinations of Instruments and Targets can be in the same dataset. Otherwise it is understood that the total combination of Targets and Instruments is the one that defines the portfolio. Therefore, is preferable to work with separated portfolios when the space defined by Targets and Instruments is different. For instance, in the portfolio of the education sector, the countries and years are equal as in the energy, but the targets and instruments differ:
##  "Target 1" "Target 10" "Target 11" "Target 12" "Target 13" ##  "Target 14" "Target 15" "Target 2" "Target 3" "Target 4" ##  "Target 5" "Target 6" "Target 7" "Target 8" "Target 9"
##  "Instrument 1" "Instrument 10" "Instrument 2" "Instrument 3" ##  "Instrument 4" "Instrument 5" "Instrument 6" "Instrument 7" ##  "Instrument 8" "Instrument 9"
Prepare a dataset with a portfolio structure
pp_clean() may help in transforming the data from a spreadsheet-like format into a tidy format.
By default, it uses a structure coming from the consensus research project. Guidelines for external experts to collect data on social and environmental policies are available, as well as the coding manual. An example of a speardsheet collecting data for policy portfolios in the Consensus project is the following: .
spreadsheet <- read.table(...) d <- pp_clean(spreadsheet, Sector = "Environmental", Year.name = "Year.Adopt", coding.category.name = "Coding.category", Instrument.name = "Instrument.No.", Target.name = "Item.No.") pp_complete()
pp_clean() easily transforms a wide format coming from a spreadsheet into a tidy object suitable for policy portfolio analysis, doing several checks on the consistency of the original data and helping to spot inconsistencies and to debug problems with the coding process.
The coding process involves looking for instances where there is policy intervention in different scenarios, and therefore in cases (Instruments and Targets) when even not a single case of policy intervention has been observed the data would not include such a space. For instance, we may be interested in recording whether there is policy intervention in, say, providing funds for schools when there is a disabled student in a clasroom. But if we do not observe any single case in the portfolio, the final dataset will not contain this possibility, and therefore we must complete the observed portfolio with the potential full range of Targets and instruments. THis is achieved with the
dc <- pp_complete(d, Instrument.set = full.factor.of.potential.instruments, Target.set = full.factor.of.potential.targets)
One the dataset is cleaned and complete we may proceed to its analysis.
Analyze policy portfolios
One the structure of the tidy dataset required is clear, we can start using the functions to extract information of interest from it.
The main function that summarizes the characteristics of the portfolio is
pp_measures(). It takes a tidy portfolio data frame as input and produces a tidy data frame with entries for all the Countries and Years of the original input plus several measures with their corresponding values.
|Syldavia||Energy||2020||n.Instruments||2.00000||Number of instruments covered|
|Syldavia||Energy||2020||p.Instruments||0.13333||Proportion of instruments covered|
|Syldavia||Energy||2020||n.Targets||2.00000||Number of targets covered|
|Syldavia||Energy||2020||p.Targets||0.08000||Proportion of targets covered|
|Syldavia||Energy||2020||Unique||2.00000||Number of unique instrument configurations|
|Syldavia||Energy||2020||C.eq||0.46667||Equality of Instrument configurations|
|Syldavia||Energy||2021||n.Instruments||2.00000||Number of instruments covered|
|Syldavia||Energy||2021||p.Instruments||0.13333||Proportion of instruments covered|
id allows to explicitly ask for concrete portfolios, defined by the elements of the list that is passed.
pp_measures(P.energy, id = list(Country = "Borduria", Year = 2010:2021))
## # A tibble: 22 x 6 ## Country Sector Year Measure value Measure.label ## <fct> <fct> <int> <fct> <dbl> <fct> ## 1 Borduria Energy 2020 Space 3.75e+2 Portfolio space ## 2 Borduria Energy 2020 Size 3.47e-2 Portfolio size ## 3 Borduria Energy 2020 n.Instrume… 9.00e+0 Number of instruments covered ## 4 Borduria Energy 2020 p.Instrume… 6.00e-1 Proportion of instruments cov… ## 5 Borduria Energy 2020 n.Targets 1.20e+1 Number of targets covered ## 6 Borduria Energy 2020 p.Targets 4.80e-1 Proportion of targets covered ## 7 Borduria Energy 2020 Unique 7.00e+0 Number of unique instrument c… ## 8 Borduria Energy 2020 C.eq 6.59e-1 Equality of Instrument config… ## 9 Borduria Energy 2020 Div.gs 4.60e-1 Diversity (Gini-Simpson) ## 10 Borduria Energy 2020 Div.sh 2.77e-2 Diversity (Shannon) ## # … with 12 more rows
As a tidy dataset itself, the output of
pp_measures() can be easily combined with other functions to produce figures or tables of interest:
pp_measures(P.energy) %>% # Use only a single measure of interest filter(Measure == "Size") %>% # Use only observations with a concrete time period filter(Year > 2022) %>% # Convert the long format into wide, and therefore "Size" becomes a column spread(Measure, value) %>% # Pass this object to "ggplot()" and produce a time series of portfolio "Size" ggplot(aes(x = Year, y = Size, color = Country)) + geom_line()
In this sense, the output produced by the functions in the package is directly suitable for being used by
ggplot2, based on the grammar of graphics (Wilkinson et al. 2005), which empowers
R users by allowing them to flexibly crate graphics (Wickham 2009).
pp_measures(P.energy) %>% # Pick the two measures of portfolio diversity filter(Measure %in% c("Div.gs", "Div.sh")) %>% # Use only the last year observation filter(Year == max(Year)) %>% # Select only the relevant variables required to produce the output table select(Country, Measure.label, value) %>% # Transform the long object into wide, so that every Measure is one column spread(Measure.label, value) %>% # Sort by decreasing Shannon diversity arrange(desc(`Diversity (Shannon)`))
## # A tibble: 3 x 3 ## Country `Diversity (Gini-Simpson)` `Diversity (Shannon)` ## <fct> <dbl> <dbl> ## 1 Borduria 0.603 0.370 ## 2 Syldavia 0.100 0.0277 ## 3 San Theodoros 0 0
The current list of Measures that
pp_measures() produces is the following:
|n.Instruments||Number of instruments covered|
|p.Instruments||Proportion of instruments covered|
|n.Targets||Number of targets covered|
|p.Targets||Proportion of targets covered|
|Unique||Number of unique instrument configurations|
|C.eq||Equality of Instrument configurations|
Visual display of portfolios
pp_plot() produces a visual representation of the two-dimensional space of policy Targets (horizontal axis) and Instruments (vertical axis) and whether such space is covered by policy intervention or not.
It requires a single policy portfolio, and therefore if the original tidy dataset includes several years or countries, this must be explicitly stated using the argument
pp_plot(P.energy, id = list(Country = "Borduria", Year = 2025))
pp_plot() produces a caption with the source of the data, a subtitle with the measures of the portfolio and the boxes are side by side, but all these features can be tunned in the arguments. Check the documentation for more details.
Several options can be passed to tune the visual aspect of the portfolio, namely
spacing, that includes separation between the boxes, dropping the subtitle with
subtitle and changing the default caption with
pp_plot(P.education, id = list(Country = "Borduria", Year = 2030), spacing = TRUE, subtitle = FALSE, caption = NULL)
pp_report() is an encompassing function that generates a report in html with detailed descritive analysis of the portfolios, both considering them individually as well as comparatively (comparing countries or measures).
It also contains several arguments that can help in the analysis, but the defaults are expected to be comprehensive and meaningful.
It is possible to transform the tidy policy portfolio data frame into an array, in case that operations in a matrix-like style are required to be performed. This can be achieved with the
A <- pp_array(P.energy) # Get the dimensions: # 3 is Country # 1 is Sector # 11 is Year # 15 is Instrument # 25 is Target dim(A)
##  3 1 11 15 25
PolicyPortfolios facilitates the generation of measures of policy portfolios and its visualization, as well as the cleaning process of such datasets. It only requires, as a central component, a tidy dataset that defines whether certain policy space defined by a Target and an Instrument is covered by policy intervention or not.
The development of
PolicyPortfolios (track changes, propose improvements, report bugs) can be followed at https://github.com/xfim/PolicyPortfolios.
Adam, Christian, Christoph Knill, and Xavier Fernandez-i-Marín. 2017. “Rule Growth and Government Effectiveness: Why It Takes the Capacity to Learn and Coordinate to Constrain Rule Growth.” Policy Sciences 50 (2). Springer: 241–68.
Wickham, Hadley. 2009. Ggplot2: Elegant Graphics for Data Analysis. Use R! Springer-Verlag. https://books.google.es/books?id=bes-AAAAQBAJ.
———. 2014. “Tidy Data.” Journal of Statistical Software 59 (1): 1–23. doi:10.18637/jss.v059.i10.
Wilkinson, L., D. Wills, D. Rope, A. Norton, and R. Dubbs. 2005. The Grammar of Graphics. Statistics and Computing. Springer-Verlag.