Skip to content

Commit b394166

Browse files
minor cleanup
1 parent b0eda0e commit b394166

File tree

1 file changed

+58
-115
lines changed

1 file changed

+58
-115
lines changed
Lines changed: 58 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,65 @@
1-
library(rlang)
21
library(iidda.analysis)
32

43
if (interactive()) {
5-
measles = ("measles_1800_to_1842.rds"
6-
|> system.file(package = "iidda.analysis")
7-
|> readRDS()
8-
)
9-
meningitis = ("meningitis_on.rds"
10-
|> system.file(package = "iidda.analysis")
11-
|> readRDS()
12-
)
13-
london_mort = ("london-mort-harmonized.rds"
14-
|> system.file(package = "iidda.analysis")
15-
|> readRDS()
16-
)
17-
18-
iidda_bar(meningitis)
19-
20-
harmonizer = SeriesHarmonizer()
21-
xx = harmonizer(london_mort)
22-
View(xx)
23-
24-
cause_lookup = iidda.api::ops_staging$lookup_tables("lbom-cause-lookup")
25-
cause_hierachy = (cause_lookup
26-
|> select(synonym, nesting_cause)
27-
|> rename(cause = synonym)
28-
|> distinct()
29-
)
30-
View(cause_lookup)
31-
32-
converter = DataDictionaryConverter()
33-
NestingHarmonizer = function(category_level, id_variables) {
34-
function(data
35-
, value_variable = NULL
36-
, category_variable = NULL
37-
, nesting_variable = NULL
38-
) {
39-
data = iidda.analysis:::resolve_var_args(data)
40-
top_level_vars = c(id_variables, category_variable, value_variable)
41-
grouping_vars = c(id_variables, nesting_variable)
42-
final_id_vars = c(id_variables, category_variable)
43-
top_level_data = (data
44-
|> filter(.data[[category_variable]] == category_level)
45-
|> select(all_of(top_level_vars))
46-
)
47-
finer_data = (data
48-
|> filter(.data[[nesting_variable]] == category_level)
49-
|> summarise(!!sym(value_variable) := sum(.data[[value_variable]]), .by = all_of(grouping_vars))
50-
|> rename(!!sym(category_variable) := all_of(nesting_variable))
51-
)
52-
output_data = bind_rows(top_level_data, finer_data)
53-
unique_numbers_of_repeats = (output_data
54-
|> summarise(n = n(), .by = all_of(final_id_vars))
55-
|> pull(n)
56-
|> unique()
57-
)
58-
if (!identical(unique_numbers_of_repeats, 1L)) {
59-
stop("Harmonization failed. Please insert more coins for a better explanation")
4+
measles = ("measles_1800_to_1842.rds"
5+
|> system.file(package = "iidda.analysis")
6+
|> readRDS()
7+
)
8+
meningitis = ("meningitis_on.rds"
9+
|> system.file(package = "iidda.analysis")
10+
|> readRDS()
11+
)
12+
london_mort = ("london-mort-harmonized.rds"
13+
|> system.file(package = "iidda.analysis")
14+
|> readRDS()
15+
)
16+
17+
iidda_bar(meningitis)
18+
19+
cause_lookup = iidda.api::ops_staging$lookup_tables("lbom-cause-lookup")
20+
cause_hierachy = (cause_lookup
21+
|> select(synonym, nesting_cause)
22+
|> rename(cause = synonym)
23+
|> distinct()
24+
)
25+
26+
27+
converter = DataDictionaryConverter()
28+
NestingHarmonizer = function(category_level, id_variables) {
29+
function(data
30+
, value_variable = NULL
31+
, category_variable = NULL
32+
, nesting_variable = NULL
33+
) {
34+
data = iidda.analysis:::resolve_var_args(data)
35+
top_level_vars = c(id_variables, category_variable, value_variable)
36+
grouping_vars = c(id_variables, nesting_variable)
37+
final_id_vars = c(id_variables, category_variable)
38+
top_level_data = (data
39+
|> filter(.data[[category_variable]] == category_level)
40+
|> select(all_of(top_level_vars))
41+
)
42+
finer_data = (data
43+
|> filter(.data[[nesting_variable]] == category_level)
44+
|> summarise(!!sym(value_variable) := sum(.data[[value_variable]]), .by = all_of(grouping_vars))
45+
|> rename(!!sym(category_variable) := all_of(nesting_variable))
46+
)
47+
output_data = bind_rows(top_level_data, finer_data)
48+
unique_numbers_of_repeats = (output_data
49+
|> summarise(n = n(), .by = all_of(final_id_vars))
50+
|> pull(n)
51+
|> unique()
52+
)
53+
if (!identical(unique_numbers_of_repeats, 1L)) {
54+
stop("Harmonization failed. Please insert more coins for a better explanation")
55+
}
56+
iidda.analysis:::iidda_return(output_data, data)
6057
}
61-
iidda.analysis:::iidda_return(output_data, data)
6258
}
63-
}
64-
library(ggplot2)
65-
trimer = TrimSeries(zero_lead = TRUE, zero_trail = TRUE)
66-
(london_mort
67-
|> converter()
68-
|> ff(category_level = "Cholera", id_variables = c("period_start_date", "period_end_date"))
69-
|> trimer()
70-
|> ggplot()
71-
+ aes(period_end_date, deaths)
72-
+ geom_line()
73-
+ scale_x_date(minor_breaks = "years")
74-
+ scale_y_continuous(transform = "sqrt")
75-
+ theme_bw()
76-
)
77-
78-
79-
cholera_1842_to_1901_new = (london_mort_raw
80-
|> filter(cause == "Cholera")
81-
|> filter(between(period_end_date, "1841-12-31", "1901-12-31"))
82-
|> select(period_start_date, period_end_date, cause, deaths)
83-
|> bind_rows((london_mort_raw
84-
|> filter(nesting_cause == "Cholera")
85-
|> filter(between(period_end_date, "1841-12-31", "1901-12-31"))
86-
|> group_by(period_start_date, period_end_date, nesting_cause)
87-
|> summarise(deaths = sum(deaths))
88-
|> rename(cause = nesting_cause)
89-
))
90-
)
91-
92-
(meningitis
93-
|> iidda_prep_bar(time_unit = "month_factor_abbr")
94-
|> iidda_attach_bar()
95-
|> iidda_render_plot(title = "Friend")
96-
)
97-
(meningitis
98-
|> period_describer()
99-
|> iidda_prep_series(time_variable = "period_mid_date")
100-
|> iidda_attach_series()
101-
|> iidda_render_plot()
102-
)
103-
(measles
104-
|> period_describer(period_end_variable = "period_end_date")
105-
|> iidda_series(series_variable = "deaths")
106-
)
107-
108-
109-
110-
111-
112-
guesser = TitleChooser()
113-
measles |> guesser() |> attr("iidda")
114-
115-
attr((measles), "iidda")
116-
iidda_title(plot_object
117-
, data[[min_time]]
118-
, data[[max_time]]
119-
, data[[descriptor_name]] |> pull()
120-
, theme
59+
60+
(meningitis
61+
|> iidda_prep_bar(time_unit = "month_factor_abbr")
62+
|> iidda_attach_bar()
63+
|> iidda_render_plot(title = "Friend")
12164
)
12265
}

0 commit comments

Comments
 (0)