R package jmvReadWrite

Sebastian Jentschke

2021-09-16

The R-package jmvReadWrite reads and writes the .omv-files that are used by the statistical spreadsheet jamovi (www.jamovi.org). It is supposed to ease using syntax for statistical analyses created using the GUI in jamovi in connection with the R-library jmv.

Installation

You can either install a stable version of jmvReadWrite which is available on CRAN using the following command:

install.packages("jmvReadWrite")

or you can install the development version of the jmvReadWrite package from GitHub:

if(!require(devtools)) install.packages("devtools")
devtools::install_github("sjentsch/jmvReadWrite")

How to use the package?

The following code uses the ToothGrowth-data set that is part of the data sets included in R (the current file contains some modifications though for testing the reading and writing routines: read_omv and write_omv). With this data set, a syntax to conduct an ANOVA is run.

The results should be similar to those obtained when running the same analysis in jamovi (using the GUI). To do so, open the file menu (☰) choose Open, Data Library and ToothGrowth. Afterwards, click on the ANOVA-button in the Analyses-tab and choose ANOVA. There, you assign the variable len to Dependent Variable and supp and dose to Fixed Factors. Afterwards, you choose / tick Overall Model Test and ω². Open the drop-down menu Assumption Checks and tick Homogeneity test and Normality test. The results should be identical apart from that the table output looks nicer in jamovi (not only text, as below), numbers are rounded and maybe one or two other cosmetic differences.

If you want to copy the syntax generated in jamovi, you have to switch on the Syntax Mode. Afterwards, the syntax is shown at the top of the analysis and can be copied from there.

library(jmvReadWrite);
library(jmv);

fleOMV = system.file("extdata", "ToothGrowth.omv", package = "jmvReadWrite");
data = read_omv(fleNme = fleOMV);
jmv::ANOVA(
    formula = len ~ supp + dose + supp:dose,
    data = data,
    effectSize = c("omega"),
    modelTest = TRUE,
    homo = TRUE,
    norm = TRUE);
#> 
#>  ANOVA
#> 
#>  ANOVA - len                                                                                      
#>  ──────────────────────────────────────────────────────────────────────────────────────────────── 
#>                     Sum of Squares    df    Mean Square    F            p             ω²          
#>  ──────────────────────────────────────────────────────────────────────────────────────────────── 
#>    Overall model         2740.1033     5      548.02067    41.557178    < .0000001                
#>    supp                   205.3500     1      205.35000    15.571979     0.0002312    0.0554519   
#>    dose                  2426.4343     2     1213.21717    91.999965    < .0000001    0.6925788   
#>    supp:dose              108.3190     2       54.15950     4.106991     0.0218603    0.0236466   
#>    Residuals              712.1060    54       13.18715                                           
#>  ──────────────────────────────────────────────────────────────────────────────────────────────── 
#> 
#> 
#>  ASSUMPTION CHECKS
#> 
#>  Homogeneity of Variances Test (Levene's) 
#>  ──────────────────────────────────────── 
#>    F           df1    df2    p           
#>  ──────────────────────────────────────── 
#>    1.940130      5     54    0.1027298   
#>  ──────────────────────────────────────── 
#> 
#> 
#>  Normality Test (Shapiro-Wilk) 
#>  ───────────────────────────── 
#>    Statistic    p           
#>  ───────────────────────────── 
#>    0.9849884    0.6694242   
#>  ─────────────────────────────

Since version 0.2.0, read_omv also extracts the syntax from analyses that you may have conducted in the jamovi-GUI and that are stored in the .omv-file. To extract them, you have to set the parameter getSyn = TRUE when calling read_omv (default is FALSE). When the parameter is set, the analyses are stored in the attribute syntax. They can be used as shown in the following examples:

library(jmvReadWrite);
fleOMV = system.file("extdata", "ToothGrowth.omv", package = "jmvReadWrite");
data = read_omv(fleNme = fleOMV, getSyn = TRUE);
# please note that syntax extraction may not work on all systems
# if the syntax couldn't be extracted, an empty list (length = 0) is returned,
# otherwise, the syntax of the analyses from the .omv-file is shown and  
# the commands of the first and the second analysis are run, with the
# output of the second analysis assigned to the variable result2
if (length(attr(data, 'syntax')) >= 2) {
    attr(data, 'syntax')
    eval(parse(text=attr(data, 'syntax')[[1]]))
    eval(parse(text=paste0('result2 = ', attr(data, 'syntax')[[2]])))
    names(result2)
    # → "main"      "assump"    "contrasts" "postHoc"   "emm"
    # (the names of the five output tables)
}
#> [1] "main"      "assump"    "contrasts" "postHoc"   "emm"       "residsOV"

The jmvReadWrite-package also enables you to write .omv-files in order to use them in jamovi. Let’s assume that you have a large collection of log-files (e.g., from an experiment) that you compile and process (summarize, filter, etc.) in R in order to later analyse them in jamovi. You will have those processed log-files stored in a data frame (called, e.g., data) which you then write to a file that you can open in jamovi afterwards. Although jamovi reads R-data files (.RData, .rda, .rds) write_omv permits to store jamovi-specific attributes (such as variable labels) in addition.

library(jmvReadWrite)

# use the data set "ToothGrowth" and, if it exists, write it as jamovi-file using write_omv()
data("ToothGrowth");
wrtDta = write_omv(ToothGrowth, "Trial.omv");
names(wrtDta);
#> [1] "mtaDta" "xtdDta" "dtaFrm"
# → "mtaDta" "xtdDta" "dtaFrm"
# returns a list with the metadata (mtaDta, e.g., column and data type),
# the extended data (xtdDta, e.g., variable lables), and the data frame (dtaFrm)
# the purpose of these variables is merely for checking (understanding the file format)
# and debugging

# check whether the file was written to the disk, get the file information (size, etc.)
# and delete the file afterwards
list.files(".", "Trial.omv");
#> [1] "Trial.omv"
file.info("Trial.omv");
#>           size isdir mode               mtime               ctime
#> Trial.omv 2111 FALSE  644 2021-09-16 08:57:36 2021-09-16 08:57:36
#>                         atime  uid  gid    uname   grname
#> Trial.omv 2021-09-16 08:57:36 1000 1000 sjentsch sjentsch
unlink("Trial.omv");