predict.Ptmodels {cycleRtools}R Documentation

Predict Power or Time

Description

Given a Ptmodels object, the predict.Ptmodels will produce a named numeric vector of either time (seconds) or power (watts) values according to the x and y arguments

Usage

## S3 method for class 'Ptmodels'
predict(object, x, xtype = c("pwr", "time"), ...)

Arguments

object

an object of class "Ptmodels".

x

the value for which to make a prediction.

xtype

what is x? A power or a time value?

...

further arguments passed to or from other methods.

Value

a named numeric vector of predicted values. Names correspond to their respective models.

Examples

data(Pt_prof)  # Example power-time profile.

P    <- Pt_prof$pwr
tsec <- Pt_prof$time

mdls <- Pt_model(P, tsec)  ## Model.
print(mdls)

## What is the best predicted 20 minute power?
predict(mdls, x = 60 * 20, xtype = "time")

## How sustainable is 500 Watts?
predict(mdls, x = 500, xtype = "P") / 60  # Minutes.

## Create some plots of the models.
par(mfrow = c(2, 2), mar = c(3.1, 3.1, 1.1, 1.1))
plotargs <- alist(x = tsec, y = P, cex = 0.2, ann = FALSE, bty = "l")
mapply(function(f, m) {
  do.call(plot, plotargs)
  curve(f(x), col = "red", add = TRUE)
  title(main = paste0(rownames(m),"; RSE = ", round(m$RSE, 2)))
  legend("topleft", legend = m$formula, bty = "n")
  return()
}, f = mdls$Pfn, m = split(mdls$table, seq_len(nrow(mdls$table))))


[Package cycleRtools version 1.1.1 Index]