Description Usage Arguments Details Value Author(s) See Also Examples
Simple analyses of conjoint (factorial) experiments and visualization of results.
1 2 3 4 5 6 7 8 9 10 11 12 |
data |
A data frame containing variables specified in |
formula |
A formula specifying a model to be estimated. ; all levels across features should be unique. For |
id |
An RHS formula specifying a variable holding respondent identifiers, to be used for clustering standard errors. |
weights |
An (optional) RHS formula specifying a variable holding survey weights. |
estimate |
A character string specifying an estimate type. Current options are average marginal component effects (or AMCEs, “amce”, estimated via |
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 |
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 |
by |
A formula containing only RHS variables, specifying grouping factors over which to perform estimation. |
... |
Additional arguments to |
The main function cj
is a convenience function wrapper around the underlying estimation functions that provide for average marginal component effects (AMCEs), by default, via the amce
function, marginal means (MMs) via the mm
function, and display frequencies via cj_freqs
and cj_props
. Additional estimands may be supported in the future through their own functions and through the cj
interface. Plotting is provided via ggplot2 for all types of estimates.
The only additional functionality provided by cj
over the underlying functions is the by
argument, which will perform operations on subsets of data
, returning a single data frame. This can be useful, for example, for evaluating profile spillover effects and subgroup results, or in any situation where one might be inclined to use a for
loop or lapply
, calling cj
repeatedly on subgroups.
Note: Some features of cregg (namely, the amce_diffs
) function, or estimate = "amce_diff"
here) only work with full factorial conjoint experiments. Designs involving two-way constraints between features are supported simply by expressing interactions between constrained terms in formula
(again, except for amce_diffs
). Higher-order constraints may be supported in the future.
A data frame with special class to facilitate plotting (e.g., “cj_amce”, “cj_mm”, etc.)
Thomas J. Leeper <thosjleeper@gmail.com>
Functions: amce
, mm
, cj_freqs
, mm_diffs
, plot.cj_amce
, cj_tidy
Data: immigration
, taxes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | # load data
requireNamespace("ggplot2")
data("immigration")
immigration$contest_no <- factor(immigration$contest_no)
data("taxes")
# calculate MMs
f1 <- ChosenImmigrant ~ Gender + Education +
LanguageSkills + CountryOfOrigin + Job + JobExperience +
JobPlans + ReasonForApplication + PriorEntry
d1 <- cj(immigration, f1, id = ~ CaseID, estimate = "mm", h0 = 0.5)
# plot MMs
plot(d1, vline = 0.5)
# calculate MMs for survey-weighted data
d1 <- cj(taxes, chose_plan ~ taxrate1 + taxrate2 + taxrate3 +
taxrate4 + taxrate5 + taxrate6 + taxrev, id = ~ ID,
weights = ~ weight, estimate = "mm", h0 = 0.5)
# plot MMs
plot(d1, vline = 0.5)
# MMs split by profile number
stacked <- cj(immigration, f1, id = ~ CaseID,
estimate = "mm", by = ~ contest_no)
## plot with grouping
plot(stacked, group = "contest_no", vline = 0.5, feature_headers = FALSE)
## plot with facetting
plot(stacked) + ggplot2::facet_wrap(~ contest_no, nrow = 1L)
# estimate AMCEs
d2 <- cj(immigration, f1, id = ~ CaseID)
# plot AMCEs
plot(d2)
## subgroup analysis
immigration$ethnosplit <- cut(immigration$ethnocentrism, 2)
x <- cj(na.omit(immigration), ChosenImmigrant ~ Gender + Education + LanguageSkills,
id = ~ CaseID, estimate = "mm", h0 = 0.5, by = ~ ethnosplit)
plot(x, group = "ethnosplit", vline = 0.5)
# combinations of/interactions between features
immigration$language_entry <-
interaction(immigration$LanguageSkills, immigration$PriorEntry, sep = "_")
## higher-order MMs for feature combinations
cj(immigration, ChosenImmigrant ~ language_entry,
id = ~CaseID, estimate = "mm", h0 = 0.5)
## constrained designs
## in a constrained design, some cells are unobserved:
subset(cj_props(immigration, ~ Job + Education), Proportion == 0)
## MMs and AMCEs only use data from observed cells
## In `immigraation`, this means while the MM for `Job == "Janitor"` is an average
## across all levels of Education:
mm(subset(immigration, Job == "Janitor"), ChosenImmigrant ~ Education)
## the MM for `Job == "Doctor"` is an average across only 3 levels of education:
mm(subset(immigration, Job == "Doctor"), ChosenImmigrant ~ Education)
## Use `cj_props()` to see constraints:
subset(cj_props(immigration, ~ Job + Education), Job == "Doctor" & Proportion != 0)
## Substantively, the MM of "Doctor" might be higher than other levels of `Job`
## this could be due to the feature itself or due to the fact that it is constrained
## with a different subset of other feature levels than alternative levels of `Job`
## this may mean analysts want to report MMs (or AMCEs) only for the unconstrained levels:
elev <- c("Two-Year College", "College Degree", "Graduate Degree")
jlev <- c("Financial Analyst", "Computer Programmer", "Research Scientist", "Doctor")
mm(subset(immigration, Education %in% elev), ChosenImmigrant ~ Job)
mm(subset(immigration, Job %in% jlev), ChosenImmigrant ~ Education)
## or, present estimates excluding constrained levels:
mm(subset(immigration, !Education %in% elev), ChosenImmigrant ~ Job)
mm(subset(immigration, !Job %in% jlev), ChosenImmigrant ~ Education)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.