With the release of JASP 0.17, a new button has been added to the menus for the core analyses. In addition to renaming, duplicating, deleting an analysis and viewing the help file, JASP users now have access to the underlying function call in R that is used to compute the results. This addition is an important first step towards a more complete integration between JASP and R. This exciting new feature has been previously mentioned, but this post gives more details and illustrates how R syntax can be used in practice. A more comprehensive R syntax integration is also in the works for the near future, as discussed towards the end of this post.
One of JASP’s main goals is to make statistical analyses more accessible by removing the requirement for computer programming, so that students can focus on interpretation rather than implementation. Nevertheless, we also recognize that the option to generate the analysis R code facilitates both open science and teaching. As of JASP 0.17, users can simply copy the R code generated by JASP and share it with their peers, who can then immediately see which options were used in the analysis. Additionally, users can paste the R code into their own JASP instance and reproduce the analysis. Moreover, the R code can be changed to control the GUI (how cool is that!), and vice versa. Finally, the new functionality benefits teaching, as it allows instructors to easily share analysis settings with students and demonstrate R programming concepts in a user-friendly environment.
Example 1: Exploring Descriptives
A gif to illustrate the current syntax mode functionality can be found here.
As a first example, we consider the “Moon & Aggression” dataset from the JASP data library (Moore et al., 2012; data collected by Nancy Edwards and Alan Beck). This data set features the counts of disruptive behaviours for full moon days, and for other days. The paired t-test analysis has several options available for exploring the data, such as a descriptives table and raincloud plots. When the options have been specified, and the new “R” button is clicked, the underlying R function call is shown, including its settings:
The correspondence between the settings shown in the R-code and the settings in the JASP GUI is a two-way street:
- Changing an option in the JASP GUI will automatically update the R code;
- Changing an option in the R code and pressing Ctrl (Cmd on Macs) + Enter will update the JASP GUI!
Example 2: Three-way Mixed ANOVA
The second example features a three-way mixed ANOVA; this shows how the syntax mode holds up for more complex analyses. As a teacher myself, I find this is where the current functionality truly shines, because it simplifies how I share certain analyses with students (although sharing a .jasp file is also relatively straightforward). Instead of needing to introduce the various submenus and the repeated measures cells interface, it is now possible to simply tell students to open a specific data set (in this case, the “Bugs” data set from the JASP data library, by Ryan et al., 2013), open the R console module, and paste the following syntax:
version = "0.17.1",
betweenModelTerms = ~ Gender,
betweenSubjectFactors = "Gender",
contrasts = list(
list(contrast = "none", variable = "Disgustingness"),
list(contrast = "none", variable = "Frighteningness"),
list(contrast = "none", variable = "Gender")
descriptivePlotErrorBar = TRUE,
descriptivePlotHorizontalAxis = "Disgustingness",
descriptivePlotSeparateLines = "Frighteningness",
descriptivePlotSeparatePlot = "Gender",
descriptivePlotYAxisLabel = "Hostility",
effectSizeEstimates = TRUE,
plotWidthDescriptivesPlotLegend = 450,
postHocCorrectionHolm = FALSE,
postHocCorrectionTukey = TRUE,
postHocPooledError = FALSE,
repeatedMeasuresCells = list("Lo D, Lo F", "Lo D, Hi F", "Hi D, Lo F", "Hi D, Hi F"),
repeatedMeasuresFactors = list(
list(levels = list("Low", "High"), name = "Disgustingness"),
list(levels = list("Low", "High"), name = "Frighteningness")
withinModelTerms = list("Disgustingness", "Frighteningness", list("Disgustingness", "Frighteningness"))
Clicking “Add analysis” automatically opens the Repeated Measures ANOVA, with all of the relevant options specified. Sharing an analysis this way creates a top-down workflow, where the main features of the analysis are specified (e.g., the repeated measures cells and model terms). The main analysis can now be adjusted to highlight certain analysis features, such as a contrast analysis.
The next two steps are needed to achieve full JASP syntax mode: First, the current functionality needs to be expanded to cover all of the modules within JASP. Second, a JASP R package needs to be made available on CRAN. This will be a milestone for the JASP team, as it will enable a wider range of users to seamlessly incorporate JASP functionality into their R-based analysis workflows. For now, we hope that many users can already benefit from the current functionality, and experience the increased ease of sharing JASP results.
The R syntax options available in JASP 0.17 provide users with the following functionality:
- Users can copy the R code generated by JASP and share it with their peers, who can then immediately see which options were used in the analysis.
- Users can paste the R code into their own JASP instance and reproduce the analysis.
- Users can edit the R code to control the GUI, or change it to generate different R code. The R code is always yoked to the GUI, so that changes in one immediately affect the other.
- Instructors can easily share analysis settings with students and demonstrate R programming concepts in a user-friendly environment.
In the upcoming versions, we will add R syntax options for the modules and create an R package for CRAN, such that the JASP-generated R syntax can also be executed in R Studio. We believe that the R syntax mode makes JASP more versatile and user-friendly, and aligns with JASP’s mission to promote transparency, reproducibility, and collaboration in scientific research.
Moore, D. S., McCabe, G. P., and Craig. B. A. (2012) Introduction to the Practice of Statistics (7th ed). New York: Freeman.
Ryan, R. S., Wilde, M., & Crist, S. (2013). Compared to a small, supervised lab experiment, a large, unsupervised web-based experiment on a previously unknown effect has benefits that outweigh its potential costs. Computers in Human Behavior, 29, 1295-1301.