factorEx: Design and Analysis for Factorial Experiments

CRAN Version Build Status

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:

Installation Instructions

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)

Examples

(1) Design-based Confirmatory Analysis

Here, we use the conjoint experiment that randomized profiles according to the marginal population randomization design.

Case 1: Use Marginal Distributions for Target Profile Distributions

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"))

Case 2: Use Combination of Marginal and Partial Joint Distributions for Target Profile Distribution

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)

(2) Model-based Exploratory Analysis {#model}

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"))


naoki-egami/factorEx documentation built on Oct. 8, 2022, 5:41 a.m.