Skip to content

Commit

Permalink
Added methods for "NULL" model
Browse files Browse the repository at this point in the history
Related: #234
  • Loading branch information
mitchelloharawild committed Jul 10, 2020
1 parent 73f05e6 commit 524c37a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
9 changes: 9 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ S3method(features,tbl_ts)
S3method(features_all,tbl_ts)
S3method(features_at,tbl_ts)
S3method(features_if,tbl_ts)
S3method(fitted,"NULL")
S3method(fitted,mdl_df)
S3method(fitted,mdl_ts)
S3method(fitted,model_combination)
S3method(fitted,null_mdl)
S3method(forecast,"NULL")
S3method(forecast,fbl_ts)
S3method(forecast,lst_btmup_mdl)
S3method(forecast,lst_mdl)
Expand All @@ -83,6 +85,7 @@ S3method(format,lst_mdl)
S3method(format,mdl_ts)
S3method(fortify,fbl_ts)
S3method(gather,mdl_df)
S3method(generate,"NULL")
S3method(generate,mdl_df)
S3method(generate,mdl_ts)
S3method(generate,model_combination)
Expand All @@ -91,6 +94,7 @@ S3method(get_frequencies,"NULL")
S3method(get_frequencies,Period)
S3method(get_frequencies,character)
S3method(get_frequencies,numeric)
S3method(glance,"NULL")
S3method(glance,mdl_df)
S3method(glance,mdl_ts)
S3method(glance,null_mdl)
Expand Down Expand Up @@ -119,15 +123,18 @@ S3method(quantile,fcdist)
S3method(rbind,dcmp_ts)
S3method(rbind,fbl_ts)
S3method(reconcile,mdl_df)
S3method(refit,"NULL")
S3method(refit,lst_mdl)
S3method(refit,mdl_df)
S3method(refit,mdl_ts)
S3method(refit,null_mdl)
S3method(rep,fcdist)
S3method(report,"NULL")
S3method(report,mdl_df)
S3method(report,mdl_ts)
S3method(report,model_combination)
S3method(report,null_mdl)
S3method(residuals,"NULL")
S3method(residuals,mdl_df)
S3method(residuals,mdl_ts)
S3method(residuals,null_mdl)
Expand All @@ -139,12 +146,14 @@ S3method(response_vars,mdl_df)
S3method(select,fbl_ts)
S3method(select,grouped_fbl)
S3method(select,mdl_df)
S3method(stream,"NULL")
S3method(stream,lst_mdl)
S3method(stream,mdl_df)
S3method(stream,mdl_ts)
S3method(stream,null_mdl)
S3method(summarise,fbl_ts)
S3method(summarise,grouped_fbl)
S3method(tidy,"NULL")
S3method(tidy,mdl_df)
S3method(tidy,mdl_ts)
S3method(tidy,null_mdl)
Expand Down
33 changes: 31 additions & 2 deletions R/model_null.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ null_model <- function(formula, ...){
is_null_model <- function(x){
if(is_model(x)) return(is_null_model(x[["fit"]]))
if(inherits(x, "lst_mdl")) return(map_lgl(x, is_null_model))
inherits(x, "null_mdl")
is.null(x) || inherits(x, "null_mdl")
}

#' @export
Expand All @@ -34,51 +34,80 @@ forecast.null_mdl <- function(object, new_data, ...){
construct_fc(rep(NA_real_, h), rep(0, h), dist_unknown(h))
}

#' @export
forecast.NULL <- forecast.null_mdl

#' @export
generate.null_mdl <- function(x, new_data, ...){
mutate(new_data, .sim = NA_real_)
}
#' @export
generate.NULL <- generate.null_mdl

#' @export
stream.null_mdl <- function(object, new_data, ...){
object$n <- object$n + NROW(new_data)
object
}
#' @export
stream.NULL <- function(object, new_data, ...) {
NULL
}

#' @export
refit.null_mdl <- function(object, new_data, ...){
object$n <- NROW(new_data)
object
}
#' @export
refit.NULL <- function(object, new_data, ...) {
NULL
}

#' @export
residuals.null_mdl <- function(object, ...){
matrix(NA_real_, nrow = object$n, ncol = length(object$vars),
dimnames = list(NULL, object$vars))
}
#' @export
residuals.NULL <- function(object, new_data, ...) {
NA_real_
}

#' @export
fitted.null_mdl <- function(object, ...){
matrix(NA_real_, nrow = object$n, ncol = length(object$vars),
dimnames = list(NULL, object$vars))
}
#' @export
fitted.NULL <- function(object, new_data, ...) {
NA_real_
}

#' @export
glance.null_mdl <- function(x, ...){
tibble()
}
#' @export
glance.NULL <- glance.null_mdl

#' @export
tidy.null_mdl <- function(x, ...){
tibble(term = character(), estimate = numeric())
}
#' @export
tidy.NULL <- tidy.null_mdl

#' @export
report.null_mdl <- function(object, ...){
cat("NULL model")
}
#' @export
report.NULL <- report.null_mdl

#' @export
model_sum.null_mdl <- function(x){
"NULL model"
}
}
#' @export
report.NULL <- report.null_mdl

0 comments on commit 524c37a

Please sign in to comment.