bfmPredict: Harmonic and trend predictions from a bfastmonitor object

Description Usage Arguments Details Value Author(s) Examples

Description

Produce a new data.frame from bfastmonitor objects including harmonic and trend predictions (where applicable). Multiple bfastmonitor objects can be used (see details).

Usage

1
bfmPredict(bfm, type = "irregular", plotlabs = NULL)

Arguments

bfm

Object (or list of objects) of type bfastmonitor

type

Character. Type of time series on which bfm is based. Either “irregular" or “16-day" (see bfastts).

plotlabs

Character. Vector of labels corresponding to objects in bfm. Can be omitted (automatic labels will be added in that case if bfm is a list of bfastmonitor objects.)

Details

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.

Value

data.frame with model parameters and predictions according to bfastmontior parameters in bfm. See details for more info.

Author(s)

Ben DeVries and Jan Verbesselt

Examples

 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

bendv/bfastPlot documentation built on May 12, 2019, 10:58 a.m.