Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/yhoriuchi/projoint
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrkaufman committed Aug 15, 2023
2 parents c7e11f8 + a26159c commit ab9179e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 13 deletions.
3 changes: 2 additions & 1 deletion R/reshape_projoint.R
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ reshape_projoint <- function(

} else{

out_final <- out_final_before_fill
out_final <- out_final_before_fill %>%
dplyr::arrange(id, task, agree)
}


Expand Down
60 changes: 48 additions & 12 deletions vignettes/02-wrangle.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ library(projoint)
Let's look at a simple example. We expand all those arguments below for clarity:

```{r}
outcomes <- paste0("choice", seq(from = 1, to = 8, by = 1))
outcomes <- c(outcomes, "choice1_repeated_flipped")
outcomes1 <- paste0("choice", seq(from = 1, to = 8, by = 1))
outcomes1 <- c(outcomes1, "choice1_repeated_flipped")
out1 <- reshape_projoint(.dataframe = exampleData1,
.idvar = "ResponseId",
.outcomes = outcomes,
.outcomes = outcomes1,
.outcomes_ids = c("A", "B"),
.alphabet = "K",
.repeated = TRUE,
.flipped = TRUE)
.flipped = TRUE,
.fill = FALSE)
```

Let's walk through the arguments we have specified. `.dataframe` is a data frame, ideally read in from Qualtrics using `read_Qualtrics()` but not necessarily. The `.idvar` argument, a character, indicates that in `exampleData1`, the column `ResponseId` indicates unique survey respondents. The `.outcomes` variable lists all the columns that are outcomes; the last element in this vector is the repeated task (if it was conducted). `.outcomes_ids` indicates the possible options for an outcome; specifically, it is a vector of characters with two elements, which are the last characters of the names of the first and second profiles. For example, it should be c("A", "B") if the profile names are "Candidate A" and "Candidate B". This character vector can be anything, such as c("1", "2"), c("a", "b"), etc. *If you have multiple tasks in your design, you should use the same profile names across all these tasks*. `.alphabet` defaults to "K" if the conjoint survey was conducted using either our tool or Strezhnev's [Conjoint Survey Design Tool](https://github.com/astrezhnev/conjointsdt). The final two arguments, `.repeated` and `.flipped`, again relate to the repeated task. If the `.repeated` is set to `TRUE`, then the last element of the `.outcomes` vector is taken to be a repetition of the first task; `.flipped` indicates whether the profiles are in the reversed order.
Expand All @@ -43,33 +44,68 @@ Let's walk through the arguments we have specified. `.dataframe` is a data frame
As a slight variation, in some cases the repeated task is *not* flipped -- that is, in the repeated task, the original Profile 1 is still Profile 1, rather than flipping positions to Profile 2. Here we specify that by changing `.flipped` to `FALSE`.

```{r}
outcomes <- paste0("choice", seq(from = 1, to = 8, by = 1))
outcomes <- c(outcomes, "choice1_repeated_notflipped")
outcomes2 <- paste0("choice", seq(from = 1, to = 8, by = 1))
outcomes2 <- c(outcomes2, "choice1_repeated_notflipped")
out2 <- reshape_projoint(.dataframe = exampleData2,
.idvar = "ResponseId",
.outcomes = outcomes,
.outcomes = outcomes2,
.outcomes_ids = c("A", "B"),
.alphabet = "K",
.repeated = TRUE,
.flipped = FALSE)
.flipped = FALSE,
.fill = FALSE)
```

#### Without the repeated tasks

Or in cases with no repeated task at all, we set `.repeated` to `FALSE` and `.flipped` to `NULL`:

```{r}
outcomes <- paste0("choice", seq(from = 1, to = 8, by = 1))
outcomes3 <- paste0("choice", seq(from = 1, to = 8, by = 1))
out3 <- reshape_projoint(.dataframe = exampleData3,
.idvar = "ResponseId",
.outcomes = outcomes,
.outcomes = outcomes3,
.outcomes_ids = c("A", "B"),
.alphabet = "K",
.repeated = FALSE,
.flipped = NULL)
.flipped = NULL,
.fill = FALSE)
```

### 2.3 Arrange the order and labels of attributes and levels

### 2.3 The `.fill` argument

The `.fill` argument is logical: 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).

You can see the difference by comparing the following two:
```{r}
fill_FALSE <- reshape_projoint(.dataframe = exampleData1,
.idvar = "ResponseId",
.outcomes = outcomes1,
.outcomes_ids = c("A", "B"),
.alphabet = "K",
.repeated = TRUE,
.flipped = TRUE,
.fill = FALSE)
fill_TRUE <- reshape_projoint(.dataframe = exampleData1,
.idvar = "ResponseId",
.outcomes = outcomes1,
.outcomes_ids = c("A", "B"),
.alphabet = "K",
.repeated = TRUE,
.flipped = TRUE,
.fill = TRUE)
```
We just select the essential variables only. The first data frame includes the values for the `agree` variable (whether the same profile was chosen or not) only for the repeated task. The second data frame fills the missing values for the other non-repeated tasks.
```{r}
selected_vars <- c("id", "task", "profile", "selected", "selected_repeated", "agree")
fill_FALSE@data[selected_vars]
fill_TRUE@data[selected_vars]
```
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).

### 2.4 Arrange the order and labels of attributes and levels

The reshaped data have attributes and levels that are sorted alphabetically. Often, however, you want to reorder the attributes and/or order the levels of a particular attribute. You may also prefer not to use the actual labels for attributes and levels used in your conjoint experiments; for example, for the purpose of presentation, you may want to make them shorter. This process has been challenging for applied scholars using other packages. We make this process easy. You first save the labels using `save_labels()`. In the CSV file you save in your local computer, you should revise the column named `order` to specify the order of attributes and levels you want to display in your figure. You can also revise the labels for attributes and levels in any way you like. But *you should not make any change to the first column named `level_id`*. After saving the updated CSV file, you should use `read_labels()` to read it and save the object suitable for the next step (i.e., use `projoint()`).

Expand Down

0 comments on commit ab9179e

Please sign in to comment.