-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_lt.R
More file actions
114 lines (100 loc) · 2.85 KB
/
test_lt.R
File metadata and controls
114 lines (100 loc) · 2.85 KB
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
library(DemoTools)
library(tidyverse)
library(LifeIneq)
library(testthat)
library(scales)
library(covr)
source("R/readers.R")
source("R/list_utils.R")
source("R/lifetables.R")
# single
data_in <- read_csv("inst/extdata/single_hmd_spain.csv") %>%
dplyr::select(-1)
# abriged
data_in <- read_csv("inst/extdata/abridged_hmd_spain.csv") %>%
dplyr::select(-1)
# 5-year
data_in <- read_csv("inst/extdata/five_hmd_spain.csv") %>%
dplyr::select(-1)
argums <- expand_grid(
Sex = "t",
extrapFrom = c(60, 80),
extrapLaw = c("Kannisto", "Kannisto_Makeham",
"Makeham", "Gompertz",
"GGompertz", "Beard",
"Beard_Makeham", "Quadratic"),
OAnew = c(100, 80, 60),
age_out = c("single", "abridged", "5-year"),
radix = c(1, 100000),
SRB = 1.05,
a0rule = c("Andreev-Kingkade",
"Coale-Demeny"),
axmethod = c("UN (Greville)", "PASEX"),
by_args = "Year"
)
# lt_flexible(
# data_in,
# OAnew = argums$OAnew[1],
# age_out = argums$age_out[1],
# extrapFrom = argums$extrapFrom[1],
# extrapFit = NULL, # Default NULL, computed later
# extrapLaw = argums$extrapLaw[1],
# radix = argums$radix[1],
# SRB = argums$SRB[1],
# a0rule = argums$a0rule[1],
# axmethod = argums$axmethod[1],
# Sex = argums$Sex[1],
# by_args = argums$by_args[1]
# )
# save results
x <- vector(mode = "list",
length = nrow(argums))
# for trycatch
errors <- vector("numeric")
# Loop through each row in argums
for (i in 1:nrow(argums)) {
x[[i]] <- tryCatch(
{
lt_flexible(
data_in,
OAnew = argums$OAnew[i],
age_out = argums$age_out[i],
extrapFrom = argums$extrapFrom[i],
extrapFit = NULL, # Default NULL, computed later
extrapLaw = argums$extrapLaw[i],
radix = argums$radix[i],
SRB = argums$SRB[i],
a0rule = argums$a0rule[i],
axmethod = argums$axmethod[i],
Sex = argums$Sex[i],
by_args = argums$by_args[i]
)
},
error = function(e) {
# Store the index and error message in the `errors` list
errors[[i]] <- paste("Error at index", i, ":", e$message)
NA # Return NA for this entry in `x`
}
)
}
# name the resulting list
nms <- argums %>%
unite("x", everything(), sep = ", ") %>%
pull(x)
# add element number to names
nms <- str_c(1:nrow(argums), nms, sep = ", ")
# set the names
x <- x %>%
set_names(nms)
# lets see which names are resulting in problems
# some of the rough_method
# if no errors is empty
z <- x %>%
keep(~ is.logical(.)) %>% # empty
names() %>%
as.data.frame() %>%
separate_wider_delim('.',
delim = ", ",
names_sep = "_",
too_few = "align_start") %>%
set_names(c("element", names(argums)))