# R functions for the hierarchical shift function

The hierarchical shift function presented in the previous post is now available in the `rogme` R package. Here is a short demo.

``````# install.packages("devtools")
devtools::install_github("GRousselet/rogme")
library(rogme)
library(tibble)
``````

Load data and compute hierarchical shift function:

``````df <- flp # get reaction time data - for details `help(flp)`
# Compute shift functions for all participants
out <- hsf(df, rt ~ condition + participant)
``````

Because of the large number of participants, the confidence intervals are too narrow to be visible. So let’s subset a random sample of participants to see what can happen with a more smaller sample size:

``````set.seed(22) # subset random sample of participants
id <- unique(df\$participant)
df <- subset(df, flp\$participant %in% sample(id, 50, replace = FALSE))
out <- hsf(df, rt ~ condition + participant)
plot_hsf(out)
``````

Want to estimate the quartiles only?

``````out <- hsf(df, rt ~ condition + participant, qseq = c(.25, .5, .75))
plot_hsf(out)
``````

Want to reverse the comparison?

``````out <- hsf(df, rt ~ condition + participant, todo = c(2,1))
plot_hsf(out)
``````

P values are here:

``out\$pvalues``

P values adjusted for multiple comparisons using Hochberg’s method:

``out\$adjusted_pvalues ``

Percentile bootstrap version:

``````set.seed(8899)
out <- hsf_pb(df, rt ~ condition + participant)
``````

Plot bootstrap highest density intervals – default:

``````plot_hsf_pb(out)
``````

Plot distributions of bootstrap samples of group differences. Bootstrap distributions are shown in orange. Black dot marks the mode. Vertical black lines mark the 50% and 90% highest density intervals.

``plot_hsf_pb_dist(out)``

For more examples, a vignette is available on GitHub.

Feedback would be much appreciated: don’t hesitate to leave a comment or to get in touch directly.