cj_freqs: Conjoint feature frequencies

Description Usage Arguments Details Value See Also Examples

View source: R/cj_freqs.R

Description

Tabulate and visualize conjoint features, and their display frequencies and proportions

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
cj_freqs(
  data,
  formula,
  id = NULL,
  weights = NULL,
  feature_order = NULL,
  feature_labels = NULL,
  level_order = c("ascending", "descending"),
  ...
)

cj_props(data, formula, id, weights = NULL, margin = NULL, ...)

cj_table(
  data,
  formula,
  feature_order = NULL,
  feature_labels = NULL,
  level_order = c("ascending", "descending"),
  include_reference = FALSE,
  ...
)

Arguments

data

A data frame containing variables specified in formula. All RHS variables should be factors; all levels across features should be unique.

formula

An RHS formula specifying conjoint features to tabulate. All RHS variables should be factors; all levels across features should be unique.

id

An RHS formula specifying a variable holding respondent identifiers, to be used for clustering standard errors. By default, data are unclustered.

weights

An (optional) RHS formula specifying a variable holding survey weights.

feature_order

An (optional) character vector specifying the names of feature (RHS) variables in the order they should be encoded in the resulting data frame.

feature_labels

A named list of “fancy” feature labels to be used in output. By default, the function looks for a “label” attribute on each variable in formula and uses that for pretty printing. This argument overrides those attributes or otherwise provides fancy labels for this purpose. This should be a list with names equal to variables on the righthand side of formula and character string values; arguments passed here override variable attributes.

level_order

A character string specifying levels (within each feature) should be ordered increasing or decreasing in the final output. This is mostly only consequential for plotting via plot.cj_mm, etc.

...

Ignored.

margin

A numeric value passed to prop.table. If NULL overall proportions are calculated.

include_reference

A logical indicating whether to include a “reference” column that indicates whether a feature level is the reference category for that feature. Default is FALSE.

Details

These functions provide related but slightly different functionality. cj_table simply creates a data frame of features and their levels, which is useful for printing. cj_props provides tidy proportion tables to examine cross-feature restrictions in conjoint designs that are not equally randomized. This enables, for example, tabulation and visualization of complete restrictions (where combinations of two or more features are not permitted), as well as calculation of AMCEs for constrained designs appropriately weighted by the display proportions for particular combinations of features.

cj_freqs provides marginal display frequencies, which are a descriptive check on the presentation of individual conjoint features (for example, to ensure equal or intentionally unequal appearance of levels). This is mostly useful for plotting functionality provided in plot.cj_freqs, which provides barcharts for the frequency with which each level of each feature was presented.

Value

A data frame of class “cj_freqs”, “cj_props”, etc.

See Also

plot.cj_mm

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
data(immigration)
# identify all levels
cj_table(immigration, ~ Gender + Education + LanguageSkills)
cj_table(immigration, ~ Gender + Education + LanguageSkills, include_ref = TRUE)

# display frequencies
(f <- cj_freqs(immigration, ~ Gender + Education + LanguageSkills, id = ~ CaseID))

# restrictions
## check display proportions
cj_props(immigration, ~ Job, id = ~ CaseID)
## check which combinations were not allowed
subset(cj_props(immigration, ~ Job + Education, id = ~ CaseID), Proportion == 0)


# plotting
(p <- plot(f))

## change ggplot2 theme
p + ggplot2::theme_bw()

## monochrome bars
p + ggplot2::scale_fill_manual(values = rep("black", 9)) + 
  ggplot2::theme(legend.position = "none")

cregg documentation built on July 8, 2020, 6:57 p.m.