Joachim Gassen

Curious researcher, passionate teacher and coding nerd.

A Shiny Classroom Experiment with Real-Time Results Presentation

Overview

Today, I used a shiny app to run a classroom experiment in the first class of my introductory cost accounting course. I uploaded code, data and materials to github so that everybody can reuse it to construct similar experiments and, of course, to replicate the results from our experiment.

In principle, both formats provide the same underlying information and thus, pricing should not differ across the two treatments if subjects rationally extract all available information.

Under the full cost treatment, however, fix costs are being allocated to units based on expected unit sales. Assuming that subjects use simple “cost plus” heuristics when setting their prices, this could imply that they are less likely to set prices below $12 when receiving the full cost treatment. Note that setting prices below $12 might very well be rational when demand reacts strongly to price as the increased unit sales can compensate for the loss in margin.

These are the results from our experimental run as presented by the real-time shiny result app:

Results App

You can assess the online version of our results here. At least for our students, it seems as if, in line with some prior literature, full cost accounting causes them to set higher prices. In real life, this might imply the risk of losing market share, eventually pricing oneself out of the market.

Replicating the analysis and reusing the code

The repository contains the data from our analysis as well as all the code that you need to set up the experiment on your own shiny server. I have included the English language version along with the original German language version that I ran in class.

If you want to re-run the exact same experiment in your class for didactical purposes and/or to replicate our findings, you can also simply reach out and I can provide you access to our shiny server so that you can run the experiment with your students.

If you want to use the code as a starting point for your own classroom experiments, here are some remarks about the code.

The repository contains both shiny apps (app_experiment_en.R and app_restults_en.R) in one directory. Make sure to export them as two separate shiny apps in separate folders.

The file croom_exp.sqlite3 contains an empty SQLite database to store the response data. The file ìnit_sqlite_db.R contains some code snippets that might be useful when working with the database.

When you want to use the real-time results feature, your result app needs to have access to the database file that the experiment app is writing to. When you are hosting this on your own shiny server this can be realized by the results app linking to the database file in the folder of the experiment app. If you plan to host your apps on a service like ‘shinyapps.io’ then this will most likely not be feasible. In this case, you might consider switching to an external database.

When running this in a large class, your students might experience “Too many users” errors from shiny as shiny has a limit of 100 concurrent users for a given app. When running your own shiny server you can configure shiny to allow more users but my guess is that you will run into performance issues at some point. Another option (the one that I went with) is to ask students to be patient and hit ‘reload’.

Finally, I whipped all this up relatively quickly, so I cannot guarantee that the code is error free and runs exactly as advertised. Please get in touch when you encounter something odd.

This is it. Let me know your thoughts and I would be very happy to get in touch if you are reusing the code for your own projects. In particular, I would be interested in hearing about people that replicate our experimental classroom result. Feel free to comment below. Alternatively, you can reach me via email or twitter.

Joachim Gassen

The ‘ExPanDaR’ package offers a toolbox for interactive exploratory data analysis (EDA). You can read more about it here. The ‘ExPanD’ shiny app allows you to customize your analysis to some extent but often you might want to continue and extend your analysis with additional models and visualizations that are not part of the ‘ExPanDaR’ package.
Thus, I am currently developing an option to export the ‘ExPanD’ data and analysis to an R Notebook.

Interactive EDA is nice but customized interactive EDA is even nicer. To celebrate the new CRAN version of my ‘ExPanDaR’ package I prepare a customized variant of ‘ExPanD’ to explore the U.S. EPA data on fuel economy. Our objective is to develop an interactive display that guides the reader on how to explore the fuel economy data in an intuitive way.
First, let’s load the packages and the data from EPA’s web page.

Overview
Today, I used a shiny app to run a classroom experiment in the first class of my introductory cost accounting course. I uploaded code, data and materials to github so that everybody can reuse it to construct similar experiments and, of course, to replicate the results from our experiment.
The experiment tests whether cost allocation (variable cost or full cost) affects pricing decisions in a simple one product pricing setting.

I am an applied economist working in the area of accounting and corporate transparency. I work with observational data a lot, meaning with data that is already available and not under my control. Whenever I set sails to design a test, there are a lot of decisions to take: Which sample should I use? What is the appropriate time frame? How do I define my dependent and independent variables? What is the functional relation that I expect between dependent and independent variables?

Last week, the German NGO Open Knowledge Foundation Deutschland e.V. has made German Trade Resister data available via the project OffeneRegister.de, together with the British NGO opencorporates. In my last blog post I checked the general accessibility of the data. In this quick follow-up post I follow an idea inspired by a tweet by Johannes Filter to map the gender balance of German corporate officers.
Here is the code for generating the necessary data.

Last week, the German NGO Open Knowledge Foundation Deutschland e.V. has made German Trade Resister data available via the project OffeneRegister.de, together with the British NGO opencorporates. While the data from German Trade Resister is publicly available in principle, retrieving the data is a case-by-case activity and is very cumbersome (try for yourself if you like). The data provided by OffeneRegister.de instead comes with an easy to navigate API, and, what is even more convenient, is available for bulk download (alternatively as a JSON or as a SQLite database file).

As the year is closing down, why not spend some of the free time to explore your email data using R and the tidyverse? When I learned that Mac OS Mail stores its internal data in a SQLite database file I was hooked. A quick dive in your email archive might uncover some of your old acquaintances. Let’s take a peak.
Obviously, the below is only applicable when you are a regular user of the Mail app for Mac OS.

Exploratory data analysis is important, everybody knows that. With R, it is also easy. Below you see three lines of code that allow you to interactively explore the Preston Curve, the prominent association of country level real income per capita with life expectancy.
install.packages("ExPanDaR")
library(ExPanDaR)
wb <- read.csv("https://joachim-gassen.github.io/data/wb_condensed.csv")
ExPanD(wb, cs_id = "country", ts_id = "year")
After running these three lines of code (OK, four if you have to install the ExPanDaR package first), a shiny window will open, allowing you to explore a country-year panel of World Bank data and looking something like this.

The awesome blog post by Tyler Morgan-Wall on 3d printing maps with his rayshader package rekindled an old desire of mine: Sometimes I would like to touch data. I am a big fan of data visualization and being able to add a third dimension and this haptic feel to the mix was just too much for me to let this idea pass.
While Tyler is keeping teasing us with references to an upcoming rayshader update that will allow the 3d mapping of ggplot output, I could not wait for this to hit GitHub.

Did you ever want to do a quick exploratory pass on a panel data set? Did you ever wish to give somebody (e.g., a reviewer or a fellow researcher), the opportunity to explore your data and your findings but can’t provide your raw data? Do you get bored from producing the same tables and figures over and over again for your panel data project? If your answer to one of the questions above is yes, then the new ExPanDaR R package might be worth a look.