File: etm_intern.R

package info (click to toggle)
r-cran-etm 1.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 660 kB
  • sloc: cpp: 303; ansic: 20; sh: 13; makefile: 2
file content (49 lines) | stat: -rwxr-xr-x 1,287 bytes parent folder | download
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
#####################################################################
### The etm machinery
### Arthur Allignol <arthur.allignol@uni-ulm.de
#####################################################################


.etm <- function(entry,
                 exit,
                 from,
                 to,
                 nstate,
                 s,
                 t,
                 covariance,
                 const_modif) {

    times <- sort(unique(exit[to != 0]))
    times <- times[times > s & times <= t]

    if (length(times) == 0) {
        zzz <- list()
        zzz$est <- array(diag(1, nrow = nstate, nstate), dim = list(nstate, nstate, 1))
        zzz$dna <- array(matrix(0, nrow = nstate, ncol = nstate), dim = list(nstate, nstate, 1))
        zzz$n.risk <- zzz$time <- zzz$n.event <- NULL
        return(zzz)
    } else {

        c_modif <- matrix(const_modif, length(times), nstate, byrow = TRUE)

        zzz <- .Call("gen_msm", times, entry, exit, from, to, nstate, c_modif)

    }

    if (covariance) {

        cov_etm <- .Call("cov_aj",
                         zzz$time,
                         zzz$est,
                         zzz$n.risk,
                         zzz$n.event,
                         zzz$dna)

        zzz$cov <- cov_etm

    }

    zzz
}