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.56. 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.56.3 (2023-02-23)
For information on citing scan, type citation("scan").

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

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 all 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 8.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 -
scdf_attr Gets and sets attributes of an scdf Stable -
add_l2 Adds level-two data to an scdf Stable Section 10.0.1)
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
plot/plot.scdf Creates plots of single cases Stable
scplot Add-on package `scplot`. Create advanced ggplot2 plots. Experimental
style_plot Defines single-case plot graphical styles Superseded
export Creates html or latex tables from the output of various can functions Experimental
print/print.sc Prints the results of various scan outputs Stable
print/print.scdf Prints an scdf Stable
summary/summary.scdf Summaizes an scdf Stable
plot_rand Create a distribution plot from a randomization test obejct Experimental

2.4.3 Analysis

Table 2.3: Functions for data analysis
Function What it does ... Lifecycle stage
autocorr Autocorrelations for each phase of each case Stable
corrected_tau Baseline corrected tau Stable
describe Descriptive statistics for each phase of each case Stable
overlap An overview of overlap indeces for each case Stable
smd Various standardized mean differences between phase A and B Stable
rci Reliable change index Experimental
rand_test Randomization test Stable
tau_u Tau-U for each case and all cases Stable
trend Trend analyses for each case Stable
plm Piecewise linear regression model Stable
mplm Multivariate piecewise linear regression model Experimental
hplm Hierarchical piecewise linear regression model Stable
nap Non-overlap of all pairs for each case Stable
pnd Percentage of non overlapping data for each case Stable
pand Percentage of all non overlapping data for all cases Stable
pem Percantage exceeding the mean for each case Stable
pet Percentage exceeding the trend for each case Stable
cdc Conservative dual-criterion test Stable
outlier Detect outliers for all cases Stable

2.4.4 Manipulation

Table 2.4: Functions for data manipulation
Function What it does ... Lifecycle stage
transform Calculate new and change existing variables Stable
all_cases Helper function for transform that executes an expression across all cases of an scdf Stable
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
moving_media Helper function for transform to smooth with moving medians Stable
local_regression Helper function for transform to smooth with local regressions Stable
fill_missing Interpolate missign values or missing measurement times Stable
ranks Covert data into ranked data across all cases Superseded
transform Change and create new variabes 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
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
estimate_design Extraxt a deisgn template from an existing scdf Experimental
random_scdf Creats random single-case studies from a single-case design Stable
mcscan Add-on package `mcscan`. Create Monte-Carlo designs and analyses with `scan` (Upcoming not yet functioning)