Reshapes survey response data for conjoint analysis
reshape_projoint.Rd
This function takes a data frame, preferably from read_Qualtrics
, and reshapes it from wide to long such that each row is a distinct conjoint task rather than a respondent.
Usage
reshape_projoint(
.dataframe,
.outcomes,
.outcomes_ids = c("A", "B"),
.alphabet = "K",
.idvar = "ResponseId",
.repeated = TRUE,
.flipped = TRUE,
.covariates = NULL,
.fill = FALSE
)
Arguments
- .dataframe
A data frame, preferably from
read_Qualtrics
- .outcomes
A character vector identifying the column names that contain outcomes. If there is a repeated task, it should be the LAST element in this vector.
- .outcomes_ids
c("A", "B") (default): a vector identifying the possibilities for the outcome variables -- e.g., c("Candidate A", "Candidate B")
- .alphabet
"K" (default): a letter indicating conjoint attributes. If using Strezhnev's package (https://github.com/astrezhnev/conjointsdt) in Qualtrics.
- .idvar
"ResponseId" (default): a character identifying the column name containing respondent
- .repeated
TRUE (default) if there is a repeated task (recommended). The repeated task should be the same as the first task.
- .flipped
TRUE (default) if the profiles of the repeated task are flipped (recommended)
- .covariates
NULL (default): a character vector identifying respondents' covariates used for subgroup analysis
- .fill
FALSE (default): A logical vector: TRUE if you want to use information about whether a respondent chose the same profile for the repeated task and "fill" (using the `tidyr` package) missing values for the non-repeated tasks, FALSE (otherwise). If the number of respondents is small, if the number of specific profile pairs of your interest is small, and/or if the number of specific respondent subgroups you want to study is small, it is worth changing this option to TRUE. But please note that `.fill = TRUE` is based on an assumption that IRR is independent of information contained in conjoint tables. Although our empirical tests suggest the validity of this assumption, if you are unsure about it, it is better to use the default value (FALSE).
Value
A projoint object of class `projoint_data` ready to pass to `projoint()`.
A projoint object of class projoint_data
ready to pass to projoint
.
Examples
library(projoint)
data("exampleData1")
head(exampleData1)
#> # A tibble: 6 × 185
#> ResponseId choice1_repeated_fli…¹ choice1 choice2 choice3 choice4 choice5
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 R_1M3TDihZzq9z… Community B Commun… Commun… Commun… Commun… Commun…
#> 2 R_3HtXzkcSSlfi… Community B Commun… Commun… Commun… Commun… Commun…
#> 3 R_yjYj0jtOY98X… Community B Commun… Commun… Commun… Commun… Commun…
#> 4 R_1dKd05O6FTOV… Community B Commun… Commun… Commun… Commun… Commun…
#> 5 R_1otDp642wWYl… Community A Commun… Commun… Commun… Commun… Commun…
#> 6 R_2BnD3fuJMRKZ… Community A Commun… Commun… Commun… Commun… Commun…
#> # ℹ abbreviated name: ¹choice1_repeated_flipped
#> # ℹ 178 more variables: choice6 <chr>, choice7 <chr>, choice8 <chr>,
#> # race <chr>, party_1 <chr>, party_2 <chr>, party_3 <chr>, party_4 <chr>,
#> # ideology <chr>, honesty <chr>, `K-1-1` <chr>, `K-1-1-1` <chr>,
#> # `K-1-2` <chr>, `K-1-1-2` <chr>, `K-1-3` <chr>, `K-1-1-3` <chr>,
#> # `K-1-4` <chr>, `K-1-1-4` <chr>, `K-1-5` <chr>, `K-1-1-5` <chr>,
#> # `K-1-6` <chr>, `K-1-1-6` <chr>, `K-1-7` <chr>, `K-1-1-7` <chr>, …
# Write outcome column names
outcomes <- paste0("choice", seq(from = 1, to = 8, by = 1))
outcomes <- c(outcomes, "choice1_repeated_flipped")
# Reshape the data
reshaped_data <- reshape_projoint(
.dataframe = exampleData1,
.outcomes = outcomes)