Date: March 2024
Authors: Andre Beinrucker <andre.beinrucker@htw-berlin.de>, Markus Konrad <markus.konrad@htw-berlin.de>
This repository contains code for two R Shiny apps to conduct an in-class experiment suggested as pen and paper version by Adam Shrager in 2009.
The experiment has the aim to show how to perform hypothesis testing and lets the students generate their own data for that. The data is generated within a ranomized study, more precisely an A/B test. Both groups are shown the same quiz, but students in the test group get the hint that visualizing the sentences helps to memorize them.
There are two RStudio projects with the Shiny apps: MGParticipant
contains the code for the memory game (the participants' app) and MGTeacher
contains the code for the experiment management interface (the teachers' app). Both projects employ renv for dependency management. To install all required packages, open the respective RStudio projects, install the renv
package (if not already installed) and then run renv::restore()
.
- Create the file
MGTeacher/.Renviron
with the only contentPARTICIPANT_APP_BASEURL=http://127.0.0.1:8888/
. - Open the
MGParticipant
app and run it on a fixed port 8888 viashiny::runApp(port = 8888, launch.browser = FALSE)
. - Open the
MGTeacher
app and run it on any other port using the "Run app" button or viashiny::runApp()
. - Create a new experiment by clicking on the green "+" button in the MGTeacher app. An URL with an unique experiment session ID like
http://127.0.0.1:8888/?sess_id=XYZ
will be created which can be shared among participants. Open the link with a browser on the same machine (as the apps only run locally on your machine, the URL will not work in your smartphone or any other machine – you will need to deploy the apps on a server as described below). - A message like "Please wait. The game hasn't started yet." should appear in the browser window that shows the participant's view. Using the MGTeacher app, you can advance to the next stages of the game ("Show directions", etc.) and the participant's view will be updated accordingly.
To run this app on a server, the server needs to have a Shiny server (open-source or professionall variant) installed and configured. Then, do the following:
- Create the base folder that will contain the shiny apps. We will call this folder
MemoryGame
. This folder must be a sub-folder of the folder that is configured to serve Shiny apps (e.g.~/ShinyApps/MemoryGame
). - Copy the folders
MGParticipant
,MGTeacher
as well as the filecommon.R
to theMemoryGame
folder on the server. Make sure to exclude therenv
subfolder from copying but do include therenv.lock
file! - Install all necessary dependencies for the MGParticipant and the MGTeacher app by installing the
renv
package and then runningrenv::activate()
andrenv::restore()
. - Create an empty folder
MemoryGame/sessions
. This folder must be writable by the Shiny server instance. - Create the file
MemoryGame/MGTeacher/.Renviron
with the only contentPARTICIPANT_APP_BASEURL=<URL_TO_PARTICIPANT_APP>
; replace<URL_TO_PARTICIPANT_APP>
by the actual URL that will point to the MGParticipant app on the server, e.g.https://example-shiny-server.com/MemoryGame/MGParticipant/
. - Protect access to the MGTeacher app, e.g. by password protection (that can be employed by a HTTP proxy server that routes all requests to the Shiny apps or by using the professional variant of the Shiny server).
- Navigate to the MGTeacher app in your browser (e.g.
https://example-shiny-server.com/MemoryGame/MGTeacher/
) and create a new experiment; open the URL that was created for the experiment and check if everything works.
-
Before the lecture starts, open the teacher app: https://example-shiny-server.com/MemoryGame/MGTeacher/ . Log in with the user name and password specified before.
-
On the top left, below "Create a new ession from template:"
select "default_session_en.yaml" (or default_session_de.yaml for a German version). Then click on "+" to initialise a new game. -
You should now see "Current stage: start" at the top right.
-
Scroll down a little to the QR code, zoom in if necessary. The students will enter the game via this QR code, or alternatively via the link above it
-
We recommend to leave the browser window with the QR code open while starting the lecture and introducing the experiment (If anything goes wrong, initialize a new session before as described above)
- Say a few introductory words, like "We are going to generate data together that we will analyze afterwards... This is a memory game... It is completely anonymous, only you can see how many points you have scored."(Do not mention the intervention here, as it would spoil the effect)
- Now show the QR code on the website above, ask students to join with their smartphone. (Some may have to come to the front with their smartphone and take a photo of the QR code up close.)
- The students can now see "Please wait, the game has not started yet"
- When the students have joined, click on on the website to display the instructions on the smartphones.
- Say something like "Please read the instructions on your phone now". Important: Do not explain anything else here so that the intervention can "take effect". The intervention is that students in the test group get the hint that visualization helps to memorize the sentences. Wait 1-2 minutes until everyone has read.
- Make sure that the teacher app is not visible for students and click on . Read out the sentences one by one. Take a short break after each sentence and visualize what has been said so that the visualization group also has enough time to visualize. Ask students who are taking notes not to do so.
- Click on to display the questions.
- Make sure that everyone answers the questions individually and quietly
- After a fixed time of 3 minutes or when most people have finished, click on to end the quiz for the students.
- Click on on the top right of the website
- You can now reveal the treatment, have the students analyse the data, discuss the importance of randomization, discuss why the effect might not be significant, explain that this was essentially an A/B test and that anybody using apps on a smartphone or surfing webpages takes part in many such A/B tests every day... and much more!
The main code is divided into two Shiny apps, each an RStudio project: MGTeacher is the administration interface that allows to create new experiments as can be seen in this screenshot:
Once an experiment is created, it can be shared with students via a QR-code which leads to an URL that opens the MGParticipant app, which contains all code for the memory game.
The file common.R
contains R code used in both apps. The sessions
folder contains data for all experiments that were created. Each experiment gets an unique session ID and when creating an experiment, a folder with that session ID will be created inside the sessions
folder.
Finally, there's the UserDataAnalysis
folder which contains an RStudio project with scripts to prepare and analyse the data from the experiments.