Skip to content

Commit

Permalink
- Add strucchange and tseries in suggested packages
Browse files Browse the repository at this point in the history
- Add test for `data_class` and `fix_names` parameters of `to_lm()`
  • Loading branch information
Natsiopoulos committed Aug 15, 2023
1 parent e913045 commit a9c35e4
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ LazyData: true
Depends:
R (>= 3.5.0)
Suggests:
strucchange,
tseries,
qpcR,
sandwich,
testthat (>= 3.0.0)
Expand Down
19 changes: 12 additions & 7 deletions R/to_lm.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
#' @param fix_names A logical, indicating whether the variable names should be
#' rewritten without special functions and character in the names such as "d()"
#' or "L()". When \code{fix_names = TRUE}, the characters "(", and "," are
#' replaces with ".", and ")" and spaces are deleted. Default is FALSE.
#' @param data_class Converts the data class to \code{\link[stats]{ts}} (see
#' examples for its usage). The default is \code{\link[base]{NULL}}, which uses
#' the same data provided in the original object.
#' replaces with ".", and ")" and spaces are deleted. The name of the dependent
#' variable is always transformed, regardless of the value of this parameter.
#' Default is FALSE.
#' @param data_class If "ts", it converts the data class to
#' \code{\link[stats]{ts}} (see examples for its usage). The default is
#' \code{\link[base]{NULL}}, which uses the same data provided in the original
#' object.
#' @param ... Currently unused argument.
#'
#' @return \code{to_lm} returns an object of \code{\link[base]{class}}
Expand Down Expand Up @@ -92,10 +95,12 @@
#' plot(fluctuation)
#'

to_lm <- function(object, fix_names = FALSE, data_class = c(NULL, "ts"), ...) {
to_lm <- function(object, fix_names = FALSE, data_class = NULL, ...) {
objmodel <- object$model
if (data_class == "ts") {
objmodel <- ts(objmodel, start = start(objmodel[,1]), frequency = frequency(objmodel[,1]))
if (!is.null(data_class)) {
if (data_class == "ts") {
objmodel <- stats::ts(objmodel, start = stats::start(objmodel[,1]), frequency = stats::frequency(objmodel[,1]))
}
}
dep_var <- colnames(objmodel)[1]
fix_names_fun <- function(text) {
Expand Down
15 changes: 9 additions & 6 deletions man/to_lm.Rd

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

15 changes: 15 additions & 0 deletions tests/testthat/test-to_lm.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ test_that("From ardl to lm", {
expect_equal(ardl_3132$df.residual, ardl_3132_lm$df.residual)
expect_equal(ardl_3132$xlevels, ardl_3132_lm$xlevels)
expect_equal(ardl_3132$model, ardl_3132_lm$model, ignore_attr= TRUE)

# Check data_class = "ts"
ardl_3132_lm_ts <- to_lm(ardl_3132, data_class = "ts")
expect_equal(ardl_3132_lm$coefficients, ardl_3132_lm_ts$coefficients)
})

test_that("From uecm to lm", {
Expand All @@ -30,6 +34,17 @@ test_that("From uecm to lm", {
expect_equal(uecm_3132$df.residual, uecm_3132_lm$df.residual)
expect_equal(uecm_3132$xlevels, uecm_3132_lm$xlevels)
expect_equal(uecm_3132$model, uecm_3132_lm$model, ignore_attr= TRUE)

# fix_names = TRUE
uecm_3132_lm_names <- to_lm(uecm_3132, fix_names = TRUE)
names_FALSE <- c("d.LRM", "L(LRM, 1)", "L(LRY, 1)", "L(IBO, 1)", "L(IDE, 1)",
"d(L(LRM, 1))", "d(L(LRM, 2))", "d(LRY)", "d(IBO)",
"d(L(IBO, 1))", "d(L(IBO, 2))", "d(IDE)", "d(L(IDE, 1))")
names_TRUE <- c("d.LRM", "L.LRM.1", "L.LRY.1", "L.IBO.1", "L.IDE.1",
"d.L.LRM.1", "d.L.LRM.2", "d.LRY", "d.IBO", "d.L.IBO.1",
"d.L.IBO.2", "d.IDE", "d.L.IDE.1")
expect_equal(names(uecm_3132_lm$model), names_FALSE)
expect_equal(names(uecm_3132_lm_names$model), names_TRUE)
})

test_that("Exclude intercept when -1", {
Expand Down

0 comments on commit a9c35e4

Please sign in to comment.