-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.R
More file actions
202 lines (153 loc) · 6.84 KB
/
main.R
File metadata and controls
202 lines (153 loc) · 6.84 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
######################################################################
### Restart R
#.rs.restartR()
### Start with a clean environment by removing objects in workspace
rm(list=ls())
### Setting work directory
working_directory <- base::setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
#working_directory <- base::setwd(".")
### Load Rdata
Rdata_files <- list.files(path = working_directory, pattern = "*.RData", full.names = T) #No subdirectories
if ( length(Rdata_files) >0) {
invisible(lapply(Rdata_files,load,.GlobalEnv))
} else {
paste(c(".RData files", "do not exist"), collapse = " ")
}
### Install required packages
source("requirements.R")
### helper/customized functions
source("helperfuns_1.R")
source("helperfuns_2.R")
source("helperfuns_plots_3.R")
source("helperfuns_plots_4.R")
### process flowchart
source("flowchart.R")
#df_clean_supermarket_a <- readRDS("df_raw_a.rds")
#df_clean_a <- readRDS("df_clean_a.rds")
#df_loyalty <- readRDS("df_loyalty.rds")
#df_loyalty_analysis <- readRDS("df_loyalty_analysis.rds")
#df_loyalty_analysis_nova <- readRDS("df_loyalty_analysis_nova.rds")
#df_loyalty_analysis_class_name <- readRDS("df_loyalty_analysis_class_name.rds")
#df_loyalty_basket_classname <- readRDS("df_loyalty_basket_classname.rds")
### Load recode file
source("load_recode_file.R")
######################################################################
## Loading and Cleaning Data
### Load supermarketA Rdata file
source("load_data_local.R")
### Data cleaning
source("cleaning.R")
### Create tables in database schema in Postgres
#source("create_tables_local_database.R")
### insert raw data in created tables
#source("insert_data_tables_local_database.R")
### Select variables for analysis
source("analysis_data.R")
source("analysis_data_wide_nova.R")
source("analysis_data_wide_classname.R")
### Save analysis clean data set - spss file
source("save_analysis_clean_data.R")
######################################################################
## Data Profiling - Loyalty customers
### Descriptive and Inferential stats
source("customer_stats.R")
source("nova_items_stats.R")
#source("nova_items_stats_gt.R")
source("items_prop_differences_stats.R")
#source("items_prop_differences_stats_gt.R")
### Saving descriptive and inferential output
source("save_customer_stats_output.R")
source("save_nova_items_stats_output.R")
#source("save_nova_items_stats_gt_output.R")
source("save_items_prop_differences_stats_output.R")
#source("save_items_prop_differences_stats_gt_output.R")
######################################################################
## Plots- Loyalty customers
### Descriptive plots - simple and stacked bar graphs
source("customer_descriptive_plots.R")
source("nova_items_descriptive_plots.R")
### Time series plots - proportion
source("customer_month_trend_prop_plots.R")
source("customer_quarter_trend_prop_plots.R")
source("nova_month_trend_prop_plots.R")
source("nova_quarter_trend_prop_plots.R")
source("items_quantity_month_trend_prop_plots.R")
source("items_quantity_quarter_trend_prop_plots.R")
### Age-Sex Time series plots - proportion
source("customer_age_sex_month_trend_prop_plots.R")
source("customer_age_sex_quarter_trend_prop_plots.R")
source("nova_age_sex_month_trend_prop_plots.R")
source("nova_age_sex_quarter_trend_prop_plots.R")
source("items_quantity_count_age_sex_month_trend_prop_plots.R")
source("items_quantity_count_age_sex_quarter_trend_prop_plots.R")
### Age-County Time series plots - proportion
source("customer_age_county_month_trend_prop_plots.R")
source("customer_age_county_quarter_trend_prop_plots.R")
source("nova_age_county_month_trend_prop_plots.R")
source("nova_age_county_quarter_trend_prop_plots.R")
source("items_quantity_count_age_county_month_trend_prop_plots.R")
source("items_quantity_count_age_county_quarter_trend_prop_plots.R")
### Sex-County Time series plots - proportion
source("customer_sex_county_month_trend_prop_plots.R")
source("customer_sex_county_quarter_trend_prop_plots.R")
source("nova_sex_county_month_trend_prop_plots.R")
source("nova_sex_county_quarter_trend_prop_plots.R")
source("items_quantity_count_sex_county_month_trend_prop_plots.R")
source("items_quantity_count_sex_county_quarter_trend_prop_plots.R")
######################################################################
## Market Basket Analysis - Loyalty customers
source("transactions_stats.R")
source("save_transactions_stats_output.R")
### Transform data to dummy
source("basket_analysis_data.R")
### Class name rules
source("basket_classname_thresholds.R")
source("basket_classname_overall.R")
source("basket_classname_overall_frequent_items.R")
source("basket_classname_gender.R")
source("basket_classname_age.R")
source("basket_classname_year.R")
source("basket_classname_county.R")
source("basket_classname_age_gender.R")
source("basket_classname_age_county.R")
source("basket_classname_gender_county.R")
source("basket_classname_year_gender.R")
source("basket_classname_year_age.R")
source("basket_classname_year_county.R")
### Saving class name Market Basket Analysis output
source("save_classname_basket_output.R")
### Visualize class name LHS Rules - Heat maps
source("lhs_rules_classname_heatmap.R")
source("lhs_rules_socio_by_classname_heatmap.R")
source("lhs_rules_year_by_classname_heatmap.R")
### Visualize class name RHS Rules - Heat maps
source("rhs_rules_classname_heatmap.R")
source("rhs_rules_socio_by_classname_heatmap.R")
source("rhs_rules_year_by_classname_heatmap.R")
######################################################################
## Save workspace at the end without working directory path
save(list = ls(all.names = TRUE)[ls(all.names = TRUE) %in% c("df_loyalty_analysis", "df_loyalty_analysis_class_name",
"df_loyalty_basket_classname", "df_loyalty_analysis_nova")],
file = "df_loyalty_analysis.RData",
envir = .GlobalEnv #parent.frame()
)
save(list = ls(all.names = TRUE, pattern = "*_prop_differences_nova"),
file = "nova_prop_differences_analysis.RData",
envir = .GlobalEnv #parent.frame()
)
save(list = ls(all.names = TRUE, pattern = "*_prop_differences_items"),
file = "items_prop_differences_analysis.RData",
envir = .GlobalEnv #parent.frame()
)
save(list = ls(all.names = TRUE, pattern = "*_classname_rules"),
file = "basket_classname_analysis.RData",
envir = .GlobalEnv #parent.frame()
)
#saveRDS(df_clean_supermarket_a, file = "df_raw_a.rds")
#saveRDS(df_clean_a, file = "df_clean_a.rds")
#saveRDS(df_loyalty, file = "df_loyalty.rds")
#saveRDS(df_loyalty_analysis, file = "df_loyalty_analysis.rds")
#saveRDS(df_loyalty_analysis_nova, file = "df_loyalty_analysis_nova.rds")
#saveRDS(df_loyalty_analysis_class_name, file = "df_loyalty_analysis_class_name.rds")
#saveRDS(df_loyalty_basket_classname, file = "df_loyalty_basket_classname.rds")
######################################################################