2  The scan package

2.1 Installing the scan package

You can use the install.packages function to install scan.

install.packages("scan") will install the stable version.

The current stable release is version 0.63.0. Please refer to the Software Reference section to see which version of scan was used to create this book, and make sure you have this or a newer version installed.

R contains many packages, and it would slow things down considerably if all packages were loaded into memory at the beginning of each R session. Therefore, after installing scan, you need to enable it at the beginning of each session in which you use R. Normally, a session starts when you start the R program and ends when you quit it.

To activate a package, you need the library function. In this case, library(scan). You should get something like

scan 0.64.999 (2025-04-01)

indicating that everything went smoothly and scan is ready for work.

For creating single-case plots, please install the add-on package scplot with install.packages("scplot").

2.2 Development version of scan

Alternatively, you can compile the development version of scan yourself. This may be necessary if the stable version has some bugs or missing features that have been fixed.

You may need some computer knowledge to get the development version running. It is hosted on gitHub at <https://github.com/jazznbass/scan>.

For installation, you can apply the install_github function from the devtools package (make sure you have installed the devtools package before):

devtools::install_github("jazznbass/scan", dependencies = TRUE)

If you are using a Windows operating system, you will probably need to install Rtools first. Rtools contains additional programs (e.g. compilers) needed to compile R source packages.

You can find Rtools here: <https://cran.r-project.org/bin/windows/Rtools/>

2.3 Reporting issues with scan and suggesting enhancements

The scan gitHub repository at <https://github.com/jazznbass/scan> is the ideal place to report bugs, problems, or ideas for enhancing scan. Please use the issue tool (direct link: <https://github.com/jazznbass/scan/issues>).

We are very thankful for any feedback, corrections, or whatever helps to improve scan!

2.4 Functions overview

The functions of the scan package can be divided into the following categories:
Manage data, analyze, manipulate, simulate, and depict.

The following tables give an overview of the central functions. Furthermore, you can see the current life cycle stage of a function. The life cycle stage categorization is based on the tidyverse package and described in detail here https://lifecycle.r-lib.org/articles/stages.html.

2.4.1 Management

Table 2.1: Functions for data management
Function What it does … Lifecycle stage Chapter
scdf Creates a single-case data-frame Stable Section 3.2
select_cases Selects specific cases of an scdf Stable Section 4.1
select_phases Selects and/or recombines phases Stable Section 9.1.1
subset Selects specific measurements or variables of an scdf stable Section 4.2
read_scdf Loads external data into an scdf Stable Section 3.4.1
write_scdf Writes scdf into an external file Stable Section 3.4.3
convert Converts an scdf object into R syntax Stable Section 3.5
set_var (Re)sets dependent, measurement, and phase variable of an scdf Stable Chapter 6
add_l2 Adds level-two data to an scdf Stable Section 11.0.4
as_scdf Transforms a data.frame into an scdf Stable -
as.data.frame/as.data.frame.scdf Transforms an scdf into a data frame Stable -

2.4.2 Depiction

Table 2.2: Functions for data depiction/visualisation
Function What it does … Lifecycle stage Chapter
scplot Add-on package scplot. Creates advanced ggplot2 plots Stable Chapter 5
print/print.scdf Prints an scdf Stable Section 3.6
summary/summary.scdf Summaizes an scdf Stable Section 3.6.1
export Creates html or latex tables from the output of various scan functions Stable Chapter 16
plot/plot.scdf Creates plots of single cases Superseded -
style_plot Defines single-case plot graphical styles Superseded -
plot_rand Create a distribution plot from a randomization test obejct Superseded -

2.4.3 Analysis

Table 2.3: Functions for data analysis
Function What it does … Lifecycle stage Chapter
autocorr Autocorrelations for each phase of each case Stable Section 8.2
describe Descriptive statistics for each phase of each case Stable Section 8.1
ird Improvement rate difference Stable Section 9.7
overlap An overview of overlap indeces for each case Stable Chapter 9
smd Various standardized mean differences between phase A and B Stable Section 9.10
rci Reliable change index Stable Section 9.12
rand_test Randomization test Stable Chapter 14
trend Trend analyses for each case Stable Section 8.3
plm Piecewise linear regression model Stable Chapter 10
mplm Multivariate piecewise linear regression model Experimental Chapter 12
hplm Hierarchical piecewise linear regression model Stable Chapter 11
bplm Bayesian (multilevel) piecewise linear regression model Experimental Chapter 13
between_smd Between case standardized mean difference Stable Section 9.11
anova Modelcomparison via likelihood ratio test for plm and hplm Stable Section 10.7
tau_u Tau-U for each case and all cases Stable Section 9.8
corrected_tau Baseline corrected tau Stable Section 9.9
nap Non-overlap of all pairs for each case Stable Section 9.6
pnd Percentage of non overlapping data for each case Stable Section 9.2
pand Percentage of all non overlapping data for all cases Stable Section 9.5
pem Percantage exceeding the mean for each case Stable Section 9.3
pet Percentage exceeding the trend for each case Stable Section 9.4
cdc Conservative dual-criterion test Stable ?sec-cdc
outlier Detect outliers for all cases Stable Section 7.2

2.4.4 Manipulation

Table 2.4: Functions for data manipulation
Function What it does … Lifecycle stage Chapter
transform Calculate new and change existing variables Stable Section 4.3
all_cases Helper function for ‘transform()’ that executes an expression across all cases of an scdf Stable Section 4.3.1
across_cases Helper function for ‘transform()’ that calculates a variable for all cases of an scdf Stable -
moving_mean Helper function for ‘transform()’ to smooth with moving means Stable Section 4.3.2
moving_media Helper function for ‘transform()’ to smooth with moving medians Stable Section 4.3.2
local_regression Helper function for ‘transform()’ to smooth with local regressions Stable Section 4.3.2
fill_missing Interpolate missign values or missing measurement times Stable Section 7.1
rescale Standardizes variables across cases Stable Section 10.3
ranks Covert data into ranked data across all cases Superseded -
smooth_cases Smoothes time series data Superseded -
truncate_phase Deletes measurements of phases Superseded -
standardize Standardizes or centers variables across cases Superseded -

2.4.5 Simulation

Table 2.5: Functions for data simulation
Function What it does … Lifecycle stage Chapter
design Defines a design of one or multiple single-cases Stable -
power_test Calculates power and alpha error of a specific analyzes for a specific single-case design Stable Section 16.15
random_scdf Creats random single-case studies from a single-case design Stable -
estimate_design Extraxt a deisgn template from an existing scdf Experimental -
mcscan Add-on package mcscan. Create Monte-Carlo designs and analyses with scan (Upcoming not yet functioning) -