File: print.etm.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 (103 lines) | stat: -rwxr-xr-x 3,510 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
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
print.etm <- function(x, covariance = FALSE, whole = TRUE, ...) {

    if (!inherits(x, "etm"))
        stop("'x' must be of class 'etm'")

    absorb <- setdiff(as.character(x$trans$to), as.character(x$trans$from))
    transient <- unique(x$state.names[!(x$state.names %in% absorb)])

    cat(paste("Multistate model with", length(transient), "transient state(s)\n",
              "and", length(absorb), "absorbing state(s)\n\n", sep = " "))

    cat("Possible transitions:\n")
    print(x$trans, row.names = FALSE)
    cat("\n")

   if (is.null(x$strata)) {

        cat(paste("Estimate of P(", x$s, ", ", x$t, ")\n", sep = ""))
        print(x$est[, , dim(x$est)[3]]); cat("\n")

        if (!is.null(x$cov) & covariance == TRUE) {
            if (whole) {
                cat(paste("Estimate of cov(P(", x$s, ", ", x$t, "))\n", sep = ""))
                print(x$cov[, , dim(x$cov)[3]])
            }
            else {
                cov <- x$cov[, , dim(x$cov)[3]][rowSums(x$cov[, , dim(x$cov)[3]]) != 0, ]
                cova <- cov[, colSums(cov) != 0]
                cat(paste("Estimate of cov(P(", x$s, ", ", x$t, "))\n", sep = ""))
                print(cova)
            }
        }

    } else {

        for (i in seq_along(x$strata)) {

            cat("\t", x$strata[i], ":\n\n")

            cat(paste("Estimate of P(", x[i]$s, ", ", x[i]$t, ")\n", sep = ""))
            print(x[i]$est[, , dim(x[i]$est)[3]]); cat("\n")

            if (!is.null(x$cov) & covariance == TRUE) {
                if (whole) {
                    cat(paste("Estimate of cov(P(", x[i]$s, ", ", x[i]$t, "))\n", sep = ""))
                    print(x[i]$cov[, , dim(x[i]$cov)[3]])
                }
                else {
                    cov <- x[i]$cov[, , dim(x[i]$cov)[3]][rowSums(x[i]$cov[, , dim(x[i]$cov)[3]]) != 0, ]
                    cova <- cov[, colSums(cov) != 0]
                    cat(paste("Estimate of cov(P(", x[i]$s, ", ", x[i]$t, "))\n", sep = ""))
                    print(cova)
                }
            }

        }
    }

    invisible()

}

### etmStratified
## print.etm.stratified <- function(x, covariance = FALSE, whole = TRUE, ...) {

##     if (!inherits(x, "etm.stratified"))
##         stop("'x' must be of class 'etm.stratified'")

##     absorb <- setdiff(levels(x$trans$to), levels(x$trans$from))
##     transient <- unique(x$state.names[!(x$state.names %in% absorb)])

##     cat(paste("Multistate model with", length(transient), "transient state(s)\n",
##               "and", length(absorb), "absorbing state(s)\n\n", sep = " "))

##     cat("Possible transitions:\n")
##     print(x$trans, row.names = FALSE)
##     cat("\n")

##     for (i in seq_along(x$strata)) {

##         cat(x$strata[i], ":\n\n")

##         cat(paste("Estimate of P(", x[i]$s, ", ", x[i]$t, ")\n", sep = ""))
##         print(x[i]$est[, , dim(x[i]$est)[3]]); cat("\n")

##         if (!is.null(x$cov) & covariance == TRUE) {
##             if (whole) {
##                 cat(paste("Estimate of cov(P(", x[i]$s, ", ", x[i]$t, "))\n", sep = ""))
##                 print(x[i]$cov[, , dim(x[i]$cov)[3]])
##             }
##             else {
##                 cov <- x[i]$cov[, , dim(x[i]$cov)[3]][rowSums(x[i]$cov[, , dim(x[i]$cov)[3]]) != 0, ]
##                 cova <- cov[, colSums(cov) != 0]
##                 cat(paste("Estimate of cov(P(", x[i]$s, ", ", x[i]$t, "))\n", sep = ""))
##                 print(cova)
##             }
##         }

##     }

##     invisible()

## }