plotsegreg {MorphoRegions} | R Documentation |
Plot a segmented regression model
Description
plotsegreg()
plots the fitted lines resulting from a segmented regression model.
Usage
plotsegreg(x, scores, ...)
## S3 method for class 'regions_pco'
plotsegreg(
x,
scores,
modelsupport = NULL,
criterion = "aic",
model = 1,
bps = NULL,
cont = TRUE,
...
)
## S3 method for class 'regions_sim'
plotsegreg(
x,
scores,
modelsupport = NULL,
criterion = "aic",
model = 1,
bps = NULL,
cont = TRUE,
...
)
## S3 method for class 'regions_results_single'
plotsegreg(x, scores, ...)
Arguments
x |
a |
scores |
|
... |
ignored. |
modelsupport |
a |
criterion |
string; the criterion to use to select the best model for which breakpoints are to be displayed when |
model |
|
bps |
|
cont |
|
Details
plotsegreg()
operates on a single model identified by breakpoints and whether the model is continuous or not. When x
is a regions_pco
object, the model is selected either as the best model in the supplied modelsupport
object (where "best" is determined by the arguments to criterion
and model
) or as specified by the user using the arguments to bps
and cont
. When x
is a regions_results_single
object, the breakpoints and model form are determined based on the supplied object.
plot()
is an alias for plotsegreg()
for regions_results_single
objects.
Value
A ggplot
object that can be manipulated using ggplot2 syntax.
See Also
modelsupport()
for assessing model support using information criteria; calcmodel()
for fitting a single segmented regression model; modelperf()
for computing fit statistics for a single segmented regression model.
Examples
data("alligator")
alligator_data <- process_measurements(alligator,
pos = "Vertebra")
# Compute PCOs
alligator_PCO <- svdPCO(alligator_data)
# Evaluate model performance (R2) given supplied
# breakpoints for a continuous model
modelperf(alligator_PCO, scores = 1:3,
bps = c(7, 15, 20), cont = TRUE)
plotsegreg(alligator_PCO, scores = 1:3,
bps = c(7, 15, 20), cont = TRUE)
## See also `?calcmodel` for use with a single model
# Fit segmented regression models for 1 to 7 regions
# using PCOs 1 to 4 and a continuous model with a
# non-exhaustive search
regionresults <- calcregions(alligator_PCO,
scores = 1:4,
noregions = 7,
minvert = 3,
cont = TRUE,
exhaus = FALSE,
verbose = FALSE)
regionresults
# For each number of regions, identify best
# model based on minimizing RSS
bestresults <- modelselect(regionresults)
# Evaluate support for each model and rank
supp <- modelsupport(bestresults)
# Evaluate model performance (R2) for best model
# as chosen by BIC
modelperf(alligator_PCO, scores = 1:4,
modelsupport = supp,
criterion = "bic", model = 1)
# Plot that model for the first PCO score
plotsegreg(alligator_PCO, scores = 1:4,
modelsupport = supp,
criterion = "bic", model = 1)
## See `?simregions` for use with simulated data