Skip to content

Commit

Permalink
Merge pull request #56 from bfast2/20-bfast0n
Browse files Browse the repository at this point in the history
Create a function for bfast0n
  • Loading branch information
GreatEmerald authored Jun 2, 2020
2 parents e40a9cd + c880e6c commit 1c88bdb
Show file tree
Hide file tree
Showing 22 changed files with 277 additions and 74 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ URL: http://bfast.R-Forge.R-project.org/
LazyLoad: yes
LazyData: yes
LinkingTo: Rcpp
RoxygenNote: 5.0.1
RoxygenNote: 7.1.0
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ S3method(residuals,bfast01)
export(bfast)
export(bfast01)
export(bfast01classify)
export(bfast0n)
export(bfastmonitor)
export(bfastpp)
export(bfastts)
Expand Down
41 changes: 41 additions & 0 deletions R/bfast0n.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# This file is part of BFAST.
#
# BFAST is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# BFAST is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with BFAST. If not, see <http://www.gnu.org/licenses/>.

#' Detect multiple breaks in a time series
#'
#' A combination of \code{\link{bfastpp}} and \code{\link[strucchange]{breakpoints}}
#' to do light-weight detection of multiple breaks in a time series
#' while also being able to deal with NA values by excluding them
#' via \code{bfastpp}.
#'
#' @param ... Additional arguments to \code{\link[strucchange]{breakpoints}}.
#' @inheritParams bfastpp
#' @inheritParams strucchange::breakpoints
#' @example examples/bfast0n.r
#'
#' @export bfast0n

bfast0n <- function(data, formula=response ~ trend + harmon, order = 3,
lag = NULL, slag = NULL, na.action = na.omit,
stl = c("none", "trend", "seasonal", "both"),
decomp=c("stlplus", "stl"), sbins=1, ...)
{
data_pp <- bfastpp(data, order = 3,
lag = NULL, slag = NULL, na.action = na.omit,
stl = c("none", "trend", "seasonal", "both"),
decomp=c("stlplus", "stl"), sbins=1)
return(strucchange::breakpoints(formula=formula, data = data_pp, ...))
}
13 changes: 13 additions & 0 deletions examples/bfast0n.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
plot(simts) # stl object containing simulated NDVI time series
datats <- ts(rowSums(simts$time.series))
# sum of all the components (season,abrupt,remainder)
tsp(datats) <- tsp(simts$time.series) # assign correct time series attributes
plot(datats)

# Detect breaks
bp = bfast0n(datats)

# Default method of estimating breakpoints
bp[["breakpoints"]]
# Custom method
strucchange::breakpoints(bp, breaks=2)
10 changes: 5 additions & 5 deletions man/bfast-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 21 additions & 8 deletions man/bfast.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 23 additions & 9 deletions man/bfast01.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions man/bfast01classify.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions man/bfast0n.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 24 additions & 9 deletions man/bfastmonitor.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1c88bdb

Please sign in to comment.