← Back to list

polaR

In addition to the encyclopedia, our R package polaR makes all our code available online and lets other researchers reproduce and test our knowledge on polarization more easily.

Introduction & Installation

Right now, it is only available on GitLab. While we are working on polishing the package and making it available on CRAN, you can install it from here using devtools:

devtools::install_gitlab("felixgruenewald/polaR")

Importing Data

Different datasets use different variable names and scales for the same items. The package therefore contains an import function that takes a range of datasets and recodes names, scales and missing values into a consistent pattern on the base of which the measures can be computed. For this, a pre-defined dictionary containing all relevant variables is used to look up the variable names for the dataset specified under the source option, and transforms them accordingly. polaR:::var_dict() shows the renaming pattern and variables used for this. You can load and adapt or add to the dictionary to increase the number of variables or datasets compatible with the package. With the option keep_all option, you can opt between importing all variables in the dataset, or just those that are relevant to the computation of measures.

cses <- polaR_import(source = "cses", path = "path/to/cses.dta", keep_all = F)
ess <- polaR_import(source = "ess", path = "path/to/ess.sav", keep_all = F)

Measures

polaR includes a range of different measures that can be computed with various datasets. Some measures, like the CSES polarization index, are linked to a specific dataset. Others, like the standard deviation of issue self-placements of respondents or spread of party positions, can be computed with different data sources. Wherever it is possible to compute a measure, the package offers the possibility to do so.

sd_mass <- sd_mass(dataset = cses, issue =  "leftright")
sd_mass <- sd_mass(dataset = ess, issue =  "leftright")

Individual & Aggregate Level

Some measures work on the individual level, i.e., they add an additional polarization variables for every respondent in the original dataset. This is the case for e.g. the Spread of Like-Dislike scores by Wagner. With aggregate, you can choose whether the function puts out the full dataset with the additional individual level variables, or already a country-year aggregation of the measure.

cses <- spread_likedislike(cses, weighted = TRUE, aggregate = FALSE)
agg_spread <- spread_likedislike(cses, weighted = TRUE, aggregate = TRUE)

Other measures are computed directly on a country-year level and do not have an individual level, like here the standard deviation of participants’ left-right self-positioning, the CSES Polarization Index by Dalton or API by Reiljan:

sd_mass <- sd_mass(cses, issue =  "leftright")
polarization_index <- cses_polarization_index(cses)
api_cses <- api(cses)

Weighted Measures

Some measures have weighted variations. With weighted, you can toggle between the two versions.

spread_wgt <- spread_likedislike(cses, weighted = TRUE, aggregate = TRUE)
spread <- spread_likedislike(cses, weighted = FALSE, aggregate = TRUE)

Issue Dimension

Measures like the perception of party positions can have different issue dimensions. With issue, it can be defined which dimension the measure should be computed on.

range_lr <- range_ind(data, issue = "leftright", aggregate = TRUE)
range_se <- range_ind(data, issue = "socioeconomic", aggregate = TRUE)

Expert measures

Expert measures are somewhat of a special case, as they follow a different logic than the rest of the dataset, with many data points for the exact same expert score. For individual, respondent-based datasets, the dataset first needs to be broken down to unique country-year cases and then the measure can be calculated.

sd_expert <- sd_expert_parties(cses, issue =  "leftright")