Description Usage Arguments Details Value Author(s) Examples
Produce a new data.frame from bfastmonitor objects including harmonic and trend predictions (where applicable). Multiple bfastmonitor objects can be used (see details).
1 | bfmPredict(bfm, type = "irregular", plotlabs = NULL)
|
bfm |
Object (or list of objects) of type |
type |
Character. Type of time series on which |
plotlabs |
Character. Vector of labels corresponding to objects in |
The main purpose of this function is to prepare a data.frame
to be entered into ggplot
. Rather than simply using the tspp
part of the bfastmonitor
output to plot predicted and observed values, this function 'regularizes' the tspp
output to produce a smooth predicted curve. See bfmPlot
for a shortcut to creating ggplot objects from bfastmonitor outputs.
data.frame
with model parameters and predictions according to bfastmontior parameters in bfm
. See details for more info.
Ben DeVries and Jan Verbesselt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | data(tura_ts3)
plot(tura_ts3)
library(bfast)
# make tura_ts3 into a 'regular' time series (with NA's)
tts <- bfastts(tura_ts3, dates = time2date(time(tura_ts3)), type = "irregular")
# run bfastmonitor
bfm <- bfastmonitor(tts, start = c(2005, 1), formula = response~harmon, order = 1, history = "all")
# default plot
plot(bfm)
## predicted values (blue curve) are only shown where (irregular) observations occur on the time axis
# make a data.frame with 'regular' predictions
bfmpred <- bfmPredict(bfm)
head(bfmpred)
# simple ggplot
library(ggplot2)
p <- ggplot(data = bfmpred, aes(x = time))
p <- p + geom_line(aes(y = prediction), col = "blue")
p <- p + geom_point(aes(y = response), na.rm = TRUE)
p <- p + theme_bw()
print(p)
# label start of monitoring period with a vertical line
# and breakpoint with a red dashed line
p <- p + geom_vline(aes(xintercept = start))
p <- p + geom_vline(aes(xintercept = breakpoint), col = "red", lty = 2)
print(p)
# bfmPlot() is a shortcut to creating such plot objects
?bfmPlot
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.