layout: true --- class: middle, inverse ## .center[Fielding Surveys with formr] .leftcol40[ <center> <img src="https://jhelvy.github.io/2023-qux-conf-conjoint/images/logo.png" width=300> </center> ] .rightcol60[ ###
John Paul Helveston, Ph.D. ###
The George Washington University | Dept. of Engineering Management and Systems Engineering ###
June 15, 2023 ] --- class: center, middle, inverse # Making a survey in formr --- # Building a survey in [formr](https://formr.org/) <br> ## - Use _RMarkdown / html_ to create survey elements ## - Copy elements to a _Google Sheet_ ## - Import Google Sheets into formr _surveys_ ## - Link surveys together in formr _runs_ --- class: center, middle # My Recommentation:<br>Draft your survey in RMarkdown .cols3[ ### .center[Survey content in `demoSurvey.Rmd`] ] .cols3[ ### .center[[Google sheet](https://docs.google.com/spreadsheets/d/13jSdlIDFRVsIHbiObgyZlPTGovIcB-xDQ0dkhL75fZQ/edit?usp=sharing)] ] .cols3[ ### .center[[Live survey](https://demosurvey.formr.org/)] ] --- # .center[formr row types [(more here)](https://formr.org/documentation#available_items)] Type | Description -----|--------------------- `note` | Display content in `label` column `submit` | Next page button `mc` | Multiple choice question (single choice) `mc_multiple` | Multiple choice question (multiple choices) `mc_button` | Multiple choice question (large buttons) `select_one` | Drop down menu (choose one) `text` | Open text, single row `textarea` | Open text, block --- # Some Guidelines - Be sure that any data / images are hosted somewhere on the web - Consider each new page a **New R Session** (reload libraries, etc.) --- # Embedding images I recommend just writing html code, like this ```html <img src="https://github.com/jhelvy/2023-qux-conf-conjoint/blob/main/images/logo.png?raw=true" width=250> ``` <img src="https://github.com/jhelvy/2023-qux-conf-conjoint/blob/main/images/logo.png?raw=true" width=250> --- # Centered image I recommend just writing html code, like this ```html <center> <img src="https://github.com/jhelvy/2023-qux-conf-conjoint/blob/main/images/logo.png?raw=true" width=250> </center> ``` <center> <img src="https://github.com/jhelvy/2023-qux-conf-conjoint/blob/main/images/logo.png?raw=true" width=250> </center> --- # Check your urls carefully! <br> This is the link to the **Github page** with the image: https://github.com/jhelvy/2023-qux-conf-conjoint/blob/main/images/logo.png This is the link to the **actual image**: https://github.com/jhelvy/2023-qux-conf-conjoint/blob/main/images/logo.png?raw=true --- # Two ways to define choice options .leftcol[ Add "choice" columns <center> <img src="images/choices.png" width=100%> </center> ] -- .rightcol[ Use `choices` tab<br>(when you have a lot of choices) Example: "Year of birth" in [this demo](https://docs.google.com/spreadsheets/d/13jSdlIDFRVsIHbiObgyZlPTGovIcB-xDQ0dkhL75fZQ/edit?usp=sharing)] ] --- class: center, middle # Control the way things look in `class` column # ([options here](https://formr.org/documentation#sample_survey_sheet)) --- class: center # Importing survey into formr ### formr.org --> Admin --> Surveys --> Create new survey ### (Make sure your Google Sheet is visible!) <center> <img src="images/gsheetlink.png" width=600> </center> --- class: center # Make a run ## formr.org --> Admin --> Runs --> Create new run -- <br> # Insert survey with
-- <br> # Insert stop with
--- class: center ## Change order by adjusting numbers & clicking "Reorder" <center> <img src="images/order.png" width=500> </center> --- class: center, middle # Make it "live" with the volume buttons <center> <img src="images/publicness.png" width=1000> </center> --- class: center # Fine tune look & feel in "Settings" --- class: center, middle, inverse # Making a _conjoint_ survey in formr -- # (Detailed demo in [this blog post](https://www.jhelvy.com/posts/2021-09-18-choice-based-conjoint-surveys-in-r-with-formr/)) --- class: center ## Full demo in the [formr4conjoint](https://github.com/jhelvy/formr4conjoint) repo from GitHub (code used in the related [blog post](https://www.jhelvy.com/posts/2021-09-18-choice-based-conjoint-surveys-in-r-with-formr/)) <center> <img src="images/formr4conjoint.png" width=870> </center> --- # 3 Parts <br> - ### **Part 1**: Intro - ### **Part 2**: Conjoint questions - ### **Part 3**: Other / demographic questions --- # 3 Parts <br> - ### **Part 1**: Intro --> .red[screen for target population] - ### **Part 2**: Conjoint questions --> .red[screen for random answers] - ### **Part 3**: Other / demographic questions --- # .center[Displaying your choice questions online] .center[(See example in [part two](https://docs.google.com/spreadsheets/d/1Ih3Pt6uz-gp5vc0SBxBzl4K0aZoRLwI6dtdtZiXSLz0/edit#gid=1611481919) demo google sheet)] <br> ### 1. Export your choice questions as a .csv file ### 2. Upload your .csv file somewhere (e.g. GitHub) ### 3. Use R code to extract the values to display ### 4. Use RMarkdown to display the values --- ### 1. Export your experiment design (from [{cbcTools}](https://github.com/jhelvy/cbcTools)) as a .csv file ```r write_csv(design, here('choice_questions.csv')) ``` -- ### 2. Upload your .csv file somewhere .leftcol[.center[ ### Inside a formr run (private) <center> <img src="images/upload.png" width=500> </center> ]] .rightcol[.center[ ### github.com (public) .font200[[
](https://github.com/)] [apples example](https://github.com/jhelvy/formr4conjoint) ]] --- # .center[Serialize the experiment design] .center[Converts a data frame to one long string] ```r df ``` ``` #> profileID altID price fuelEconomy accelTime powertrain #> 1 9 1 25 30 6 Gasoline #> 2 11 2 20 20 7 Gasoline #> 3 23 3 20 25 8 Gasoline ``` ```r df_json <- jsonlite::serializeJSON(df) df_json ``` ``` #> {"type":"list","attributes":{"names":{"type":"character","attributes":{},"value":["profileID","altID","price","fuelEconomy","accelTime","powertrain"]},"class":{"type":"character","attributes":{},"value":["data.frame"]},"row.names":{"type":"integer","attributes":{},"value":[1,2,3]}},"value":[{"type":"integer","attributes":{},"value":[9,11,23]},{"type":"integer","attributes":{},"value":[1,2,3]},{"type":"double","attributes":{},"value":[25,20,20]},{"type":"double","attributes":{},"value":[30,20,25]},{"type":"double","attributes":{},"value":[6,7,8]},{"type":"integer","attributes":{"levels":{"type":"character","attributes":{},"value":["Gasoline","Electric"]},"class":{"type":"character","attributes":{},"value":["factor"]}},"value":[1,1,1]}]} ``` --- ### Using the `calculate` type ([example sheet](https://docs.google.com/spreadsheets/d/1Ih3Pt6uz-gp5vc0SBxBzl4K0aZoRLwI6dtdtZiXSLz0/edit#gid=1611481919)) .leftcol[ RMarkdown ```r # Read in the choice questions library(tidyverse) design <- read_csv("https://raw.githubusercontent.com/jhelvy/formr4conjoint/master/survey/choice_questions.csv") # Define the respondent ID respondentID <- sample(design$respID, 1) # Create the subset of rows for that respondent ID df <- design %>% filter(respID == respondentID) %>% mutate(image = paste0("https://raw.githubusercontent.com/jhelvy/formr4conjoint/master/survey/images/", image)) # Convert df to json df_json <- jsonlite::serializeJSON(df) ``` ] .rightcol[ Google sheet <center> <img src="images/calculate.png" width=100%> </center> ] --- ## Random choice questions as **buttons** Use the `mc_button` question type .leftcol[ ### `label` - Show your question text - Insert a code chunk to create one-row data frame for each alternative ### `choice` columns - Insert RMarkdown code to display each alternative ] .rightcol[ <center> <img src="images/cbc_buttons.png" width=100%> </center> ] --- ## Random choice questions as **buttons** .leftcol[ Create separate data frames for each alternative ```r library(dplyr) alts <- jsonlite::unserializeJSON(df_json) alt1 <- alts %>% filter(altID == 1) alt2 <- alts %>% filter(altID == 2) alt3 <- alts %>% filter(altID == 3) ``` ] -- .rightcol[ Use RMarkdown formatting to display content in each alternative ```r ***Option 1** ***Price**: $ `r alt1$price` ***Powertrain**: $ `r alt1$powertrain` ***Fuel Economy**: `r alt1$fuelEconomy` mpg ***0-60 Accel. Time**: `r alt1$accelTime` s ``` **Option 1** **Price**: $ 25<br> **Powertrain**: $ Gasoline<br> **Fuel Economy**: 30 mpg<br> **0-60 Accel. Time**: 6 s ] --- ## Random choice questions as **table** - Use the `mc_button` question type .leftcol[ ### `label` - Show your question text - Insert a code chunk to modify `alts` data frame & display it using `kable()` - Use [kableExtra](https://haozhu233.github.io/kableExtra/awesome_table_in_html.html#Basic_HTML_table) to control table styling ### `choice` columns - Simple text / number for each option ] .rightcol[ <center> <img src="images/cbc_table.png" width=100%> </center> ] --- ## Random choice questions as **table** .leftcol[ ```r library(dplyr) alts <- jsonlite::unserializeJSON(df_json) %>% # Add $ sign to price mutate(price = scales::dollar(price)) %>% # Make nicer attribute labels select( `Option:` = altID, `Powertrain:` = powertrain, `Price:` = price, `Fuel Economy (mpg):` = fuelEconomy, `Accel. Time (s):` = accelTime) # Drop row names row.names(alts) <- NULL ``` ] .rightcol[ Display the _transpose_, `t(alts)` ```r kable(t(alts)) ``` <table> <tbody> <tr> <td style="text-align:left;"> Option: </td> <td style="text-align:left;"> 1 </td> <td style="text-align:left;"> 2 </td> <td style="text-align:left;"> 3 </td> </tr> <tr> <td style="text-align:left;"> Powertrain: </td> <td style="text-align:left;"> Gasoline </td> <td style="text-align:left;"> Gasoline </td> <td style="text-align:left;"> Gasoline </td> </tr> <tr> <td style="text-align:left;"> Price: </td> <td style="text-align:left;"> $25 </td> <td style="text-align:left;"> $20 </td> <td style="text-align:left;"> $20 </td> </tr> <tr> <td style="text-align:left;"> Fuel Economy (mpg): </td> <td style="text-align:left;"> 30 </td> <td style="text-align:left;"> 20 </td> <td style="text-align:left;"> 25 </td> </tr> <tr> <td style="text-align:left;"> Accel. Time (s): </td> <td style="text-align:left;"> 6 </td> <td style="text-align:left;"> 7 </td> <td style="text-align:left;"> 8 </td> </tr> </tbody> </table> ] --- class: inverse <br> ## .center[Back to workshop website:<br><br> https://jhelvy.github.io/2023-qux-conf-conjoint/] .footer-large[ .right[ @JohnHelveston
<br> @jhelvy
<br> @jhelvy
<br> jhelvy.com
<br> jph@gwu.edu
]]