# piecewiseRegr

0th

Percentile

##### Piecewise regression analysis

This function conducts a piecewise regression analysis and shows a plot illustrating the results. The function enables easy customization of the main plot elements and easy saving of the plot with anti-aliasing.

Keywords
regression, htest, hplot
##### Usage
piecewiseRegr(data,
timeVar = 1,
yVar = 2,
phaseVar = NULL,
baselineMeasurements = NULL,
robust = FALSE,
digits = 2,
colors = list(pre = viridis(4)[1],
post = viridis(4)[4],
diff = viridis(4)[3],
intervention = viridis(4)[2],
points = "black"),
theme = theme_minimal(),
pointSize = 2,
pointAlpha = 1,
lineSize = 1,
yRange=NULL,
yBreaks = NULL,
showPlot = TRUE,
plotLabs = NULL,
outputFile = NULL,
outputWidth = 16,
outputHeight = 16,
ggsaveParams = list(units = "cm",
dpi = 300,
type = "cairo"))
##### Arguments
data

The dataframe containing the variables for the analysis.

timeVar

The name of the variable containing the measurement moments (or an index of measurement moments). An index can also be specified, and assumed to be 1 if omitted.

yVar

The name of the dependent variable. An index can also be specified, and assumed to be 2 if omitted.

phaseVar

The variable containing the phase of each measurement. Note that this normally should only have two possible values.

baselineMeasurements

If no phaseVar is specified, baselineMeasurements can be used to specify the number of baseline measurements, which is then used to construct the phaseVar dummy variable.

robust

Whether to use normal or robust linear regression.

digits

The number of digits to show in the results.

colors

The colors to use for the different plot elements.

theme

The theme to use in the plot.

pointSize,lineSize

The sizes of points and lines in the plot.

yRange

This can be used to manually specify the possible values that the dependent variable can take. If not provided, the observed range of the dependent variable values is used instead.

yBreaks

If NULL, the pretty function is used to estimate the best breaks for the Y axis. If a value is supplied, this value is used as the size of intervals between the (floored) minimum and (ceilinged) maximum of yRange (e.g. if yBreaks is 1, a break point every integer; if 2 and the minimum is 1 and the maximum is 7, breaks at 1, 3, 5 and 7; etc).

pointAlpha

The alpha channel (transparency, or rather, 'opaqueness') of the points.

showPlot

Whether to show the plot or not.

plotLabs

A list with arguments to the ggplot2 labs function, which can be used to conveniently set plot labels.

outputFile

If not NULL, the path and filename specifying where to save the plot.

outputWidth, outputHeight

The dimensions of the plot when saving it (in units specified in ggsaveParams).

ggsaveParams

The parameters to use when saving the plot, passed on to ggsave.

##### Value

Mainly, this function prints its results, but it also returns them in an object containing three lists:

input

The arguments specified when calling the function

intermediate

Intermediat objects and values

output

The results such as the plot.

##### References

Verboon, P. & Peters, G.-J. Y. (2018) Applying the generalised logistic model in single case designs: modelling treatment-induced shifts. PsyArXiv https://doi.org/10.17605/osf.io/ad5eh

genlog

##### Aliases
• piecewiseRegr
##### Examples
# NOT RUN {
data(Singh);

### Extract Jason
dat <- Singh[Singh\$tier==1, ];

### Conduct piecewise regression analysis
piecewiseRegr(dat,
timeVar='time',
yVar='score_physical',
phaseVar='phase');

### Pretend treatment started between measurements
### 5 and 6
piecewiseRegr(dat,
timeVar='time',
yVar='score_physical',
baselineMeasurements=5);

# }

Documentation reproduced from package userfriendlyscience, version 0.7.2, License: GPL (>= 3)

### Community examples

Looks like there are no examples yet.