Skip to content

Commit 65cb02a

Browse files
committed
re-name function
fix minor things
1 parent e5874d2 commit 65cb02a

File tree

9 files changed

+26
-13
lines changed

9 files changed

+26
-13
lines changed

.sandbox/benchmarking.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
library(dynamichazard); library(testthat); library(survival)
22

3-
test_sim_func_logit <- asNamespace("dynamichazard")$test_sim_func_logit
3+
test_sim_func_logit <- dynamichazard:::test_sim_func_logit
44

55
set.seed(599479)
66

.sandbox/profile.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
library(dynamichazard);
22
library(survival);
3-
test_sim_func_logit <- asNamespace("dynamichazard")$test_sim_func_logit
3+
test_sim_func_logit <- dynamichazard:::test_sim_func_logit
44

55
set.seed(9997)
66
sims <- test_sim_func_logit(n_series = 1e5, n_vars = 10, t_0 = 0, t_max = 10,

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: dynamichazard
22
Type: Package
33
Title: Dynamic Hazard Models using State Space Models
4-
Version: 0.6.1
4+
Version: 0.6.2
55
Authors@R: c(person("Benjamin", "Christoffersen",
66
email = "boennecd@gmail.com",
77
role = c("cre", "aut")),

R/sims.R

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,21 @@ test_sim_func_logit <- function(
134134
re_draw = T, beta_start = 3, intercept_start,
135135
sds = rep(1, n_vars + !missing(intercept_start)),
136136
is_fixed = c(), lambda = 1,
137-
tstart_sampl_func = function(t_0 = t_0, t_max = t_max)
138-
t_0,
139-
betas, linkfunc = "logit"){
137+
tstart_sampl_func = function(t_0 = t_0, t_max = t_max) t_0, betas){
138+
cl <- match.call()
139+
cl[["linkfunc"]] <- "logit"
140+
cl[[1L]] <- bquote(
141+
environment(.(cl[[1L]]))$test_sim_func_discrete)
142+
eval(cl, parent.frame())
143+
}
144+
145+
test_sim_func_discrete <- function(
146+
n_series, n_vars = 10L, t_0 = 0L, t_max = 10L, x_range = .1, x_mean = -.1,
147+
re_draw = T, beta_start = 3, intercept_start,
148+
sds = rep(1, n_vars + !missing(intercept_start)),
149+
is_fixed = c(), lambda = 1,
150+
tstart_sampl_func = function(t_0 = t_0, t_max = t_max) t_0, betas,
151+
linkfunc){
140152
# make output matrix
141153
n_row_max <- n_row_inc <- 10^5
142154
res <- matrix(NA_real_, nrow = n_row_inc, ncol = 4 + n_vars,

inst/shiny/app.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ if(!require(shiny))
33
stop("Requires 'shiny' to run the demo")
44

55
test_sim_func_exp <- dynamichazard:::test_sim_func_exp
6-
test_sim_func_logit <- dynamichazard:::test_sim_func_logit
76
exp_model_names <- dynamichazard:::exp_model_names
87

98
# Global params
@@ -359,7 +358,7 @@ server <- function(input, output) {
359358

360359
sim_input <- reactive({
361360
f_choice <- if(input$sim_with == "exponential")
362-
quote(test_sim_func_exp) else quote(test_sim_func_logit)
361+
quote(test_sim_func_exp) else quote(test_sim_func_discrete)
363362

364363
n_fixed <- if(input$sim_fix_options == 1)
365364
0 else if(input$sim_fix_options == 2)
@@ -384,6 +383,8 @@ server <- function(input, output) {
384383
tstart_sampl_func = .(start_fun)))
385384
if(input$sim_with == "cloglog")
386385
sim_quote[["linkfunc"]] <- "cloglog"
386+
else if(input$sim_with == "logit")
387+
sim_quote[["linkfunc"]] <- "logit"
387388

388389
sim_exp <- bquote({
389390
set.seed(.(input$seed))

speedtest/speedtest.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ matplot(fit$state_vecs, type = "l", lty = 2, add = TRUE)
2424

2525
```{r func_setup}
2626
sim_func <- function(n, p){
27-
func <- asNamespace("dynamichazard")$test_sim_func_logit
27+
func <- dynamichazard:::test_sim_func_logit
2828
set.seed(101)
2929
t_max <- 30L
3030
func(n_series = n, n_vars = p, t_max = t_max, x_range = 1, x_mean = 0,

tests/testthat/helper.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ bigqr.init <- asNamespace("biglm")$bigqr.init
198198
# Simulated data sets to test against
199199
set.seed(6790753)
200200

201-
test_sim_func_logit <- asNamespace("dynamichazard")$test_sim_func_logit
201+
test_sim_func_logit <- dynamichazard:::test_sim_func_logit
202202
get_sim <- function(n)
203203
test_sim_func_logit(n_series = n, n_vars = 10, t_0 = 0, t_max = 10,
204204
x_range = 1, x_mean = 0, re_draw = T, beta_start = rnorm(10),

tests/testthat/test_cloglog.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
context("testing cloglog link function")
22

33
set.seed(57826639)
4-
dat <- test_sim_func_logit(
4+
dat <- test_sim_func_discrete(
55
n_series = 400, n_vars = 2, t_0 = 0, t_max = 30,
66
x_range = 1, x_mean = 0, re_draw = T, beta_start = rnorm(2),
77
is_fixed = 2,

vignettes/Comparing_methods_for_logistic_models.Rmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ csl: bib_style.csl
1212
vignette: >
1313
%\VignetteIndexEntry{Comparing methods for time varying logistic models}
1414
%\VignetteEngine{knitr::rmarkdown}
15-
\usepackage[utf8]{inputenc}
15+
%\VignetteEncoding{UTF-8}
1616
---
1717

1818
```{r setup, include=FALSE}
@@ -48,7 +48,7 @@ knitr::opts_knit$set(warning = F, message = F)
4848
\newcommand{\mat}[1]{\mathbf{#1}}
4949

5050
# Introduction
51-
In this vignette, we compare the dynamic logistic model in `dynamichazard` with others methods within the package and methods from the `timereg` and `mgcv` packages. Further this note will serve as an illustration of how to use the `ddhazard` function for the logistic model. We will use the `pbc2` dataset from the `survival` package. The motivation is that the `pbc2` data set is commonly used in survival analysis for illustrations. It is suggested to first read or skim `vignette("ddhazard", "dynamichazard")` to get an introduction to the models and estimation methods in this package.
51+
In this vignette, we compare the dynamic logistic model in `dynamichazard` with other methods within the package and methods from the `timereg` and `mgcv` packages. Further this note will serve as an illustration of how to use the `ddhazard` function for the logistic model. We will use the `pbc2` dataset from the `survival` package. The motivation is that the `pbc2` data set is commonly used in survival analysis for illustrations. It is suggested to first read or skim `vignette("ddhazard", "dynamichazard")` to get an introduction to the models and estimation methods in this package.
5252

5353
The note is structured as follows: First, we cover the `pbc2` data set. Then we estimate two static (non-dynamic) logistic regression models using `glm`. This is followed by a fit using a Generalized Additive model with the `gam` function in the `mgcv` package. Next, we will estimate a cox-model with time varying parameters using the `timecox` function in the `timereg` package. Finally, we will end by illustrating the methods in this package for time varying parameters in a logistic regression.
5454

0 commit comments

Comments
 (0)