
Last chance! 50% off unlimited learning
Sale ends in
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.
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"))
The dataframe containing the variables for the analysis.
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.
The name of the dependent variable. An index can also be specified, and assumed to be 2 if omitted.
The variable containing the phase of each measurement. Note that this normally should only have two possible values.
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.
Whether to use normal or robust linear regression.
The number of digits to show in the results.
The colors to use for the different plot elements.
The theme to use in the plot.
The sizes of points and lines in the plot.
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.
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).
The alpha channel (transparency, or rather, 'opaqueness') of the points.
Whether to show the plot or not.
If not NULL
, the path and filename specifying where to save the plot.
The dimensions of the plot when saving it (in units specified in ggsaveParams
).
The parameters to use when saving the plot, passed on to ggsave
.
Mainly, this function prints its results, but it also returns them in an object containing three lists:
The arguments specified when calling the function
Intermediat objects and values
The results such as the plot.
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
# NOT RUN {
### Load dataset
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);
# }
Run the code above in your browser using DataLab