Skip to content

Commit

Permalink
Bugfixes, Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffenMoritz committed Dec 8, 2020
1 parent c67f609 commit 4573d12
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 19 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Depends:
Imports:
stats,
grDevices,
ggplot2,
ggplot2 (>= 3.3.0),
ggtext,
stinepack,
forecast,
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
## Changes in Version 3.2
Thanks to Mark J. Lamias for bug / issue reporting.
Thanks to Cyrus Mohammadian for bug reporting.

* Fix to remove CRAN note - removed not used utils from DESCRIPTION imports

* Minor fix to ggplot_na_distribution (bars end now at max(timeseries)*1.05)

* Typo corrections in statsNA

* Specified ggplot2 (>= 3.3.0) in imports, to prevent errors with older ggplot2 versions (reported by Cyrus Mohammadian)

* Updated na_locf documentation to make behavior of na_remaining parameter more clear (issue reported by Mark J. Lamias)


## Changes in Version 3.1
Thanks to Johannes Menzel for bug reporting, Thanks to Jan (jmablans) for bug reporting,
Expand Down
44 changes: 35 additions & 9 deletions R/na_locf.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,41 @@
#' @return Vector (\code{\link{vector}}) or Time Series (\code{\link{ts}})
#' object (dependent on given input at parameter x)
#'
#' @details Replaces each missing value with the most recent present value
#' prior to it (Last Observation Carried Forward- LOCF). This can also be
#' done from the reverse direction -starting from the back (Next Observation
#' Carried Backward - NOCB). Both options have the issue, that NAs at the
#' beginning (or for nocb at the end) of the time series cannot be imputed
#' (since there is no last value to be carried forward present yet). In this
#' case there are remaining NAs in the imputed time series. Since this only
#' concerns very few values at the beginning of the series, na_remaining
#' offers some quick solutions to get a series without NAs back.
#' @details
#'
#' ## General Functionality
#' Replaces each missing value with the most recent present value
#' prior to it (Last Observation Carried Forward - LOCF). This can also be
#' done in reverse direction, starting from the end of the series (then
#' called Next Observation Carried Backward - NOCB).
#'
#'
#' ## Handling for NAs at the beginning of the series
#' In case one or more successive observations directly at the start of the
#' time series are NA, there exists no 'last value' yet, that can be carried
#' forward. Thus, no LOCF imputation can be performed for these NAs. As soon
#' as the first non-NA value appears, LOCF can be performed as expected. The
#' same applies to NOCB, but from the opposite direction.
#'
#' While this problem might appear seldom and will only affect a very small
#' amount of values at the beginning, it is something to consider.
#' The \code{na_remaining} parameter helps to define, what should happen with these
#' values at the start, that would remain NA after pure LOCF.
#'
#' Default setting is \code{na_remaining = "rev"}, which performs nocb / locf from
#' the other direction to fill these NAs. So a NA at the beginning will be
#' filled with the next non-NA value appearing in the series.
#'
#' With \code{na_remaining = "keep"} NAs at the beginning (that can not be imputed
#' with pure LOCF) are just left as remaining NAs.
#'
#' With \code{na_remaining = "rm"} NAs at the beginning of the series are completely
#' removed. Thus, the time series is basically shortened.
#'
#' Also available is \code{na_remaining = "mean"}, which uses the overall mean of the
#' time series to replace these remaining NAs. (but beware, mean is usually
#' not a good imputation choice - even if it only affects the values at the
#' beginning)
#'
#' @author Steffen Moritz
#'
Expand Down
2 changes: 1 addition & 1 deletion R/na_random.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ na_random <- function(x, lower_bound = NULL, upper_bound = NULL, maxgap = Inf) {

# 1.6 Check and set values for param lower_bound and upper_bound

# If lower or upper bound is NULL, which is the funtion default usw min/max
# If lower or upper bound is NULL, which is the function default usw min/max
if (is.null(lower_bound)) {
lower_bound <- min(data, na.rm = TRUE)
}
Expand Down
43 changes: 35 additions & 8 deletions man/na_locf.Rd

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

0 comments on commit 4573d12

Please sign in to comment.