*この節の作者: Sebastian Jentschke*

# Rj Editor for jamovi¶

## Preparation¶

First you have to install the module Rj from the jamovi library. This will create a «R»-icon in the icon bar.

## Running R commands¶

Click on the «R» icon and select «Rj Editor».

This opens an input field on the left side where you can use R commands.

You can access your dataset with the variable

`data`

. The first line selects the first three columns of your dataset. Alternatively, you can use variable names as shown in the second line.summary(data[1:3]) summary(data[, c('var1', 'var2', 'var3')])Sometimes you may need a list of all your variables as a string (e.g., for using them in connection with functions in Computed variables). Of course, you can as well restrict the variables with the column indices as in the command above. Afterwards, you can just copy the output text and insert it, e.g., into a function for a computed variable:

`SUM([insert text you copied])`

paste0(names(data), collapse = ", ") paste0(names(data[2:10]), collapse = ", ")But you can also use functions from R libraries (e.g.,

`stats`

). When doing so, you may have to precede these functions with the name of the package and`::`

.stats::aggregate(as.numeric(data[, 'var1']), list(data[, 'gender']), mean)It may take a bit of time to figure out how to use these functions, especially to discover, e.g., which format is required for the data matrices you use as input to functions (those may need to be converted to numbers with

`as.numeric()`

or to a list with`list`

). But once you managed that, you have unlimited access to (almost) any kind of statistical analysis you can imagine.The following commands permits you to list the wealth of R libraries included with jamovi and Rj:

sort(rownames(installed.packages()))Some of these libraries are especially interesting:

`stats`

to get access to a wealth of statistical analyses (e.g.,`stats::glm`

for fitting Generalized Linear Models or`stats:kmeans`

for running k-means cluster analyses)

`lme4`

to calculate Linear, Generalized Linear, and Nonlinear mixed modells

`MASS`

implements analyses from Venables og Ripley's famous book «Modern Applied Statistics with S» (which includes, e.e., linear discriminant analysis`MASS::lda`

)

`lavaan`

to run a wide range of analyses with latent variables (incl. confirmatory factor analysis, structural equation modeling and latent growth curve models)

`BayesFactor`

to run several types of Bayes-analyses to complement your «classical» (frequentist) statistics (e.g. the Bayes-equivalent of the t-test; NB: it is of course easier to use the jamovi-module «jsq» for that)

`cluster`

to run several types of cluster analyses

`ggplot2`

to produce (almost) any type of fancy figures you can imaginethere are also several of Hadley Wickham's

`tidyverse`

libraries included, e.g.,`dplyr`

,`stringr`

or`tidyselect`

## Switch between R-versions¶

Per default, Rj uses the R-installation that is included with jamovi. For most circumstances this will be sufficient (not the least because quite a wealth of libraries is included; see above). However, there might be occasions where you would like to use the R-installation on your computer; typically, if you want to use libraries that are not included in jamovi's R-version. To do this, click on the cogwheel symbol in the top-right corner of the Rj-input field. A window opens where you can set whether you would like to use jamovi's R version («jamovi R» in the dropdown box at the bottom) or your system's R version («System R»). Please note that this option this option is not available for certain system-and-R-version-combinations (e.g., R > 3.4 on Linux).