Skip to content

Commit

Permalink
new default for p_select
Browse files Browse the repository at this point in the history
  • Loading branch information
Daan de Jong committed Nov 30, 2023
1 parent 787c48c commit 39fa507
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 164 deletions.
280 changes: 140 additions & 140 deletions .Rhistory
Original file line number Diff line number Diff line change
@@ -1,143 +1,3 @@
library(devtools)
install()
devtools::load_all(".")
devtools::document()
?binom
?rbinom
1-250*999/1000
1-(250*999/1000)
250*999/1000
1-(250**(999/1000))
1-(250^(999/1000))
250^(999/1000)
999/1000
250^.999
.999*.999
1 - .999 ^ 250
citation(package = "hystar")
qnorm(.975, mean = 0, sd = 1)
usethis::use_pkgdown()
pkgdown::build_site()
packageVersion("hystar")
usethis::use_version()
devtools::load_all(".")
?hystar_fit
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)
devtools::load_all(".")
fit <- hystar_fit(sim$data)
head(sim$data)
plot(sim)
fit <- hystar_fit(sim$data)
devtools::load_all(".")
fit <- hystar_fit(sim$data)
fit$st_errors
devtools::load_all(".")
fit <- hystar_fit(sim$data)
fit$st_errors
devtools::load_all(".")
fit <- hystar_fit(sim$data)
fit$st_errors
confint(fit)
coef(fit)
usethis::use_version()
?do.call
check()
devtools::check()
devtools::load_all(".")
fit
fit$tar
?mapply
?identity
devtools::load_all(".")
y <- rnorm(100)
R <- c(rep(0, 50), rep(1, 50)
)
rv <- c(1, 1)
X <- matrix(c(rep(1, 99), y[1:99]), ncol = 2)
solve(t(X) %*% X)
X <- cbind(matrix(c(rep(1, 99), y[1:99]), ncol = 2) * (1-R), matrix(c(rep(1, 99), y[1:99]), ncol = 2) * R)
matrix(c(rep(1, 99), y[1:99]), ncol = 2)
matrix(c(rep(1, 99), y[1:99]), ncol = 2) * R
R <- matrix(c(rep(0, 50), rep(1, 50)), ncol = 2)
R
R <- matrix(c(rep(0, 50), rep(1, 50)), ncol = 2, nrow = 100)
R
X <- cbind(matrix(c(rep(1, 99), y[1:99]), ncol = 2) * (1-R), matrix(c(rep(1, 99), y[1:99]), ncol = 2) * R)
1_r
1-R
R <- matrix(c(rep(0, 49), rep(1, 50)), ncol = 2, nrow = 9)
R <- matrix(c(rep(0, 49), rep(1, 50)), ncol = 2, nrow = 99)
X <- cbind(matrix(c(rep(1, 99), y[1:99]), ncol = 2) * (1-R), matrix(c(rep(1, 99), y[1:99]), ncol = 2) * R)
X
solve(t(X) %*% X)
create_acov_mat(rnorm(100))
create_acov_mat(1:5, 1:100)
acf(y)
y
plot(y)
acf(y)
?acf
acf(y, plot = FALSE)
compute_acov_vec(y, 10)
acf(y, plot = FALSE, type = "cov")
create_acov_mat(compute_acov_vec(y, 10))
create_acov_mat(compute_acov_vec(y, 10), y)
create_acov_mat(compute_acov_vec(y, 3), y)
mean(y)
var(y)
var(y)
var(matrix(c(y, y), ncol = 2))
var(matrix(c(y[2:100], y[1:99]), ncol = 2))
devtools::load_all(".")
check()
devtools::check()
devtools::load_all(".")
devtools::load_all(".")
check()
library(devtools)
check()
?hystar_fit
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)
fit$st_errors
fit <- hystar_fit(sim$data, p0 = 2)
fit$st_errors
fit$eff
str(fit)
devtools::load_all(".")
compute_p_values(fit$coefficients, fit$st_errors)
devtools::load_all(".")
check()
devtools::load_all(".")
document()
check()
licence()
print
is.generic(print)
is.function(print)
class(print)
class(hystar.print)
class(print.hystar_fit)
devtools::load_all(".")
class(print.hystar_fit)
?UseMethod
plot
?hystar_fit
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)
plot(sim)
fit <- hystar_fit(sim$data)
summary(fit)
plot(fit, regime_names = c("a", "b"))
devtools::load_all(".")
warnings()
plot(fit, xlab = "test")
devtools::load_all(".")
plot(fit, xlab = "test")
plot(fit, xlab = "test", regime_names = NULL)
plot(fit_hystar,
main = "Depression time series from a network model",
xlab = "time",
Expand Down Expand Up @@ -510,3 +370,143 @@ print_welcome_message()
devtools::load_all(".")
hystar_info()
print_welcome_message()
library(devtools)
devtools::load_all(".")
print_welcome_message()
hystar_info()
devtools::load_all(".")
plot(hystar_sim(z_sim()))
?packageStartupMessage
devtools::load_all(".")
devtools::load_all(".")
hystar_info()
devtools::load_all(".")
?hystar_fit
?message
?Sys.sleep
devtools::load_all(".")
hystar_fit(hystar_sim(z_sim())$data, d = 1:10)
hystar_fit(hystar_sim(z_sim())$data, d = 1:5)
hystar_fit(hystar_sim(z_sim())$data, d = 1:5)
hystar_fit(hystar_sim(z_sim())$data, d = 1:10)
hystar_fit(hystar_sim(z_sim())$data, d = 1:10)
hystar_fit(hystar_sim(z_sim())$data, d = 1:6)
hystar_fit(hystar_sim(z_sim())$data, d = 1:7)
hystar_fit(hystar_sim(z_sim())$data, d = 1:8)
hystar_fit(hystar_sim(z_sim())$data, d = 1:9)
hystar_fit(hystar_sim(z_sim())$data, d = 1:10)
hystar_fit(hystar_sim(z_sim())$data, d = 1:11)
time_eff(1:100, 10, 2, 2)
create_x(hystar_sim(z_sim())$data$y, time_eff(1:100, 10, 2, 2), 1, 1)
hystar_fit(hystar_sim(z_sim())$data, p0 = 1:10)
hystar_fit(hystar_sim(z_sim())$data, p0 = 1:9)
hystar_fit(hystar_sim(z_sim())$data, p0 = 1:8)
hystar_fit(hystar_sim(z_sim())$data, p0 = 1:7)
hystar_fit(hystar_sim(z_sim())$data, p0 = 1:6)
hystar_fit(hystar_sim(z_sim())$data, p0 = 1:5)
hystar_fit(hystar_sim(z_sim(200))$data, p0 = 1:6)
hystar_fit(hystar_sim(z_sim(500))$data, d = 1:11)
hystar_fit(hystar_sim(z_sim(50))$data, p0 = 1:6)
?try
Inf
Inf >1000
hystar_fit(hystar_sim(z_sim(50))$data, p0 = 1:)
hystar_fit(hystar_sim(z_sim(50))$data, p0 = 1:7)
devtools::load_all(".")
hystar_fit(hystar_sim(z_sim(50))$data, p0 = 1:7)
devtools::load_all(".")
hystar_fit(hystar_sim(z_sim(50))$data, p0 = 1:7)
(1)[ , 1, drop = TRUE]
devtools::load_all(".")
hystar_fit(hystar_sim(z_sim(50))$data, p0 = 1:7)
devtools::load_all(".")
hystar_fit(hystar_sim(z_sim(50))$data, p0 = 1:7)
?withCallingHandlers
devtools::load_all(".")
hystar_fit(hystar_sim(z_sim(50))$data, p0 = 1:7)
devtools::load_all(".")
hystar_fit(hystar_sim(z_sim(50))$data, p0 = 1:7)
devtools::load_all(".")
hystar_fit(hystar_sim(z_sim(150))$data, d = 1:6)
?message
devtools::load_all(".")
hystar_fit(hystar_sim(z_sim(150))$data, d = 1:6)
devtools::load_all(".")
hystar_fit(hystar_sim(z_sim(150))$data, d = 1:6)
devtools::load_all(".")
hystar_fit(hystar_sim(z_sim(150))$data, d = 1:6)
devtools::load_all(".")
hystar_fit(hystar_sim(z_sim(150))$data, d = 1:6)
devtools::load_all(".")
hystar_fit(hystar_sim(z_sim(150))$data, d = 1:6)
hystar_fit(hystar_sim(z_sim(150))$data, d = 1:6)
?txtProgressBar
txtProgressBar
devtools::load_all(".")
hystar_fit(hystar_sim(z_sim(150))$data, d = 1:6)
devtools::load_all(".")
devtools::load_all(".")
hystar_fit(hystar_sim(z_sim(150))$data, d = 1:6)
hystar_fit(hystar_sim(z_sim(150))$data, p0 = 1:5, p1 = 1:5)
hystar_fit(hystar_sim(z_sim(500))$data, p0 = 1:2, p1 = 1:2)
devtools::load_all(".")
hystar_fit(hystar_sim(z_sim(200))$data, p1 = 1:2)
stringi::stri_escape_unicode(🎉)
stringi::stri_escape_unicode("🎉")
document()
devtools::load_all(".")
devtools::load_all(".")
devtools::load_all(".")
devtools::load_all(".")
devtools::load_all(".")
devtools::load_all(".")
devtools::load_all(".")
devtools::load_all(".")
devtools::load_all(".")
devtools::load_all(".")
devtools::load_all(".")
devtools::load_all(".")
check(
)
devtools::load_all(".")
"
__ __
/ /_ __ ______/ /_________
/ _ / // (_ -/ _/ _ / __\
/_//_/\_, /___)\__/\_,_/_/
devtools::load_all(".")
devtools::load_all(".")
devtools::load_all(".")
hystar_fit(hystar_sim(z_sim())$data)
hystar_fit(hystar_sim(z_sim(300))$data, d = 3)
hystar_fit(hystar_sim(z_sim(300))$data, d = 1:3)
?hystar
hystar_fit(hystar_sim(z_sim(300))$data, d = 1:3)$ic
devtools::load_all(".")
hystar_fit(hystar_sim(z_sim(50))$data, d = 1:3)$ic
devtools::load_all(".")
hystar_fit(hystar_sim(z_sim(50))$data, d = 1:3)$ic
devtools::load_all(".")
hystar_fit(hystar_sim(z_sim(50))$data, d = 1:3)$ic
check()
devtools::load_all(".")
hystar_fit(hystar_sim(z_sim())$data)
devtools::load_all(".")
hystar_fit(hystar_sim(z_sim())$data)
devtools::load_all(".")
?invisible
test()
check()
document()
?hystar_info
?hystar
devtools::load_all(".")
check()
check()
hystar_fit(hystar_sim(z_sim()$data)
)
hystar_fit(hystar_sim(z_sim())$data)
devtools::load_all(".")
hystar_fit(hystar_sim(z_sim())$data)
hystar_fit(hystar_sim(z_sim())$data)$ic
usethis::use_version()
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# `hystar` 1.2.1.9000 (development version)

* Default argument for `p_select` in `hystar_fit()` now shows all four options. The new default is `p_select = c("bic", "aic", "aicc", "aiccp")`, and the first option `"bic"` is taken when the user doesn't provide the argument.

# `hystar` 1.2.1

* Added a welcome message with a logo and first directions for help.
Expand Down
5 changes: 3 additions & 2 deletions R/checks_fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ check_data <- function(data) {
"You provided an object of class ", class(data)),
call. = FALSE)

data <- data[, c(1, 2)]
data <- data[, c(1, 2), drop = FALSE]

if (!is.numeric(data)) error_numeric(data)

Expand Down Expand Up @@ -97,11 +97,12 @@ check_rz <- function(r, z) {
}

check_p_select <- function(p_select) {
if (length(p_select) > 1) p_select <- p_select[1]
if (!is.character(p_select))
stop(paste0("`p_select` must be of type character."),
call. = FALSE)
p_select <- tolower(p_select)
choices <- c("aic", "aicc", "bic")
choices <- c("aic", "aicc", "bic", "aiccp")
p_select <- tryCatch(
error = function(cond) {
stop(paste0("'p_select' must be one of these: ",
Expand Down
13 changes: 10 additions & 3 deletions R/hystar_fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@
#' equal to `p0`.
#' @param p_select The information criterion that should be minimized to select
#' the orders \eqn{p_0} and \eqn{p_1}. Choices:
#' * `"bic"` (default, Bayesian Information Criterion)
#' * `"aic"` (Akaike Information Criterion)
#' * `"aicc"` (Corrected Akaike Information Criterion)
#' * `"bic"` (default, Bayesian Information Criterion)
#' * `"aiccp"` (Change-point Akaike Information Criterion)
#' @param thin `TRUE` (default) or `FALSE`. Only relevant when `r` is a vector.
#' * If `TRUE` (default), the search space for the thresholds are the
#' \eqn{100a\%, 100(a+0.01)\%, \dots, 100b\%} percentiles of `z`.
Expand Down Expand Up @@ -101,15 +102,21 @@
#' * `nobs()`
#'
#' @export
hystar_fit <- function(data, r = c(.1, .9), d = 0L, p0 = 1L, p1 = 1L, p_select = "bic",
thin = FALSE, tar = FALSE) {
hystar_fit <- function(data,
r = c(.1, .9),
d = 0L,
p0 = 1L, p1 = 1L,
p_select = c("bic", "aic", "aicc", "aiccp"),
thin = FALSE,
tar = FALSE) {
check_data(data)
if (is.vector(data)) {
y <- z <- data
} else {
y <- data[, 1]
z <- data[, 2]
}

p_select <- check_hystar_fit_input(z, d, p0, p1, p_select, r, thin, tar)
eff <- time_eff(y, max(d), max(p0), max(p1))
x <- create_x(y, eff, max(p0), max(p1))
Expand Down
3 changes: 2 additions & 1 deletion R/hystar_sim.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ hystar_sim <- function(z,
d = 0,
phi_R0 = c(0, .5),
phi_R1 = c(2, .5),
resvar = c(1, 1), start_regime = NULL) {
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
Loading

0 comments on commit 39fa507

Please sign in to comment.