Takes a dataframe containing
id column
weight column
conjoint answer columns and either:
design version column with a design dataframe provided or:
raw design columns (not yet implemented)
and instructions on how to find these columns. Returns a list containing ...
Usage
cjt_parse_data(
data,
id_col,
answer_cols,
weight_col = NULL,
design_version_col = NULL,
design = NULL
)Arguments
- data
A data.frame.
- id_col
Quoted or unquoted id column name.
- answer_cols
Pattern of conjoint answer column names. Must contain "task" placeholder for the task number.
- weight_col
Quoted or unquoted weight column name.
- design_version_col
Quoted or unquoted design version column name.
- design
A design dataframe.
Examples
cjt_parse_data(
example_cjt_fp_responses,
id_col = response_id,
weight_col = weights,
answer_cols = "a{task}_m1_message_cjt",
design_version_col = cjt_version,
design = example_cjt_fp_design
)
#> $tidy_data
#> # A tibble: 20,052 × 6
#> id version task alt attributes$problem $policy $scope selected
#> <chr> <chr> <dbl> <dbl> <fct> <fct> <fct> <lgl>
#> 1 R_0001 1 1 1 Incarceration Neutra… Neutr… FALSE
#> 2 R_0001 1 1 2 Police End ov… Oppo … FALSE
#> 3 R_0001 1 1 3 Oppo - Violent crime wave Reduce… Finan… TRUE
#> 4 R_0001 1 2 1 Oppo - Lawless liberal ci… Reduce… Oppo … FALSE
#> 5 R_0001 1 2 2 Criminalizing not working Reduce… Neutr… TRUE
#> 6 R_0001 1 2 3 Oppo - Fentanyl Elimin… Finan… FALSE
#> 7 R_0001 1 3 1 Criminalizing not working End ov… Oppo … FALSE
#> 8 R_0001 1 3 2 Incarceration Elimin… Finan… TRUE
#> 9 R_0001 1 3 3 Oppo - Violent crime wave Oppo -… Oppo … FALSE
#> 10 R_0001 1 4 1 Incarceration Reduce… US st… FALSE
#> # ℹ 20,042 more rows
#> # ℹ 3 more variables: attributes$messenger <fct>, $villain <fct>, $value <fct>
#>
#> $weights
#> # A tibble: 557 × 2
#> id weight
#> <chr> <dbl>
#> 1 R_0001 1.06
#> 2 R_0002 0.984
#> 3 R_0003 1.09
#> 4 R_0004 1.00
#> 5 R_0005 0.939
#> 6 R_0006 1.07
#> 7 R_0007 0.960
#> 8 R_0008 1.18
#> 9 R_0009 1.00
#> 10 R_0010 1.09
#> # ℹ 547 more rows
#>