generated from opensafely/research-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudy_definition.py
58 lines (51 loc) · 1.56 KB
/
study_definition.py
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
from cohortextractor import StudyDefinition, patients, codelist, codelist_from_csv # NOQA
study = StudyDefinition(
default_expectations={
"date": {"earliest": "1900-01-01", "latest": "today"},
"rate": "uniform",
"incidence": 0.5,
},
population=patients.registered_with_one_practice_between(
"2019-01-01", "2023-01-01"
),
ageVar=patients.age_as_of(
"2023-01-01",
return_expectations={
"rate": "universal",
"int": {"distribution": "population_ages"},
},
),
sex=patients.sex(
return_expectations={
"rate": "universal",
"category": {"ratios": {"M": 0.49, "F": 0.51}},
}
),
region=patients.registered_practice_as_of(
"2020-02-01",
returning="nuts1_region_name",
return_expectations={
"rate": "universal",
"category": {
"ratios": {
"North East": 0.1,
"North West": 0.1,
"Yorkshire and the Humber": 0.1,
"East Midlands": 0.1,
"West Midlands": 0.1,
"East of England": 0.1,
"London": 0.2,
"South East": 0.2,
},
},
},
),
ethnicity=patients.with_ethnicity_from_sus(
returning="group_6",
use_most_frequent_code=True,
return_expectations={
"category": {"ratios": {"1": 0.8, "5": 0.1, "3": 0.1}},
"incidence": 0.75,
},
)
)