Giter VIP home page Giter VIP logo

reda's Introduction

reda

CRAN_Status_Badge Build Status codecov

Overview

The R package reda provides functions for

  • simulating survival, recurrent event, and multiple event data from stochastic process point of view;
  • exploring and modeling recurrent event data through the mean cumulative function (MCF) by the Nelson-Aalen estimator of the cumulative hazard rate function, and gamma frailty model with spline rate function;
  • comparing two-sample recurrent event responses with the pseudo-score tests.

Installation of CRAN Version

You can install the released version from CRAN.

install.packages("reda")

Development

The latest version of the package is under development at GitHub. If it is able to pass the automated package checks, one may install it by

if (! require(remotes)) install.packages("remotes")
remotes::install_github("wenjie2wang/reda", upgrade = "never")

Getting Started

Online documentation provides function documentations and includes package vignettes for

License

GNU General Public License (ā‰„ 3)

reda's People

Contributors

jun-yan avatar stc04003 avatar wenjie2wang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

reda's Issues

How to get frailty effect from simEventData()?

Question

Received the following question from email:

Iā€™m simulating recurrent survival data and I am using log-normal frailties. I want the frailties used in the simulation to appear in the data, so that I can see how well my model estimates the frailties. Right now the simulation looks like this:

nProcess <- 300
rho_weibull_ph <- function(x, lambda, p) lambda * p * x ^ (p - 1)
df=simEventData(z = cbind(rbinom(nProcess, 1, 0.5)),
                zCoef = c(0.5),frailty = stats::rlnorm, endTime = rnorm(nProcess, 10),
                recurrent = TRUE, rho = rho_weibull_ph,
                arguments = list(rho = list(lambda = 0.001, p = 1),frailty = list(sdlog = 0.25)))

My question is how can we get the frailties used in the simulation to be a column in the dataset?

Possible Workaround

The frailty effect is saved in the simEvent object. Therefore, a simple wrapper function is needed to use simEvent() instead
of using simEventData(). For instance,

library(reda)
set.seed(123)
nProcess <- 300
rho_weibull_ph <- function(x, lambda, p) lambda * p * x ^ (p - 1)
dat <- do.call(rbind, lapply(seq_len(nProcess), function(i) {
    obj <- simEvent(z = rbinom(1, 1, 0.5), zCoef = 0.5,
                    rho = rho_weibull_ph, frailty = stats::rlnorm,
                    arguments = list(rho = list(lambda = 0.2, p = 1),
                                     frailty = list(sdlog = 0.25)))
    out <- reda:::simEvent2data(i, obj)
    out$frailty <- obj@frailty$frailty
    out
}))
head(dat, 10)
##    ID      time event origin X  frailty
## 1   1 0.1292489     1      0 0 1.221572
## 2   1 0.3593253     1      0 0 1.221572
## 3   1 1.6547921     1      0 0 1.221572
## 4   1 2.9409516     1      0 0 1.221572
## 5   1 3.0000000     0      0 0 1.221572
## 6   2 1.2635873     1      0 0 1.525842
## 7   2 2.1844353     1      0 0 1.525842
## 8   2 3.0000000     0      0 0 1.525842
## 9   3 1.2199754     1      0 0 1.563189
## 10  3 3.0000000     0      0 0 1.563189

Turn off confidence calculation

Dear Wenjie:

First, I would like to let you know this is a great package. I am working on a project to calculate a large number of mcf. It is very slow due the number of mcf calculations. I believe the confidence interval is more time consuming than mcf. Is there a way I can turn off the confidence interval calculation.

Thanks,

Sincerely yours,

Bug in simEventData

Hi,

I think there is a bug in simEventData. I used the following function to generate recurrent event with time-variant covariate. zt is a vector of length 553, which is attached.
zt.csv

AT<-function(time,zt) zt[pmax(0,floor(time-100))+1]
zfun<-function(time,zt,Z2) cbind(AT(time,zt),Z2) ## time-variant covariate vector
x=simEventData(z = zfun, zCoef = c(0.1,2),origin=0,endTime=length(zt),arguments = list(z = list(zt=zt,Z2=1)),rho=0.001)

With the above codes, I get the following results:

x
ID time event origin X.1 X.2
1 1 26.28915 1 0 100.00000 1
2 1 72.58110 1 0 100.00000 1
3 1 97.80675 1 0 100.00000 1
4 1 139.48710 1 0 14.96476 1
5 1 148.87831 1 0 12.75497 1
6 1 171.86007 1 0 11.22835 1
7 1 204.00038 1 0 9.49048 1
8 1 212.41692 1 0 9.10000 1
9 1 216.82910 1 0 9.70141 1
10 1 239.12504 1 0 9.49023 1
11 1 298.58581 1 0 9.37119 1
12 1 448.02677 1 0 28.17732 1
13 1 453.27768 1 0 30.40548 1
14 1 454.55875 1 0 30.87229 1
15 1 465.77483 1 0 36.38604 1
16 1 553.00000 0 0 87.94848 1

However, when I concatenate a vector of 10 to zt as follows, simEventData generate a lot of events. Since the time-variant covariate values did not change for the time period 0 to 553, so many events in this time period does not make sense.

zt=c(zt,rep(10,533))
x=simEventData(z = zfun, zCoef = c(0.1,2),origin=0,endTime=length(zt),arguments = list(z = list(zt=zt,Z2=1)),rho=0.001)

x
ID time event origin X.1 X.2
1 1 0.006242786 1 0 100 1
2 1 0.006839542 1 0 100 1
3 1 0.017938353 1 0 100 1
4 1 0.028651440 1 0 100 1
5 1 0.033637245 1 0 100 1
6 1 0.046612646 1 0 100 1
7 1 0.051124358 1 0 100 1
8 1 0.052338844 1 0 100 1
9 1 0.063594936 1 0 100 1
10 1 0.067455526 1 0 100 1
11 1 0.083278221 1 0 100 1
12 1 0.083860555 1 0 100 1
13 1 0.092751879 1 0 100 1
14 1 0.092862057 1 0 100 1
15 1 0.096591501 1 0 100 1
16 1 0.106756317 1 0 100 1
17 1 0.109465642 1 0 100 1
18 1 0.118664398 1 0 100 1
19 1 0.118995341 1 0 100 1
20 1 0.129560419 1 0 100 1
21 1 0.140414691 1 0 100 1
22 1 0.144648840 1 0 100 1
23 1 0.152500856 1 0 100 1
24 1 0.153273102 1 0 100 1
25 1 0.156321097 1 0 100 1
26 1 0.174974314 1 0 100 1
27 1 0.180033237 1 0 100 1
28 1 0.186355416 1 0 100 1
29 1 0.191305847 1 0 100 1
30 1 0.200493667 1 0 100 1
31 1 0.203004847 1 0 100 1
32 1 0.203831227 1 0 100 1
33 1 0.213427058 1 0 100 1
34 1 0.219884156 1 0 100 1
35 1 0.226711902 1 0 100 1
36 1 0.238861370 1 0 100 1
37 1 0.248352938 1 0 100 1
38 1 0.249743697 1 0 100 1
39 1 0.251025185 1 0 100 1
40 1 0.259059073 1 0 100 1
41 1 0.260553979 1 0 100 1
42 1 0.265022980 1 0 100 1
43 1 0.265408599 1 0 100 1
44 1 0.266536777 1 0 100 1
45 1 0.268670326 1 0 100 1
46 1 0.292304101 1 0 100 1
47 1 0.302883653 1 0 100 1
48 1 0.303276499 1 0 100 1
49 1 0.306170839 1 0 100 1
50 1 0.312236723 1 0 100 1
51 1 0.313719985 1 0 100 1
52 1 0.317544096 1 0 100 1
53 1 0.320767841 1 0 100 1
54 1 0.323275411 1 0 100 1
55 1 0.335794068 1 0 100 1
56 1 0.336983959 1 0 100 1
57 1 0.344310057 1 0 100 1
58 1 0.349678224 1 0 100 1
59 1 0.360598594 1 0 100 1
60 1 0.372449873 1 0 100 1
61 1 0.378575765 1 0 100 1
62 1 0.392175993 1 0 100 1
63 1 0.394257982 1 0 100 1
64 1 0.395818677 1 0 100 1
65 1 0.397277389 1 0 100 1
66 1 0.408018247 1 0 100 1
67 1 0.413464217 1 0 100 1
68 1 0.417847208 1 0 100 1
69 1 0.427381956 1 0 100 1
70 1 0.458754522 1 0 100 1
71 1 0.460189161 1 0 100 1
72 1 0.467391060 1 0 100 1
73 1 0.474431766 1 0 100 1
74 1 0.482510073 1 0 100 1
75 1 0.495227621 1 0 100 1
76 1 0.497469003 1 0 100 1
77 1 0.497635925 1 0 100 1
78 1 0.508283200 1 0 100 1
79 1 0.509404770 1 0 100 1
80 1 0.511629727 1 0 100 1
81 1 0.513421083 1 0 100 1
82 1 0.519522748 1 0 100 1
83 1 0.527497089 1 0 100 1
84 1 0.529607839 1 0 100 1
85 1 0.543771408 1 0 100 1
86 1 0.544726510 1 0 100 1
87 1 0.546149712 1 0 100 1
88 1 0.549375325 1 0 100 1
89 1 0.551445292 1 0 100 1
90 1 0.555493815 1 0 100 1
91 1 0.563718817 1 0 100 1
92 1 0.567767155 1 0 100 1
93 1 0.577351468 1 0 100 1
94 1 0.581826004 1 0 100 1
95 1 0.584861912 1 0 100 1
96 1 0.587809261 1 0 100 1
97 1 0.589983361 1 0 100 1
98 1 0.597754619 1 0 100 1
99 1 0.600915567 1 0 100 1
100 1 0.600990019 1 0 100 1
101 1 0.603297320 1 0 100 1
102 1 0.605375022 1 0 100 1
103 1 0.614614531 1 0 100 1
104 1 0.619029684 1 0 100 1
105 1 0.620205188 1 0 100 1
106 1 0.625461296 1 0 100 1
107 1 0.633465294 1 0 100 1
108 1 0.633507280 1 0 100 1
109 1 0.640759321 1 0 100 1
110 1 0.642790922 1 0 100 1
111 1 0.644641142 1 0 100 1
112 1 0.656446538 1 0 100 1
113 1 0.660237826 1 0 100 1
114 1 0.663517186 1 0 100 1
115 1 0.663615622 1 0 100 1
116 1 0.664658161 1 0 100 1
117 1 0.665626199 1 0 100 1
118 1 0.678755968 1 0 100 1
119 1 0.681003655 1 0 100 1
120 1 0.681719499 1 0 100 1
121 1 0.690110526 1 0 100 1
122 1 0.696531586 1 0 100 1
123 1 0.710909445 1 0 100 1
124 1 0.711612790 1 0 100 1
125 1 0.728442951 1 0 100 1
126 1 0.741216006 1 0 100 1
127 1 0.745733117 1 0 100 1
128 1 0.768354068 1 0 100 1
129 1 0.769063435 1 0 100 1
130 1 0.771498263 1 0 100 1
131 1 0.772921513 1 0 100 1
132 1 0.791330999 1 0 100 1
133 1 0.815834509 1 0 100 1
134 1 0.815878029 1 0 100 1
135 1 0.816734014 1 0 100 1
136 1 0.817243638 1 0 100 1
137 1 0.819825244 1 0 100 1
138 1 0.823388786 1 0 100 1
139 1 0.844831005 1 0 100 1
140 1 0.846703023 1 0 100 1
141 1 0.856267187 1 0 100 1
142 1 0.858514492 1 0 100 1
143 1 0.861123661 1 0 100 1
144 1 0.875305698 1 0 100 1
145 1 0.875617931 1 0 100 1
146 1 0.876870024 1 0 100 1
147 1 0.886627804 1 0 100 1
148 1 0.887348842 1 0 100 1
149 1 0.889334413 1 0 100 1
150 1 0.902878098 1 0 100 1
151 1 0.906231215 1 0 100 1
152 1 0.907070927 1 0 100 1
153 1 0.907322761 1 0 100 1
154 1 0.907600294 1 0 100 1
155 1 0.907841225 1 0 100 1
156 1 0.910605047 1 0 100 1
157 1 0.927590676 1 0 100 1
158 1 0.941816746 1 0 100 1
159 1 0.947595752 1 0 100 1
160 1 0.953814089 1 0 100 1
161 1 0.973006674 1 0 100 1
162 1 0.978912536 1 0 100 1
163 1 0.999507157 1 0 100 1
164 1 1.007360715 1 0 100 1
165 1 1.010971548 1 0 100 1
166 1 1.015471441 1 0 100 1
[ reached 'max' / getOption("max.print") -- omitted 31878 rows ]

Question: Arguments for z in simEventData()

First of all, this is an amazing versatile package. It is very useful, especially for simulating event data.

I am currently looking at the following example from this vignette.

zFun3 <- function(time, a, b) cbind(time / 10 + a, as.numeric(time > b))
(simDat <- simEventData(nProcess = 3, z = zFun3, zCoef = c(- 0.1, 0.5),
                        arguments = list(z = list(a = quote(rpois(1, 10) / 10),
                                                  b = quote(runif(1, 1, 3))))))

I was trying to modify this code to fix the values of a:

zFun3 <- function(time, a, b) cbind(time / 10 + a, as.numeric(time > b))
(simDat <- simEventData(nProcess = 3, z = zFun3, zCoef = c(- 0.1, 0.5),
                        arguments = list(z = list(a = c(0.1, 0.2, 0.3),
                                                  b = quote(runif(1, 1, 3))))))

However, this does not work. Any suggestions how to have different but deterministic values for inputs of z?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.