Title: | Access the Polarization in Comparative Attitudes Project |
---|---|
Description: | Distributes data from the Polarization in Comparative Attitudes Project. Helper functions enable data retrieval in wide and tidy formats for user-defined countries and years. Provides support for case-insensitive country names in many languages. Mehlhaff (2022) <https://imehlhaff.net/files/Polarization%20and%20Democracy.pdf>. |
Authors: | Isaac Mehlhaff [aut, cre, cph]
|
Maintainer: | Isaac Mehlhaff <[email protected]> |
License: | CC0 |
Version: | 1.1.1 |
Built: | 2025-02-25 03:14:51 UTC |
Source: | https://github.com/imehlhaff/polarcap |
Retrieves PolarCAP data for defined countries and years. Returns data in wide format. For tidy
format, use melt.PolarCAP()
.
get.PolarCAP( countries = NA, years = NA, type = c("ideology", "affect"), value.only = FALSE, include.se = FALSE )
get.PolarCAP( countries = NA, years = NA, type = c("ideology", "affect"), value.only = FALSE, include.se = FALSE )
countries |
a character vector of countries to be retrieved. See Details. |
years |
a numeric vector of years to be retrieved. |
type |
a character vector indicating which polarization estimates should be returned. Must be
|
value.only |
a logical indicating whether |
include.se |
a logical indicating whether standard errors should be returned. Defaults to
|
Ideally, country names passed to countries
would be ISO 3166-1 alpha-3 country codes
(case-insensitive). However, get.PolarCAP()
will accept country names in almost any language or
format and attempt to convert them to ISO3 codes by calling to.ISO3()
.
get.PolarCAP()
will alert the user to any country names still unrecognized after this
conversion and return results only for those which are recognized.
If value.only = FALSE
, get.PolarCAP()
returns a data frame with columns
corresponding to country names, country ISO3 codes, years, polarization estimates for the
polarization type(s) given in type
, and associated standard errors (if
include.se = TRUE
). If value.only = TRUE
, get.PolarCAP()
returns a scalar
polarization estimate for the polarization type given in type
.
get.PolarCAP("USA", c(2018, 2019), "ideology", include.se = TRUE) get.PolarCAP("USA", c(2018, 2019), c("ideology", "affect"), include.se = TRUE) countries <- rep(c("MEX", "USA"), each = 2) years <- rep(c(2018, 2019), 2) data <- as.data.frame(cbind(countries, years)) data$ideology1 <- apply(data, 1, function(x) get.PolarCAP(x[1], x[2], type = "ideology", value.only = TRUE)) data
get.PolarCAP("USA", c(2018, 2019), "ideology", include.se = TRUE) get.PolarCAP("USA", c(2018, 2019), c("ideology", "affect"), include.se = TRUE) countries <- rep(c("MEX", "USA"), each = 2) years <- rep(c(2018, 2019), 2) data <- as.data.frame(cbind(countries, years)) data$ideology1 <- apply(data, 1, function(x) get.PolarCAP(x[1], x[2], type = "ideology", value.only = TRUE)) data
Retrieves PolarCAP data for defined countries and years. Returns data in tidy format. For wide
format, or to return a polarization estimate as a scalar, use get.PolarCAP()
.
melt.PolarCAP( countries = NA, years = NA, type = c("ideology", "affect"), include.se = FALSE )
melt.PolarCAP( countries = NA, years = NA, type = c("ideology", "affect"), include.se = FALSE )
countries |
a character vector of countries to be retrieved. See Details. |
years |
a numeric vector of years to be retrieved. |
type |
a character vector indicating which polarization estimates should be returned. Must be
|
include.se |
a logical indicating whether standard errors should be returned. Defaults to
|
Ideally, country names passed to countries
would be ISO 3166-1 alpha-3 country codes
(case-insensitive). However, melt.PolarCAP()
will accept country names in almost any language or
format and attempt to convert them to ISO3 codes by calling to.ISO3()
.
melt.PolarCAP()
will alert the user to any country names still unrecognized after this
conversion and return results only for those which are recognized.
a data frame with columns corresponding to country names, country ISO3 codes, years,
polarization types given in type
, polarization estimates, and associated standard errors (if
include.se = TRUE
).
melt.PolarCAP("USA", c(2018, 2019), "ideology", include.se = TRUE) melt.PolarCAP("USA", c(2018, 2019), c("ideology", "affect"), include.se = TRUE)
melt.PolarCAP("USA", c(2018, 2019), "ideology", include.se = TRUE) melt.PolarCAP("USA", c(2018, 2019), c("ideology", "affect"), include.se = TRUE)
Checks if requested countries are formatted correctly for PolarCAP and attempts to convert them to ISO 3166-1 alpha-3 country codes if not.
to.ISO3(countries)
to.ISO3(countries)
countries |
a character vector of countries to be checked (case-insensitive). |
a character vector of length equal to that of countries
.
to.ISO3(c("ALB", "aus", "united states"))
to.ISO3(c("ALB", "aus", "united states"))