Description:
R package factorEx
provides design-based and model-based estimators for the population average marginal component effects (the pAMCE) in factorial experiments, including conjoint analysis. The package also implements a series of recommendations offered in de la Cuesta, Egami, and Imai (2022, PA) and Egami and Imai (2019, JASA).
Authors:
References:
de la Cuesta, Egami, and Imai. (2022). Improving the External Validity of Conjoint Analysis: The Essential Role of Profile Distribution. Political Analysis, Vol.30, No.1 (January), pp. 19–45.
Egami and Imai. (2019). Causal Interaction in Factorial Experiments: Application to Conjoint Analysis. Journal of the American Statistical Association, Vol.114, No.526 (June), pp. 529–540.
factorEx
is available on CRAN and can be installed using:
install.packages("factorEx")
You can also install the most recent development version using the devtools
package. First you have to install devtools
using the following code. Note that you only have to do this once:
if(!require(devtools)) install.packages("devtools")
Then, load devtools
and use the function install_github()
to install factorEx
:
library(devtools) install_github("naoki-egami/factorEx", dependencies=TRUE)
Design-based Confirmatory Analysis
Model-based Exploratory Analysis
Here, we use the conjoint experiment that randomized profiles according to the marginal population randomization design.
When using marginal distributions, target_dist
should be a list and each element should have a factor name. Within each list, a numeric
vector should have the same level names as those in data
.
## Load the package and data library(factorEx) data("OnoBurden") OnoBurden_data_pr <- OnoBurden$OnoBurden_data_pr # randomization based on marginal population design # we focus on target profile distributions based on Democratic legislators. # See de la Cuesta, Egami, and Imai (2019+) for details. target_dist_marginal <- OnoBurden$target_dist_marginal target_dist_marginal
We can estimate the pAMCE with design_pAMCE
with target_type = "marginal"
. Use factor_name
to specify for which factors we estimate the pAMCE.
out_design_mar <- design_pAMCE(formula = Y ~ gender + age + family + race + experience + party + pos_security, factor_name = c("gender", "age", "experience"), data = OnoBurden_data_pr, pair_id = OnoBurden_data_pr$pair_id, cluster_id = OnoBurden_data_pr$id, target_dist = target_dist_marginal, target_type = "marginal") summary(out_design_mar)
Use plot
to visualize the estimated pAMCEs.
plot(out_design_mar, factor_name = c("gender", "experience"))
The use of partial joint distributions is useful because it can relax the assumption of no three-way or higher-order interactions (see de la Cuesta, Egami, and Imai (2019+)).
When using a combination of marginal and partial joint distributions, target_dist
should be a list and each element should be a numeric
vector (if marginal) or an array
/table
(if partial joint). Then, use argument partial_joint_name
to specify which factors are marginal and partial joints. In the following example, c("gender", "age", "family")
has the partial joint distributions over the three factors. race
and party
are based on the marginal distributions, respectively. c("experience", "pos_security")
has the partial joint distributions over the two factors. Within each list, a numeric
vector or an array
/table
should have the same level names as those in data
.
target_dist_partial <- OnoBurden$target_dist_partial target_dist_partial partial_joint_name <- list(c("gender", "age", "family"), "race", "party", c("experience", "pos_security"))
We can estimate the pAMCE with design_pAMCE
with target_type = "partial_joint"
and appropriate partial_joint_name
. The function can use factor_name
to specify for which factors we estimate the pAMCE.
out_design_par <- design_pAMCE(formula = Y ~ gender + age + family + race + experience + party + pos_security, factor_name = c("gender", "age", "race"), data = OnoBurden_data_pr, pair_id = OnoBurden_data_pr$pair_id, cluster_id = OnoBurden_data_pr$id, target_dist = target_dist_partial, target_type = "partial_joint", partial_joint_name = partial_joint_name) summary(out_design_par)
Here, we use the conjoint experiment that randomized profiles according to the uniform distribution and incorporate the target profile distribution in the analysis stage.
OnoBurden_data <- OnoBurden$OnoBurden_data # randomization based on uniform # due to large sample size, focus on "congressional candidates" for this example OnoBurden_data_cong <- OnoBurden_data[OnoBurden_data$office == "Congress", ] out_model <- model_pAMCE(formula = Y ~ gender + age + family + race + experience + party + pos_security, data = OnoBurden_data_cong, reg = TRUE, pair_id = OnoBurden_data_cong$pair_id, cluster_id = OnoBurden_data_cong$id, target_dist = target_dist_marginal, target_type = "marginal") summary(out_model, factor_name = c("gender"))
When sample = TRUE
, the function also reports the AMCE based on the in-sample profile distributions (sample AMCE
), which is the uniform AMCE in this example.
summary(out_model, factor_name = c("gender"), sample = TRUE)
Use plot
to visualize the estimated pAMCEs. When diagnose = TRUE
, it provides two diagnostic checks; specification tests and the check of bootstrap distributions.
plot(out_model, factor_name = c("gender"), diagnose = TRUE)
In the model-based analysis, we can also decompose the difference between the pAMCE and the uniform AMCE. Use effect_name
to specify which pAMCE we want to decompose. effect_name
has two elements; the first is a factor name and the second is a level name of interest.
decompose_pAMCE(out_model, effect_name = c("gender", "Female"))
Or use plot_decompose
to visualize the decomposition.
plot_decompose(out_model, effect_name = c("gender", "Female"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.