QuestionMap: QuestionMap

QuestionMapR Documentation

QuestionMap

Description

An R6 QuestionMap object holds the mapping for one question or demographic between the sample data and population data.

Methods

Public methods


Method new()

Create a new QuestionMap

Usage
QuestionMap$new(name, col_names, values_map)
Arguments
name

The name of the underlying construct. For example if the sample data uses the name "age_bracket" and the population data uses the name "age_group" then name could be "age". This name will be used later in the workflow when creating a data set with unified names.

col_names

A character vector of length two giving the column names of the question in the sample data (first element) and the population data (second element).

values_map

A named list where the names correspond to the responses to the question in the sample data and the values correspond to the responses in the population data. In some cases multiple values in the sample may correspond to a single value in the population, or vice versa (e.g., the sample survey has age groups 18-25 and 26-35 but the population data only uses 18-35, see Examples).

If there is a meaningful ordering over the values, they should be listed in that order, either descending or ascending. Note that if responses were given with both the values in the data and the actual responses given (useful as these will be used for plotting), the mapping should use the values in the data (generally shorter). See Examples.

Returns

A QuestionMap object that can be added to a SurveyMap object.

Examples
q_age <- QuestionMap$new(
  name = "age",
  col_names = c("age","age_group"),
  values_map = list(
    "18-25" = "18-35",
    "26-35" = "18-35",
    "36-45" = "36-55",
    "46-55" = "36-55",
    "56-65" = "56-65",
    "66-75" = "66+",
    "76-90" = "66+"
  )
)
print(q_age)

q_gender <- QuestionMap$new(
  name = "gender",
  col_names = c("gender", "gender"),
  values_map = list("male" = "m","female" = "f", "nonbinary" = "nb")
)
print(q_gender)

q_party_pref <- QuestionMap$new(
  name = "party_pref",
  col_names = c("vote_for", "vote_pref"),
  values_map = list(
    "Box Party" = "The BP",
    "The BP" = "The BP",
    "The Circle Party" = "The Circles",
    "The Circles" = "The Circles"
  )
)
print(q_party_pref)


Method print()

Print a QuestionMap.

Usage
QuestionMap$print(...)
Arguments
...

Currently ignored.

Returns

The QuestionMap object, invisibly.


Method name()

Access name

Usage
QuestionMap$name()
Returns

A string.


Method col_names()

Access col_names

Usage
QuestionMap$col_names()
Returns

A character vector of length 2.


Method values()

Access values

Usage
QuestionMap$values()
Returns

A data frame.


Method clone()

The objects of this class are cloneable with this method.

Usage
QuestionMap$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples


## ------------------------------------------------
## Method `QuestionMap$new`
## ------------------------------------------------

q_age <- QuestionMap$new(
  name = "age",
  col_names = c("age","age_group"),
  values_map = list(
    "18-25" = "18-35",
    "26-35" = "18-35",
    "36-45" = "36-55",
    "46-55" = "36-55",
    "56-65" = "56-65",
    "66-75" = "66+",
    "76-90" = "66+"
  )
)
print(q_age)

q_gender <- QuestionMap$new(
  name = "gender",
  col_names = c("gender", "gender"),
  values_map = list("male" = "m","female" = "f", "nonbinary" = "nb")
)
print(q_gender)

q_party_pref <- QuestionMap$new(
  name = "party_pref",
  col_names = c("vote_for", "vote_pref"),
  values_map = list(
    "Box Party" = "The BP",
    "The BP" = "The BP",
    "The Circle Party" = "The Circles",
    "The Circles" = "The Circles"
  )
)
print(q_party_pref)


lauken13/mrpkit documentation built on Aug. 6, 2023, 3:42 a.m.