-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTesting_running_time_in_R.qmd
More file actions
85 lines (73 loc) · 1.81 KB
/
Testing_running_time_in_R.qmd
File metadata and controls
85 lines (73 loc) · 1.81 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
# Testing R performance versus SAS
## Task 1
What are the counts and proportions of males and females in outpatient claims (2017-2019) by year?
```{r}
tic()
ccaeo |>
filter(YEAR %in% 2017:2019) |>
select(SEX, YEAR) |>
group_by(YEAR) |>
count(SEX) |>
to_duckdb()
toc()
```
## Task 2
Calculate summary statistics for the co-payments in pharmacy claims (2017-2019) for metformin-containing medications
```{r}
tic()
ccaed |>
select(ENROLID, NDCNUM, COPAY, YEAR) |>
filter(YEAR %in% 2017:2019) |>
filter(!is.na(ENROLID)) |>
select(-ENROLID) |>
filter(str_detect(NDCNUM, metformin_drugs_regex)) |>
select(-NDCNUM) |>
to_duckdb() |>
collect() |>
summarise(COPAY2 = mean(COPAY, na.rm = T), .by = YEAR)
toc()
```
## Task 3
How many pioglitazone dispensing claims with at least a 30-day supply in 2018 and 2019?
```{r}
tic()
ccaed |>
select(ENROLID, NDCNUM, YEAR, DAYSUPP) |>
filter(YEAR %in% 2018:2019) |>
filter(!is.na(ENROLID), DAYSUPP >= 30) |>
select(-ENROLID) |>
filter(str_detect(NDCNUM, pioglitazone_drugs_regex)) |>
select(-NDCNUM) |>
to_duckdb() |>
group_by(YEAR) |>
count()
toc()
```
## Task 4
Calculate the summary statistics of the number of hospital admissions per beneficiary (2017-2019).
```{r}
tic()
ccaei |>
select(ENROLID, ADMDATE, YEAR) |>
filter(YEAR %in% 2017:2019) |>
filter(!is.na(ENROLID)) |>
distinct() |>
count(ENROLID, sort = T) |>
collect()
toc()
```
## Task 5
Calculate the counts and proportions of type 2 diabetes patients by region (2017-2019)
```{r}
tic()
ccaeo |>
filter(!is.na(ENROLID), YEAR %in% 2017:2019) |>
select(ENROLID, contains("DX"), REGION) |>
to_duckdb() |>
filter(
(if_any(contains("DX"), ~str_detect(.x, {{type2_diabetes_regex}})))
) |>
distinct(ENROLID, REGION) |>
count(REGION)
toc()
```