2025-01-12 04:36:52 +08:00

144 lines
4.7 KiB
Plaintext

R Under development (unstable) (2024-02-06 r85866) -- "Unsuffered Consequences"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: aarch64-unknown-linux-gnu
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> options(na.action=na.exclude) # preserve missings
> options(contrasts=c('contr.treatment', 'contr.poly')) #ensure constrast type
> library(survival)
>
> #
> # Generate each of the messages from is.ratetable
> #
> mdy.date <- function(m, d, y) {
+ y <- ifelse(y<100, y+1900, y)
+ as.Date(paste(m,d,y, sep='/'), "%m/%d/%Y")
+ }
> temp <- runif(21*2*4)
>
> # Good
> attributes(temp) <- list(dim=c(21,2,4),
+ dimnames=list(c(as.character(75:95)), c("male","female"),
+ c(as.character(2000:2003))),
+ dimid=c("age","sex","year"),
+ type=c(2,1,4),
+ cutpoints=list(c(75:95), NULL, mdy.date(1,1,2000) +c(0:3)*366.25),
+ class='ratetable')
> is.ratetable(temp)
[1] TRUE
>
> # Factor problem + cutpoints length
> attributes(temp) <- list(dim=c(21,2,4),
+ dimnames=list(c(as.character(75:95)), c("male","female"),
+ c(as.character(2000:2003))),
+ dimid=c("age","sex","year"),
+ type=c(1,1,2),
+ cutpoints=list(c(75:95), NULL, mdy.date(1,1,2000) +c(0:4)*366.25),
+ class='ratetable')
> is.ratetable(temp, verbose=T)
[1] "type[3] is numeric or factor but the cutpoint is a date"
[2] "attribute type[1] is continuous; cutpoint should be null"
[3] "wrong length for cutpoints 3"
>
>
> # missing dimid attribute + unsorted cutpoint
> attributes(temp) <- list(dim=c(21,2,4),
+ dimnames=list(c(as.character(75:95)), c("male","female"),
+ c(as.character(2000:2003))),
+ type=c(2,1,3),
+ cutpoints=list(c(75:95), NULL, mdy.date(1,1,2000) +c(4:1)*366.25),
+ class='ratetable')
> is.ratetable(temp, verbose=T)
[1] "wrong length for dimid, or dimnames do not have names"
[2] "unsorted cutpoints for dimension 3"
>
> # wrong length for dimid and type, illegal type
> attributes(temp) <- list(dim=c(21,2,4),
+ dimnames=list(c(as.character(75:95)), c("male","female"),
+ c(as.character(2000:2003))),
+ dimid=c("age","sex","year", "zed"),
+ type=c(2,1,3,6),
+ cutpoints=list(c(75:95), NULL, mdy.date(1,1,2000) +c(0:3)*366.25),
+ class='ratetable')
> is.ratetable(temp, verbose=T)
[1] "wrong length for dimid, or dimnames do not have names"
[2] "type attribute must be 1, 2, 3, or 4"
[3] "wrong length for type attribute"
>
>
> # Print and summary
> print(survexp.us[1:20,,c('1953', '1985')] )
Rate table with dimension(s): age sex year
, , year = 1953
sex
age male female
0 8.936600e-05 6.911204e-05
1 6.169963e-06 5.423669e-06
2 3.860391e-06 3.161334e-06
3 2.909162e-06 2.424089e-06
4 2.448747e-06 1.950051e-06
5 2.210350e-06 1.692520e-06
6 1.988411e-06 1.481583e-06
7 1.813065e-06 1.298053e-06
8 1.684303e-06 1.169315e-06
9 1.593900e-06 1.087146e-06
10 1.569249e-06 1.051541e-06
11 1.626780e-06 1.043325e-06
12 1.771975e-06 1.089887e-06
13 2.062389e-06 1.199447e-06
14 2.462443e-06 1.347361e-06
15 2.944779e-06 1.550072e-06
16 3.410754e-06 1.752797e-06
17 3.819231e-06 1.928140e-06
18 4.164702e-06 2.056914e-06
19 4.504735e-06 2.169256e-06
, , year = 1985
sex
age male female
0 3.350073e-05 2.680036e-05
1 2.451492e-06 2.108968e-06
2 1.739100e-06 1.341882e-06
3 1.369277e-06 1.013196e-06
4 1.122754e-06 7.940941e-07
5 9.995021e-07 7.530142e-07
6 9.173378e-07 6.571643e-07
7 8.488687e-07 5.887021e-07
8 7.530153e-07 5.339338e-07
9 6.297793e-07 4.791661e-07
10 5.202416e-07 4.517830e-07
11 5.202416e-07 4.517830e-07
12 7.530134e-07 5.202412e-07
13 1.232311e-06 6.571636e-07
14 1.862374e-06 8.351727e-07
15 2.533686e-06 1.026887e-06
16 3.150341e-06 1.204921e-06
17 3.657474e-06 1.341877e-06
18 4.041315e-06 1.424054e-06
19 4.315527e-06 1.465144e-06
> summary(survexp.usr)
Rate table with 4 dimensions:
age ranges from 0 to 39812.25; with 110 categories
sex has levels of: male female
race has levels of: white black
year ranges from 1940-01-01 to 2020-01-01; with 81 categories
>
> proc.time()
user system elapsed
0.418 0.029 0.442