-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnova_items_stats_gt.R
More file actions
111 lines (91 loc) · 3.31 KB
/
nova_items_stats_gt.R
File metadata and controls
111 lines (91 loc) · 3.31 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(dplyr)
library(gtsummary)
working_directory
my_gtsummary_theme
gtsummary_compact_theme
## Descriptive statistics for nova items
### nova
descriptive_nova_items_gt <- descriptive_table(
df = df_loyalty_analysis %>%
dplyr::select(nova, customer_id),
foot_note = "n (%)",
caption = "Nova Classification",
categorical_proportion_digits = 3,
flex_table = FALSE,
include = c("nova")
)
## Inferential statistics
### nova classification by year
inferential_year_nova_items_gt <-
inferential_table(
df = df_loyalty_analysis %>%
dplyr::select(nova, year, customer_id),
foot_note = "n (%)",
caption = "Nova Classification",
categorical_proportion_digits = 3,
flex_table = FALSE,
by_vars = c("year"),
include = c("year", "nova")
)
### gender, branch, age-group, repeat customer by nova classification
inferential_nova_items_gt <-
inferential_table(
df = df_loyalty_analysis %>%
dplyr::select(nova, year, customer_id, gender, age_group, county_name),
foot_note = "n (%)",
caption = "Nova Classification",
categorical_proportion_digits = 3,
by_vars = c("nova"),
percent = "row",
include = c("gender", "age_group", "county_name", "year", "nova")
)
print(inferential_nova_items_gt)
### stratify gender - nova classification by age-group, county, year
inferential_strata_gender_nova_items_gt <-
inferential_strata_table(
df = df_loyalty_analysis %>%
dplyr::select(nova, year, customer_id, gender, age_group, county_name),
foot_note = "n (%)",
caption = "Nova Classification - Strata Gender",
categorical_proportion_digits = 3,
strata_vars = "gender",
by_vars = c("age_group", "county_name", "year"),
percent = "column",
include = c("nova")
)
print(inferential_strata_gender_nova_items)
### stratify age-group - nova classification by gender, county, year
inferential_strata_age_nova_items_gt <-
inferential_strata_table(
df = df_loyalty_analysis %>%
dplyr::select(nova, year, customer_id, gender, age_group, county_name),
foot_note = "n (%)",
caption = "Nova Classification - Strata Age group",
categorical_proportion_digits = 3,
strata_vars = "age_group",
by_vars = c("gender", "county_name", "year"),
percent = "column",
include = c("nova")
)
print(inferential_strata_age_nova_items_gt)
### stratify county - nova classification by gender, age-group, year
inferential_strata_county_nova_items_gt <-
inferential_strata_table(
df = df_loyalty_analysis %>%
dplyr::select(nova, year, customer_id, gender, age_group, county_name),
foot_note = "n (%)",
caption = "Nova Classification - Strata County",
categorical_proportion_digits = 3,
strata_vars = "county_name",
by_vars = c("gender", "age_group", "year"),
percent = "column",
include = c("nova")
)
print(inferential_strata_county_nova_items_gt)
## Merging gtsummary tables
### Merging descriptive and inferential year
descriptive_inferential_year_nova_items_gt_merge <- gtsummary::tbl_merge(tbls= c(list(descriptive_nova_items_gt),
inferential_year_nova_items_gt )
) %>%
gtsummary::as_flex_table()
print(descriptive_inferential_year_nova_items_gt_merge)