From b8e401d92d3dbd352de7559ce3e59de3adc7be48 Mon Sep 17 00:00:00 2001 From: Daan de Jong Date: Mon, 27 Nov 2023 14:17:08 +0100 Subject: [PATCH] rounding of r0 and r1 in plot labels --- .Rhistory | 232 ++++++++++++++++++++++++++-------------------------- NEWS.md | 4 +- R/plot.R | 5 +- R/welcome.R | 29 +++++++ README.Rmd | 7 +- README.md | 28 +++---- 6 files changed, 168 insertions(+), 137 deletions(-) create mode 100644 R/welcome.R diff --git a/.Rhistory b/.Rhistory index 7108de7..6e63a07 100644 --- a/.Rhistory +++ b/.Rhistory @@ -1,119 +1,3 @@ -devtools::load_all(".") -fit <- hystar_fit(y = s$data$y, z = s$data$z, -r = matrix(c(-.3, -.3, --.2, .1), nrow = 2, byrow = TRUE), -d = 0, p0 = 1, p1 = 1, tar = TRUE) -fit <- hystar_fit(y = s$data$y, z = s$data$z, -r = matrix(c(-.3, -.3, --.2, -.2), nrow = 2, byrow = TRUE), -d = 0, p0 = 1, p1 = 1, tar = TRUE) -fit <- hystar_fit(y = s$data$y, z = s$data$z, -r = matrix(c(-.3, -.3, --.2, -.2), nrow = 2, byrow = TRUE), -d = 0, p0 = 1, p1 = 1, tar = TRUE) -devtools::load_all(".") -fit <- hystar_fit(y = s$data$y, z = s$data$z, -r = matrix(c(-.3, -.3, --.2, -.2), nrow = 2, byrow = TRUE), -d = 0, p0 = 1, p1 = 1, tar = TRUE) -s -devtools::load_all(".") -devtools::load_all(".") -fit <- hystar_fit(y = s$data$y, z = s$data$z, -r = matrix(c(-.3, -.3, --.2, -.2), nrow = 2, byrow = TRUE), -d = 0, p0 = 1, p1 = 1, tar = TRUE) -fit2 <- hystar_fit(y = s$data$y, z = s$data$z, -d = 0, p0 = 1, p1 = 1, tar = FALSE) -fit -summary(fit) -devtools::load_all(".") -summary(fit) -fit2 <- hystar_fit(y = s$data$y, z = s$data$z, -d = 0, p0 = 1, p1 = 1, tar = FALSE) -summary(fit) -summary(fit2) -devtools::load_all(".") -summary(fit2) -coef(fit) -devtools::load_all(".") -plot(fit) -plot(fit2) -check() -hystar_sim(z = 1:10, r = c(2, 2), d = 1, -phi_R0 = 1, phi_R1 = 2 -) -s -s <- hystar_sim(z = z, r = c(-.5, .5), d = 0, -phi_R0 = c(0, .5), phi_R1 = c(2, -.3)) -plot(s) -summary(s) -s <- hystar_sim(z = z, r = c(-.5, -.5), d = 0, -phi_R0 = c(0, .5), phi_R1 = c(2, -.3)) -devtools::load_all(".") -s -s <- hystar_sim(z = z, r = c(-.5, -.5), d = 0, -phi_R0 = c(0, .5), phi_R1 = c(2, -.3)) -plot(s) -s -test() -test_coverage() -check() -install() -plot(s, main = "lalala") -plot(s, main = "lalala") -plot(s) -devtools::load_all(".") -library(devtools) -devtools::load_all(".") -z <- z_sim(500, 3, 1) -s <- hystar_sim(z = z, r = c(-.5, -.5), d = 0, -phi_R0 = c(0, .5), phi_R1 = c(2, -.3)) -plot(s) -plot(s, main = "lalala") -devtools::load_all(".") -plot(s) -devtools::load_all(".") -plot(s) -plot(s, main = "lala") -plot(s) -devtools::load_all(".") -plot(s) -plot(s, main = "lalala") -check() -install() -library(devtools) -devtools::load_all(".") -libary(covr) -library(covr) -package_coverage() -?hystar -?hystar_fit -sysfonts::font_add_google("Zilla Slab", "pf", regular.wt = 500) -library(sysfonts) -install.packages("sysfonts") -library(devtools) -z <- z_sim(100, 4) -devtools::load_all(".") -z <- z_sim(100, 4) -s <- hystar_sim(z = z, r = c(-.5, .5), d = 0, phi_R0 = 2, phi_R1 = 1) -fit <- hystar_fit(s$data) -plot(fit) -z <- z_sim(100, 4) -s <- hystar_sim(z = z, r = c(-.5, .5), d = 0, phi_R0 = 2, phi_R1 = 1) -fit <- hystar_fit(s$data) -plot(fit) -s <- hystar_sim(z = z, r = c(-.5, .5), d = 0, phi_R0 = -1, phi_R1 = 3) -fit <- hystar_fit(s$data) -plot(fit) -head(s$data) -hystar_fit() -hystar_fit(1:100) -plot(hystar_fit(1:100)) -hystar_fit(NA) -hystar_fit("test") -hystar_fit(list(daan = 3)) -is.vector(list()) library(devtools) install() devtools::load_all(".") @@ -510,3 +394,119 @@ devtools::load_all(".") check() devtools::check() graphics.off() +library(devtools) +usethis::use_vignette("hystar") +vignette("hystar", "hystar") +devtools::load_all(".") +vignette("hystar", "hystar") +?vignette +vignette("hystar") +vignette("hystar") +vignettes("pivoting", "tidyr") +vignette("pivoting", "tidyr") +vignette("Pivoting", "tidyr") +vignette("linking", package = "pkgdown") +file.exists("CRAN-SUBMISSION") +?arima +Sys.getenv() +session_info() +knitr::opts_chunk +usethis::use_pkgdown_github_pages() +?gh_token_help +gh_token_help() +create_github_token() +usethis::use_pkgdown_github_pages() +gitcreds::gitcreds_set() +gh_token_help() +gitcreds::gitcreds_set() +usethis::use_pkgdown_github_pages() +?hystar_fit +devtools::load_all(".") +document() +devtools::load_all(".") +document() +usethis::use_logo() +usethis::use_logo(img = "hystar_logo.png") +usethis::use_logo(img = "hystar_logo.png") +devtools::load_all(".") +devtools::load_all(".") +document() +check() +check() +usethis::use_version() +library(pkgdown) +?buid_reference +?build_reference +usethis::use_news_md() +?z_sim +?hystar_sim +usethis::use_version() +?hystar_fit +devtools::load_all(".") +document() +usethis::use_readme_rmd() +usethis::use_github_action("render-rmarkdown") +knitr::opts_chunk$set( +collapse = TRUE, +comment = "#>", +fig.path = "man/figures/README-", +out.width = "100%" +) +control_variable <- z_sim(n_t = 100) +simulated_hystar_model <- hystar_sim(z = z) +knitr::opts_chunk$set( +collapse = TRUE, +comment = "#>", +fig.path = "man/figures/README-", +out.width = "100%" +) +library(hystar) +control_variable <- z_sim(n_t = 100) +simulated_hystar_model <- hystar_sim(z = z) +knitr::opts_chunk$set( +collapse = TRUE, +comment = "#>", +fig.path = "man/figures/README-", +out.width = "100%" +) +library(hystar) +control_variable <- z_sim(n_t = 100) +simulated_hystar_model <- hystar_sim(z = control_variable) +fitted_hystar_model <- hystar_fit(data = simulated_hystar_model$data) +summary(fitted_hystar_model) +package_version("hystar") +package_version() +?package_version +packageVersion("hystar") +?z_sim +devtools::load_all(".") +devtools::install_github("daandejongen/hystar") +usethis::use_coverage() +use_github_action("test-coverage") +build_readme() +test_coverage() +devtools::load_all(".") +devtools::load_all(".") +devtools::load_all(".") +document() +?session_info +?sessionInfo +sessionInfo +sessionInfo() +browseURL("https://www.r-project.org") +?hystar +?browseURL +getOption("browser") +devtools::load_all(".") +devtools::load_all(".") +devtools::load_all(".") +hystar_info() +hystar_info() +print_welcome_message() +devtools::load_all(".") +print_welcome_message() +devtools::load_all(".") +print_welcome_message() +devtools::load_all(".") +hystar_info() +print_welcome_message() diff --git a/NEWS.md b/NEWS.md index b81a6a0..4dbcff9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,7 +2,7 @@ # `hystar` 1.2.0 -* More options to customize the graphs from the `plot()`-method for R-objects of class `hystar_fit` and `hystar_sim`: +* More options to *customize* the graphs from the `plot()`-method for R-objects of class `hystar_fit` and `hystar_sim`: - the colors of the background and lines @@ -18,5 +18,5 @@ # `hystar` 1.0.0 -* First CRAN release! +* First CRAN release! 🎉 diff --git a/R/plot.R b/R/plot.R index 5591d0d..0be2d4d 100644 --- a/R/plot.R +++ b/R/plot.R @@ -49,7 +49,10 @@ plot_z <- function(hystar_object, yaxt = "n", ylab = zlab, main = main ) - axis(side = 2, at = hystar_object$thresholds, labels = hystar_object$thresholds, las = 0) + axis(side = 2, + at = round(hystar_object$thresholds, 2), + labels = hystar_object$thresholds, + las = 0) if (show_legend) plot_legend(hystar_object = hystar_object, regimes_name_color = regimes_name_color) } diff --git a/R/welcome.R b/R/welcome.R new file mode 100644 index 0000000..aecad5b --- /dev/null +++ b/R/welcome.R @@ -0,0 +1,29 @@ +print_welcome_message <- function() { +hystar_string <- " + _ _ +| | | | +| |__ _ _ ___ | |_ __ _ _ __ +| '_ \\| | | |/ __|| _| / _` || '__\\ +| | | || |_| |\\__ \\| |_ | (_| || | +|_| |_||___ ||___/ \\__| \\__,_||_| + ___| | + |____/ 1.2.0 \n\n" + +info_string <- " +Estimation and simulation of the HysTAR Model. +For function help, run `?hystar_fit`, `?hystar_sim` or `?z_sim`. +For more information, run `hystar_info()`. +" +cat(hystar_string) +cat(info_string) +} + +#' @export +#' @importFrom utils browseURL +hystar_info <- function() { + browseURL("https://daandejongen.github.io/hystar/index.html") +} + + + + diff --git a/README.Rmd b/README.Rmd index dc69ca1..0bcacbe 100644 --- a/README.Rmd +++ b/README.Rmd @@ -26,12 +26,11 @@ knitr::opts_chunk$set( The R-package [`hystar`](https://cran.r-project.org/package=hystar) package allows you to simulate and estimate the hysteretic threshold autoregressive (HysTAR) model. It comes with three functions: -* `hystar_fit`, to estimate the HysTAR parameters with the conditional least -squares method, +* `hystar_fit`, to *estimate* the HysTAR parameters with the *conditional least squares* method, -* `z_sim`, to simulate a threshold variable, +* `z_sim`, to simulate a *threshold variable*, -* `hystar_sim`, to simulate an outcome variable. +* `hystar_sim`, to simulate an *outcome variable*. Results from the time series analysis can be assessed with the standard methods in R, like `plot`, `summary` and `print`. Additionally, you can extract the predictive residuals with the `residuals`-method for further analysis. diff --git a/README.md b/README.md index 6ecab48..ca9fd41 100644 --- a/README.md +++ b/README.md @@ -18,12 +18,12 @@ The R-package [`hystar`](https://cran.r-project.org/package=hystar) package allows you to simulate and estimate the hysteretic threshold autoregressive (HysTAR) model. It comes with three functions: -- `hystar_fit`, to estimate the HysTAR parameters with the conditional - least squares method, +- `hystar_fit`, to *estimate* the HysTAR parameters with the + *conditional least squares* method, -- `z_sim`, to simulate a threshold variable, +- `z_sim`, to simulate a *threshold variable*, -- `hystar_sim`, to simulate an outcome variable. +- `hystar_sim`, to simulate an *outcome variable*. Results from the time series analysis can be assessed with the standard methods in R, like `plot`, `summary` and `print`. Additionally, you can @@ -41,34 +41,34 @@ simulated_hystar_model <- hystar_sim(z = control_variable) fitted_hystar_model <- hystar_fit(data = simulated_hystar_model$data) summary(fitted_hystar_model) #> HysTAR model fitted on 99 observations, of which -#> 49 observations in regime 0 and -#> 50 observations in regime 1. +#> 44 observations in regime 0 and +#> 55 observations in regime 1. #> #> Estimated thresholds: #> r0 r1 -#> -0.509 0.509 +#> -0.509 0.218 #> #> Estimated delay: #> 0 #> #> Estimated model coefficients: #> est SE p -#> phi_00 -0.123 0.104 0.238 -#> phi_01 0.358 0.096 0.000 -#> phi_10 1.996 0.396 0.000 -#> phi_11 0.478 0.104 0.000 +#> phi_00 -0.153 0.131 0.244 +#> phi_01 0.507 0.111 0.000 +#> phi_10 1.312 0.325 0.000 +#> phi_11 0.612 0.092 0.000 #> #> Estimated residual variances: #> sigma2_0 sigma2_1 -#> 0.534 0.900 +#> 0.751 1.073 #> #> Residuals: #> min 1q median 3q max -#> -1.837 -0.562 -0.083 0.512 2.059 +#> -2.359 -0.803 -0.009 0.633 2.250 #> #> Information criteria: #> aic aicc bic -#> -23.98109 -22.92602 -12.56956 +#> 3.236331 4.306919 14.610899 ``` ## Install