Access results from randomized surveys #579
-
Dear formr community, I am using formr for an experimental setup: I use the shuffle function in a run to assign participants randomly to survey A1 or A2. After this, I have another survey B for everyone, in which I want to display some (own) answers participants gave in the previous survey. However, given the randomization, I do not know if the answers are stored in survey A1 or A2, so I cannot use survey$variable. I tried ifelse(!is.na(A1$variable), A1$variable, A2$variable), but that didn't work. I am guessing this is nothing unusual, so there must be an implemented way to do it, so maybe someone can give me a hint where to look or how to approach this? This would be much appreciated. I didn't see a similar problem discussed before, so please excuse if I missed it. Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Hi Caro, that should work — that's how I would go about it at least. Can you say more about what doesn't work, perhaps provide a reproducible example? |
Beta Was this translation helpful? Give feedback.
-
Hi Ruben, thanks for the swift reply. The survey just doesn't show anything if the randomization didn't shuffle the person in the first group of the ifelse statement, i.e. A1 in my example above, see this screenshot: If the person was shuffled in the first group, then it shows the result as expected (and if nothing is entered in the target variable, it shows NA, so it's not about the target variable being an empty string), see this screenshot: To be precise, my ifelse()-statement is a nested one, as I have three groups, so it really looks like this, but the logic is the same as in my intitial example:
I tried to make a reproducible example, and attached it: Maybe a workaround could be to access the shuffle$group codings in the survey following the shuffle? Would that work? Best, |
Beta Was this translation helpful? Give feedback.
-
So, if you use debug mode, you can download the attached Rmd file in the last step, where the error occurs. But yes, you could also refer to the shuffle$group variable in the ifelse condition, that's yet another way. |
Beta Was this translation helpful? Give feedback.
-
Wow, thanks a lot Ruben! Not only for identifying the problem, but also for showing me how I could debug similar problems myself in the future. And for showcasing coalesce, I didn't know that function - so many learnings, it's much appreciated! |
Beta Was this translation helpful? Give feedback.
So, if you use debug mode, you can download the attached Rmd file in the last step, where the error occurs.
Then, you can open the code on your local computer and go through it line-by-line.
If you do that, you see that the problem is that surveyA1$reflection1 isn't NA — it's NULL/it doesn't exist.
So,
heading1 <- ifelse(!is.null(survey_A1$reflection1), "Gemeinsamkeiten", ifelse(!is.null(survey_A2$reflection1), "Unterschieden", "Eigenschaften"))
works.If you don't want to write that much (quickly becomes confusing), how about
dplyr::coalesce(survey_A1$reflection1, survey_A2$reflection1, survey_A3$reflection1)
.But yes, you could also refer to the shuffle$group variable in the ifelse cond…