Skip to content

Commit

Permalink
more default arguments in simulation functions
Browse files Browse the repository at this point in the history
updated examples accordingly
  • Loading branch information
Daan de Jong committed Nov 23, 2023
1 parent 3c19ced commit c2ab2ac
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 24 deletions.
13 changes: 9 additions & 4 deletions R/hystar_sim.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,15 @@
#' @export
#'
#' @examples
#' z <- z_sim(n_t = 200, n_switches = 5, start_regime = 1)
#' sim <- hystar_sim(z = z, r = c(-.5, .5), d = 2, phi_R0 = c(0, .6), phi_R1 = 1)
#' fit <- hystar_fit(sim$data)
hystar_sim <- function(z, r, d, phi_R0, phi_R1, resvar = c(1, 1), start_regime = NULL) {
#' simulated_control_variable <- z_sim()
#' simulated_hystar_model <- hystar_sim(simulated_control_variable)
#' fitted_hystar_model <- hystar_fit(simulated_hystar$data)
hystar_sim <- function(z,
r = c(-0.5, 0.5),
d = 0,
phi_R0 = c(0, .5),
phi_R1 = c(2, .5),
resvar = c(1, 1), start_regime = NULL) {

temp <- check_hystar_sim_input(z, r, d, phi_R0, phi_R1, resvar, start_regime)
z <- temp$z
Expand Down
3 changes: 2 additions & 1 deletion R/simulate.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
#' @export
#'
#' @inherit hystar_sim examples
z_sim <- function(n_t, n_switches,
z_sim <- function(n_t = 100,
n_switches = 2,
start_regime = 0, start_hyst = FALSE,
range = c(-1, 1)) {

Expand Down
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,32 @@ The hystar package also has a `plot()` method that combines the
threshold and outcome variable in one figure and visualizes the regimes and
thresholds.

## Install
You can install the `hystar`-package via CRAN by running:
`install.packages("hystar")`
## Installation

`install.packages("hystar")` for the CRAN version.

`devtools::install_github("daandejongen/hystar")` for the development version.

## Use
```
z <- z_sim(n_t = 200, n_switches = 5)
sim <- hystar_sim(z = z, r = c(-.5, .5), d = 2, phi_R0 = c(0, .6), phi_R1 = 1)
fit <- hystar_fit(sim$data)
control_variable <- z_sim()
simulated_hystar_model <- hystar_sim(z = z)
fitted_hystar_model <- hystar_fit(simulated_hystar_model$data)
```

## Cite

If you have used this package for an academic publication, please cite it with:

De Jong, D. (2022). _hystar: Simulation and Estimation of the Hysteretic TAR Model_. R package version 0.0.9, <https://github.com/daandejongen/hystar/>.
De Jong, D. (2022). _hystar: Simulation and Estimation of the Hysteretic TAR Model_. R package version 1.0.0, <https://github.com/daandejongen/hystar/>.

BibTeX:
```
@Manual{,
title = {hystar: Simulation and Estimation of the Hysteretic TAR Model},
author = {Daan {de Jong}},
year = {2022},
note = {R package version 0.0.9},
note = {R package version 1.0.0},
url = {https://github.com/daandejongen/hystar/},
}
```
Expand Down
2 changes: 2 additions & 0 deletions man/hystar-package.Rd

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

6 changes: 3 additions & 3 deletions man/hystar_fit.Rd

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

16 changes: 12 additions & 4 deletions man/hystar_sim.Rd

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

14 changes: 10 additions & 4 deletions man/z_sim.Rd

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

0 comments on commit c2ab2ac

Please sign in to comment.