-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfcal-lcmm.qmd
executable file
·61 lines (55 loc) · 1.45 KB
/
fcal-lcmm.qmd
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
#### LCMM
```{R LCMM code}
#| eval: false
#| echo: true
#| code-fold: false
## Modelling ##
library(lcmm)
library(splines)
args <- commandArgs(trailingOnly = TRUE)
fcal <- readRDS("fcal.RDS")
fcal$calpro_result <- log(fcal$calpro_result)
if(!dir.exists("cache")) dir.create("cache")
rep <- 50
# set the maximum number of iterations
maxiter <- 10
if(file.exists("m1.RDS")) {
m1 <- readRDS("m1.RDS")
ng <- as.numeric(args[1])
# create a cluster
cl <- parallel::makeForkCluster(parallel::detectCores())
# export the number of groups to the cluster
parallel::clusterExport(cl, "ng")
# run gridsearch
hlme.fit <- gridsearch(
rep = rep,
maxiter = maxiter,
minit = m1,
cl = cl,
hlme(calpro_result ~ ns(calpro_time,
df = 4,
Boundary.knots = c(0, 7)),
mixture = ~ ns(calpro_time,
df = 4,
Boundary.knots = c(0, 7)),
random = ~ 1,
subject = "ids",
classmb = ~ 1 + diagnosis,
ng = ng,
data = fcal,
maxiter = 24000,
verbose = TRUE,
partialH = FALSE)
)
# stop the cluster
parallel::stopCluster(cl)
if (hlme.fit$conv == 1) {
message("Convergence achieved for ", ng, " subgroups ✅ \n")
} else {
stop("Convergence NOT achieved for ", ng, " subgroups ⚠️ \n")
}
saveRDS(hlme.fit, paste0("cache/fcal-", ng, ".RDS"))
} else {
stop("m1 not found!")
}
```