Learn R Programming

MorphoRegions (version 0.1.0)

calcmodel: Calculate results of a single segmented regression model

Description

calcmodel() fits a multivariate segmented regression model using the supplied PCOs and breakpoints.

Usage

calcmodel(x, scores, bps, cont = TRUE)

Value

A regions_results_single object, which contains the results of the model (breakpoints and RSS of each PCO and overall) and model support statistics.

Arguments

x

a regions_pco object; the output of a call to svdPCO().

scores

numeric; the indices of the PCO scores to use as the outcomes in fitting the model (e.g., 1:4 to use the first four scores).

bps

numeric; the indices of the breakpoints to use in fitting the model. To request a model with no breakpoints, set to NA.

cont

logical; whether to fit a model that is continuous (TRUE) or discontinuous (FALSE) at the breakpoints. Default is TRUE. Ignored when bps is NA.

See Also

calcregions() and addregions() for computing all possible models instead of just a single one; plotsegreg(), for which the plot method is an alias, for plotting the fitted regression lines; modelsupport() for interpreting the model support statistics.

Examples

Run this code
data("alligator")

alligator_data <- process_measurements(alligator,
                                       pos = "Vertebra")

# Compute PCOs
alligator_PCO <- svdPCO(alligator_data)

# Calculate a single segmented regression model
# using first 2 PCOs and a discontinuous model
regionsmodel <- calcmodel(alligator_PCO,
                          scores = 1:3,
                          bps = c(8, 16, 21),
                          cont = FALSE)

regionsmodel

#Evaluate performance (R2) on that model
modelperf(regionsmodel)

#Plot model results:
plotsegreg(regionsmodel, scores = 1:3)

Run the code above in your browser using DataLab