-
Notifications
You must be signed in to change notification settings - Fork 0
/
.Rhistory
510 lines (510 loc) · 16.7 KB
/
.Rhistory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
library(reda)
install.packages("reda")
library(reda)
install.packages("frailtyEM")
library(frailtyEM)
install.packages("reReg")
library(reReg)
library(revents)
pkgdown::build_site()
pkgdown::build_site()
pkgdown::build_articles()
pkgdown::build_articles()
pkgdown::build_articles()
pkgdown::build_site()
usethis::use_git()
pkgdown::build_articles()
pkgdown::build_site()
usethis::use_pkgdown_github_pages()
pkgdown::build_site()
devtools::document()
deploy_to_branch()
library(revents)
library(utils)
# Load data layout corresponding to the third layout
file_path_data_csv <- "revents/inst/data_layout_1.csv"
data_layout_1 <- read.csv(file_path_data_csv)
library(here)
knitr::opts_chunk$set(warning = FALSE, message = FALSE)
suppressWarnings({
suppressMessages({
library(survival)
library(broom)
library(dplyr)
library(utils)
library(frailtyEM)
library(here)
})
})
# Load data layout corresponding to the third layout
file_path_data_csv <- here("data", "data_layout_1.csv")
data_layout_1 <- read.csv(file_path_data_csv)
# Load data layout corresponding to the third layout
file_path_data_csv <- here("data", "data_layout_1.csv")
data_layout_1 <- read.csv(file_path_data_csv)
# Load data layout corresponding to the third layout
file_path_data_csv <- here("inst", "data_layout_1.csv")
data_layout_1 <- read.csv(file_path_data_csv)
# Load data layout corresponding to the third layout
library(here)
file_path_data_csv <- here("inst", "data_layout_1.csv")
data_layout_1 <- read.csv(file_path_data_csv)
pkgdown::build_articles()
usethis::use_data_raw("data_layout_1")
usethis::use_data_raw("data_layout_2")
usethis::use_data_raw("data_layout_3")
data_layout_1 <- readr::read_csv("data-raw/data_layout_1.csv")
data_layout_2 <- readr::read_csv("data-raw/data_layout_2.csv")
data_layout_3 <- readr::read_csv("data-raw/data_layout_3.csv")
usethis::use_data(data_layout_1, overwrite = TRUE)
usethis::use_data(data_layout_3, overwrite = TRUE)
usethis::use_data(data_layout_2, overwrite = TRUE)
usethis::use_r("data_layout_1")
usethis::use_r("data_layout_2")
usethis::use_r("data_layout_3")
# Load data layout corresponding to the third layout
data("data_layout_1", package = "revents")
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
knitr::opts_chunk$set(warning = FALSE, message = FALSE)
suppressWarnings({
suppressMessages({
library(survival)
library(broom)
library(dplyr)
library(frailtyEM)
})
})
# Load data layout corresponding to the third layout
data("data_layout_1", package = "revents")
# Load data layout corresponding to the third layout
data("data_layout_1", package = "revents")
devtools::document()
# Load data layout corresponding to the third layout
data("data_layout_1", package = "revents")
devtools::load_all(".")
data("data_layout_1", package = "revents")
?revents::data_layout_1
View(data_layout_1)
knitr::opts_chunk$set(warning = FALSE, message = FALSE)
suppressWarnings({
suppressMessages({
library(survival)
library(broom)
library(dplyr)
library(frailtyEM)
})
})
# Load data layout corresponding to the third layout
data_layout_1 <- data("data_layout_1", package = "revents")
# Load data layout corresponding to the third layout
data("data_layout_1", package = "revents")
data_layout_1 <- revents::data_layout_1
devtools::document()
# Load data layout corresponding to the third layout
data("data_layout_1", package = "revents")
data_layout_1 <- revents::data_layout_1
# set scientific notation to FALSE
options(scipen = 999)
cox.relapses <- coxph(Surv(TSTART, TSTOP, STATUS) ~ DISEASE_COURSE + AGE + SEX
+ RACE + TIME_SINCE_DIAGNOSIS, ties = "breslow",
data = subset(data_layout_1, SEVENT == 1))
cox.relapses
# Load data layout corresponding to the third layout
data("data_layout_1", package = "revents")
data_layout_1 <- revents::data_layout_1
# set scientific notation to FALSE
options(scipen = 999)
cox.relapses <- coxph(Surv(TSTART, TSTOP, STATUS) ~ DISEASE_COURSE + AGE + SEX
+ RACE + TIME_SINCE_DIAGNOSIS, ties = "breslow",
data = subset(data_layout_1, SEVENT == 1))
cox.relapses
View(data_layout_1)
coldesc <- rep("", ncol(data_layout_1))
names(coldesc) <- names(data_layout_1)
dput(coldesc)
devtools::document()
?revents::data_layout_1
library(roxygen2)
devtools::document()
install.packages("roxygen2")
devtools::document()
library(roxygen2)
devtools::document()
devtools::document()
devtools::document()
devtools::document()
devtools::document()
source("data-raw/create_data.R")
devtools::document()
## code to prepare `data_layout_1` dataset goes here
usethis::use_data(data_layout_1, overwrite = TRUE)
data_layout_1 <- readr::read_csv("data-raw/data_layout_1.csv")
usethis::use_data(data_layout_1, overwrite = TRUE)
vars <- c(
ID = "participant ID",
PARAMCD = "parameter",
TSTART = "time study start",
TSTOP = "time stop observation",
TGAP = "time gap between events",
STATUS = "status of the event",
SEVENT = "sequence number of event per id",
AGE = "age of the participant",
SEX = "Sex of the participant",
DISEASE_COURSE = "type of disease course",
RACE = "race of the participant",
TIME_SINCE_DIAGNOSIS = "time since diagnosis"
)
glue::glue("#' \\item{[colname]}{[coldesc]}",
colname = names(vars),
coldesc = vars,
.open = "[",
.close = "]")
## code to prepare `data_layout_2` dataset goes here
usethis::use_data(data_layout_2, overwrite = TRUE)
data_layout_2 <- readr::read_csv("data-raw/data_layout_2.csv")
usethis::use_data(data_layout_2, overwrite = TRUE)
vars <- c(
ID = "participant ID",
PARAMCD = "parameter",
TSTART = "time study start",
TSTOP = "time stop observation",
TGAP = "time gap between events",
STATUS = "status of the event",
SEVENT = "sequence number of event per id",
AGE = "age of the participant",
SEX = "Sex of the participant",
DISEASE_COURSE = "type of disease course",
RACE = "race of the participant",
TIME_SINCE_DIAGNOSIS = "time since diagnosis"
)
glue::glue("#' \\item{[colname]}{[coldesc]}",
colname = names(vars),
coldesc = vars,
.open = "[",
.close = "]")
## code to prepare `data_layout_3` dataset goes here
usethis::use_data(data_layout_3, overwrite = TRUE)
data_layout_3 <- readr::read_csv("data-raw/data_layout_3.csv")
usethis::use_data(data_layout_3, overwrite = TRUE)
vars <- c(
ID = "participant ID",
PARAMCD = "parameter",
TSTART = "time study start",
TSTOP = "time stop observation",
TGAP = "time gap between events",
STATUS = "status of the event",
SEVENT = "sequence number of event per id",
AGE = "age of the participant",
SEX = "Sex of the participant",
DISEASE_COURSE = "type of disease course",
RACE = "race of the participant",
TIME_SINCE_DIAGNOSIS = "time since diagnosis"
)
glue::glue("#' \\item{[colname]}{[coldesc]}",
colname = names(vars),
coldesc = vars,
.open = "[",
.close = "]")
devtools::document()
# Load data layout corresponding to the third layout
data("data_layout_1", package = "revents")
data_layout_1 <- revents::data_layout_1
devtools::load_all(".")
devtools::load_all(".")
usethis::use_data(data_layout_1, overwrite = TRUE)
usethis::use_data(data_layout_1, overwrite = TRUE)
source("data-raw/create_data.R")
source("data-raw/create_data.R")
source("data-raw/create_data.R")
library(revents)
devtools::document()
devtools::document()
devtools::document()
# Cargar librerías necesarias
library(here)
# Definir rutas a los archivos CSV
file_path_data_csv_1 <- here::here("data-raw", "data_layout_1.csv")
file_path_data_csv_2 <- here::here("data-raw", "data_layout_2.csv")
file_path_data_csv_3 <- here::here("data-raw", "data_layout_3.csv")
# Leer los archivos CSV
data_layout_1 <- read.csv(file_path_data_csv_1)
data_layout_2 <- read.csv(file_path_data_csv_2)
data_layout_3 <- read.csv(file_path_data_csv_3)
# Guardar los objetos en archivos .rda en el directorio `data`
save(data_layout_1, file = here::here("data", "data_layout_1.rda"))
source("data-raw/create_data.R")
# Cargar librerías necesarias
library(here)
# Definir rutas a los archivos CSV
file_path_data_csv_1 <- here::here("data-raw", "data_layout_1.csv")
file_path_data_csv_2 <- here::here("data-raw", "data_layout_2.csv")
file_path_data_csv_3 <- here::here("data-raw", "data_layout_3.csv")
# Leer los archivos CSV
data_layout_1 <- read.csv(file_path_data_csv_1)
data_layout_2 <- read.csv(file_path_data_csv_2)
data_layout_3 <- read.csv(file_path_data_csv_3)
# Guardar los objetos en archivos .rda en el directorio `data`
save(data_layout_1, file = here::here("data", "data_layout_1.rda"))
save(data_layout_2, file = here::here("data", "data_layout_2.rda"))
save(data_layout_3, file = here::here("data", "data_layout_3.rda"))
source("data-raw/create_data.R")
devtools::document()
devtools::document()
devtools::load_all(".")
?revents::data_layout_1
data("data_layout_1",package = "revents")
usethis::use_data(data_layout_1)
devtools::check_man()
data_layout_1 <- readr::read_csv("data/data_layout_1.csv")
usethis::use_data(data_layout_1, overwrite = TRUE)
Line 35
Line 35
glue::glue("#' \\item{[colname]}{[coldesc]}",
colname = names(vars),
coldesc = vars,
.open = "[",
.close = "]")
vars <- c(
ID = "participant ID",
PARAMCD = "parameter",
TSTART = "time study start",
TSTOP = "time stop observation",
TGAP = "time gap between events",
STATUS = "status of the event",
SEVENT = "sequence number of event per id",
AGE = "age of the participant",
SEX = "Sex of the participant",
DISEASE_COURSE = "type of disease course",
RACE = "race of the participant",
TIME_SINCE_DIAGNOSIS = "time since diagnosis"
)
glue::glue("#' \\item{[colname]}{[coldesc]}",
colname = names(vars),
coldesc = vars,
.open = "[",
.close = "]")
devtools::check_man()
devtools::document()
data_layout_2 <- readr::read_csv("data-raw/data_layout_2.csv")
usethis::use_data(data_layout_2, overwrite = TRUE)
data_layout_1 <- readr::read_csv("data-raw/data_layout_1.csv")
usethis::use_data(data_layout_1, overwrite = TRUE)
data_layout_3 <- readr::read_csv("data-raw/data_layout_3.csv")
usethis::use_data(data_layout_3, overwrite = TRUE)
devtools::document()
devtools::document()
devtools::document()
devtools::document()
library(revents)
head(revents::data_layout_1)
# Load data layout corresponding to the third layout
data("data_layout_1", package = "revents")
data_layout_1 <- revents::data_layout_1
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
knitr::opts_chunk$set(warning = FALSE, message = FALSE)
suppressWarnings({
suppressMessages({
library(revents)
library(survival)
library(broom)
library(dplyr)
library(frailtyEM)
})
})
# Load data layout corresponding to the third layout
data("data_layout_1", package = "revents")
data_layout_1 <- revents::data_layout_1
# set scientific notation to FALSE
options(scipen = 999)
cox.relapses <- coxph(Surv(TSTART, TSTOP, STATUS) ~ DISEASE_COURSE + AGE + SEX
+ RACE + TIME_SINCE_DIAGNOSIS, ties = "breslow",
data = subset(data_layout_1, SEVENT == 1))
cox.relapses
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
library(dplyr)
library(purrr)
library(tibble)
library(reda)
library(tidyr)
library(gtsummary)
library(writexl)
library(kableExtra)
# Set seed for reproducibility
set.seed(123)
# Define a function to simulate recurrent event data using reda
simulate_recurrent_event_data <- function(n, max_event, mean_follow_up_time, max_follow_up_time, mstype, outcome) {
simulate_individual_data <- function(id) {
# Generate baseline hazard times (exponential distribution)
basehaz <- rexp(n = pmax(pmin(round(rnorm(1, max_event/2, max_event/4)), max_event), 1),
rate = 1 / mean_follow_up_time)
basehaz <- basehaz[basehaz < max_follow_up_time]
basehaz <- c(basehaz,max_follow_up_time)
# Create a tibble for the individual's data
tibble(
id = id,
status = c(rep(1, length(basehaz) - 1), 0),
time = basehaz,
mstype = mstype,
outcome = outcome
)
}
# Use purrr::map_dfr to apply the helper function to each individual and combine the results
sim_data_all <- map_dfr(1:n, simulate_individual_data) %>%
arrange(id, time)
# Return the simulated data
return(sim_data_all)
}
# Generate the datasets for relapses in RRMS and SPMS patients
# this parameters have been changed in order to find differences between groups
# just for illustrative purposes
rrms_relapse_data<-simulate_recurrent_event_data(n = 791,
max_event = 10,
mean_follow_up_time = 8,
max_follow_up_time = 10,
mstype = "RRMS",
outcome = "RELAPSE")
spms_relapse_data<-simulate_recurrent_event_data(n = 522,
max_event = 4,
mean_follow_up_time = 5,
max_follow_up_time = 10,
mstype = "SPMS",
outcome = "RELAPSE")
spms_relapse_data$id <- spms_relapse_data$id + 791
# Bind datasets
df <- bind_rows(rrms_relapse_data,
spms_relapse_data)
#Add baaseline characteristics
# Function to generate data for RRMS
generate_rrms_data <- function(n) {
tibble(
id = 1:n,
Age = rnorm(n, mean = 36.5, sd = 9.1),
Sex = factor(rbinom(n, 1, prob = 0.70), labels = c("Male", "Female")),
Race = factor(rbinom(n, 1, prob = 0.88), labels = c("No white", "White")),
Time_since_diagnosis = rlnorm(n, meanlog = log(2), sdlog = log(5/2)),
EDSS_overall = rlnorm(n, meanlog = log(2), sdlog = log(3.5/1.5))
)
}
# Function to generate data for SPMS
generate_spms_data <- function(n) {
tibble(
id = 1:n,
Age = rnorm(n, mean = 49.4, sd = 8.1),
Sex = factor(rbinom(n, 1, prob = 0.63), labels = c("Male", "Female")),
Race = factor(rbinom(n, 1, prob = 0.96), labels = c("No white", "White")),
Time_since_diagnosis = rlnorm(n, meanlog = log(14.5), sdlog = log(22/7.8)), # approximate log-normal
EDSS_overall = rlnorm(n, meanlog = log(6), sdlog = log(6.5/4.5)) # approximate log-normal
)
}
# Generate the datasets
rrms_data <- generate_rrms_data(791)
spms_data <- generate_spms_data(522)
spms_data$id <- spms_data$id + 791
#Merge with the previous part
df_revents <- inner_join(bind_rows(rrms_data, spms_data),df, by="id")
kbl(df_revents[1:10,]) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed"))
# Save data as CSV
file_path_data_csv <- "C:/Users/david/revents/inst/simulated_data.csv"
write.csv(as.data.frame(df_revents), file_path_data_csv)
usethis::use_data(simulated_data, overwrite = TRUE)
df_revents <- readr::read_csv("data-raw/simulated_data.csv")
usethis::use_data(data_layout_3, overwrite = TRUE)
usethis
usethis::use_r("simulated_data")
devtools::document()
library(revents)
devtools::document()
library(revents)
library(revents)
devtools::document()
devtools::load_all(".")
df_revents <- readr::read_csv("data-raw/simulated_data.csv")
usethis::use_data(data_layout_3, overwrite = TRUE)
usethis::use_data(simulated_data, overwrite = TRUE)
# Cargar librerías necesarias
library(here)
file_path_data_csv_simulated <- here::here("data-raw", "simulated_data.csv")
df_revents <- read.csv(file_path_data_csv_1)
file_path_data_csv_simulated <- here::here("data-raw", "simulated_data.csv")
df_revents <- read.csv(file_path_data_csv_simulated)
save(df_revents, file = here::here("data", "simulated_data.rda"))
devtools::document()
devtools::document()
head(revents::df_revents)
df_revents <- readr::read_csv("data-raw/df_revents.csv")
usethis::use_data(simulated_data, overwrite = TRUE)
usethis::use_data(df_revents, overwrite = TRUE)
df_revents <- readr::read_csv("data-raw/df_revents.csv")
usethis::use_data(df_revents, overwrite = TRUE)
devtools::document()
devtools::load_all(".")
head(revents::df_revents)
library(revents)
# Load the simulated data
data("df_revents", package = "revents")
df_revents <- revents::df_revents
# Load the simulated data
data("df_revents", package = "revents")
df_revents <- revents::df_revents
df_revents <- revents::df_revents
pkgdown::build_articles()
pkgdown::build_site()
pkgdown::build_articles()
pkgdown::build_articles()
usethis::use_pkgdown_github_pages()
devtools::document()
# Find the maximum SEVENT value in your data
max_SEVENT <- max(data_layout_1$SEVENT)
# Create a data frame with all combinations of USUBJID and SEVENT
combinations <- expand.grid(ID = unique(data_layout_1$ID), SEVENT = 1:max_SEVENT)
# Merge the original data frame with all combinations of USUBJID and SEVENT
data_layout_2 <-
merge(combinations, data_layout_1,
by = c("ID", "SEVENT"),
all.x = TRUE
) %>%
arrange(ID, SEVENT) %>%
# select only necessary variables (TGAP are not necessary in this layout)
dplyr::select(-TGAP) %>%
# fill in missing values by repeating the value of the last cell
fill(PARAMCD, TSTART, TSTOP, STATUS, SEVENT, DISEASE_COURSE, SEX, AGE, RACE,
TIME_SINCE_DIAGNOSIS
)
kbl(data_layout_2[1:20,]) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed"))
kbl(data_layout_2[1:20,]) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed"))
pkgdown::build_articles()
usethis::use_pkgdown_github_pages()
devtools::document()
vars <- c(
ID = "participant ID",
PARAMCD = "parameter",
TSTART = "time study start",
TSTOP = "time stop observation",
TGAP = "time gap between events",
STATUS = "status of the event",
SEVENT = "sequence number of event per id",
AGE = "age of the participant",
SEX = "Sex of the participant",
DISEASE_COURSE = "type of disease course",
RACE = "race of the participant",
TIME_SINCE_DIAGNOSIS = "time since diagnosis"
)
glue::glue("#' \\item{[colname]}{[coldesc]}",
colname = names(vars),
coldesc = vars,
.open = "[",
.close = "]")
head(revents::data_layout_2)
head(revents::data_layout_3)