-
Notifications
You must be signed in to change notification settings - Fork 0
/
.Rhistory
301 lines (301 loc) · 8.23 KB
/
.Rhistory
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
48+36
load("clean_data/nhanes_data_12d_5r.Rdata")
# generate a small dataset
library(rvinecopulib)
library(dplyr)
set.seed(123)
x <- 1:20
y1 <- x + rnorm(20, mean = 0, sd = 5)
y2 <- 4*x + rnorm(20, mean = 0, sd = 5)
# Generate data third variable (slope = 10)
Age <- c(runif(20, min = 0, max = 20),
runif(20, min = 20, max = 40))
data <- cbind(rbind(cbind(x,y1),cbind(x,y2)),Age)
Weight_1 <- rep(c(1,10), each = 20)
Weight_2 <- rep(c(10,1), each = 20)
colnames(data) <- c("x", "y","age")
data <- as.numeric(data)
copula_sw <- vine(dat = data,
margins_controls = list(mult = 1, xmin =NaN, xmax = NaN, bw = NA, deg = 2),
copula_controls = list(family_set = "parametric",
weights = Weight_1,
par_method = "mle",
selcrit = "aic",
keep_data = TRUE,
cores = 1,
var_types = rep("c", 3)),
weights = numeric(),
keep_data = TRUE,
cores = 1)
copula_uw <- vine(dat = data,
margins_controls = list(mult = 1, xmin =NaN, xmax = NaN, bw = NA, deg = 2),
copula_controls = list(family_set = "parametric",
weights = Weight_2,
par_method = "mle",
selcrit = "aic",
keep_data = TRUE,
cores = 1,
var_types = rep("c", 3)),
weights = numeric(),
keep_data = TRUE,
cores = 1)
copula_sw
copula_uw
tree_sw <- plot(copula_sw$copula,
tree = 1,
var_names = "use",
edge_labels = "family")
copula_uw$copula
data
x <- 1:20
y1 <- x + rnorm(20, mean = 0, sd = 5)
y2 <- 4*x + rnorm(20, mean = 0, sd = 5)
# Generate data third variable (slope = 10)
Age <- c(runif(20, min = 0, max = 20),
runif(20, min = 20, max = 40))
data <- cbind(rbind(cbind(x,y1),cbind(x,y2)),Age)
data
Weight_1 <- rep(c(1,10), each = 20)
Weight_2 <- rep(c(10,1), each = 20)
colnames(data) <- c("x", "y","age")
data <- as.numeric(data)
data <- cbind(rbind(cbind(x,y1),cbind(x,y2)),Age)
Weight_1 <- rep(c(1,10), each = 20)
Weight_2 <- rep(c(10,1), each = 20)
colnames(data) <- c("x", "y","age")
copula_sw <- vine(dat = data,
margins_controls = list(mult = 1, xmin =NaN, xmax = NaN, bw = NA, deg = 2),
copula_controls = list(family_set = "parametric",
weights = Weight_1,
par_method = "mle",
selcrit = "aic",
keep_data = TRUE,
cores = 1,
var_types = rep("c", 3)),
weights = numeric(),
keep_data = TRUE,
cores = 1)
copula_uw <- vine(dat = data,
margins_controls = list(mult = 1, xmin =NaN, xmax = NaN, bw = NA, deg = 2),
copula_controls = list(family_set = "parametric",
weights = Weight_2,
par_method = "mle",
selcrit = "aic",
keep_data = TRUE,
cores = 1,
var_types = rep("c", 3)),
weights = numeric(),
keep_data = TRUE,
cores = 1)
copula_sw$copula
copula_uw$copula
sim_sw <- rvine(1000, copula_sw) %>%
as.data.frame() %>%
mutate(type = "weighted VP")
sim_uw <- rvine(1000, copula_uw) %>%
as.data.frame() %>%
mutate(type = "unweighted VP")
sim <- rbind(sim_sw, sim_uw)
library(GGally)
library(ggplot2)
library(GGally)
ggpairs(sim, aes(color = type))
?numeric
library(rvinecopulib)
library(dplyr)
library(ggplot2)
library(GGally)
set.seed(123)
x <- 1:20
y1 <- x + rnorm(20, mean = 0, sd = 10)
y2 <- 4*x + rnorm(20, mean = 0, sd = 15)
# Generate data third variable (slope = 10)
Age <- c(runif(20, min = 0, max = 20),
runif(20, min = 20, max = 40))
data <- cbind(rbind(cbind(x,y1),cbind(x,y2)),Age)
Weight_1 <- rep(c(1,10), each = 20)
Weight_2 <- rep(c(10,1), each = 20)
colnames(data) <- c("x", "y","age")
data
copula_sw <- vine(dat = data,
margins_controls = list(mult = 1, xmin =NaN, xmax = NaN, bw = NA, deg = 2),
copula_controls = list(family_set = "parametric",
weights = Weight_1,
par_method = "mle",
selcrit = "aic",
keep_data = TRUE,
cores = 1,
var_types = rep("c", 3)),
weights = numeric(),
keep_data = TRUE,
cores = 1)
copula_uw <- vine(dat = data,
margins_controls = list(mult = 1, xmin =NaN, xmax = NaN, bw = NA, deg = 2),
copula_controls = list(family_set = "parametric",
weights = Weight_2,
par_method = "mle",
selcrit = "aic",
keep_data = TRUE,
cores = 1,
var_types = rep("c", 3)),
weights = numeric(),
keep_data = TRUE,
cores = 1)
### tree ----
copula_sw
copula_uw
Weight_1 <- rep(c(1,10), each = 20)
Weight_1
Weight_2 <- rep(c(10,1), each = 20)
Weight_2
copula_1_20 <- vine(dat = data[c(1:20,)],
margins_controls = list(mult = 1, xmin =NaN, xmax = NaN, bw = NA, deg = 2),
copula_controls = list(family_set = "parametric",
weights = Weight_1,
par_method = "mle",
selcrit = "aic",
keep_data = TRUE,
cores = 1,
var_types = rep("c", 3)),
weights = numeric(),
keep_data = TRUE,
cores = 1)
data[1:20,]
copula_1_20 <- vine(dat = data[1:20,],
margins_controls = list(mult = 1, xmin =NaN, xmax = NaN, bw = NA, deg = 2),
copula_controls = list(family_set = "parametric",
weights = Weight_1,
par_method = "mle",
selcrit = "aic",
keep_data = TRUE,
cores = 1,
var_types = rep("c", 3)),
weights = numeric(),
keep_data = TRUE,
cores = 1)
data[21:40,]
copula_21_40 <- vine(dat = data[21:40,],
margins_controls = list(mult = 1, xmin =NaN, xmax = NaN, bw = NA, deg = 2),
copula_controls = list(family_set = "parametric",
weights = Weight_1,
par_method = "mle",
selcrit = "aic",
keep_data = TRUE,
cores = 1,
var_types = rep("c", 3)),
weights = numeric(),
keep_data = TRUE,
cores = 1)
copula_1_20$copula
copula_21_40$copula
x <- rnorm(30) * matrix(1, 30, 5) + 0.5 * matrix(rnorm(30 * 5), 30, 5)
x
u <- pseudo_obs(x)
u
fit <- vinecop(u)
summary(fit)
plot(fit)
contour(fit)
# test the weight with this example
nrows(u)
# test the weight with this example
nrow(u)
weight_test_1 <- rep(c(1,100),each = 15)
weight_test_2 <- rep(c(100,1),each = 15)
fit_1 <- vinecop(u,
weights = weight_test_1)
summary(fit)
summary(fit_1)
fit_1
fit_2 <- vinecop(u,
weights = weight_test_2)
fit_2
# weight works!!! --> maybe it's because of the absolute value of weight
# Assign weights for experiments
Weight_1 <- rep(c(1,1000), each = 20) # more weight on the second part of the <data>
Weight_2 <- rep(c(1000,1), each = 20) # more weight on the first part of the <data>
colnames(data) <- c("x", "y","age")
copula_sw <- vine(dat = data,
margins_controls = list(mult = 1, xmin =NaN, xmax = NaN, bw = NA, deg = 2),
copula_controls = list(family_set = "parametric",
weights = Weight_1,
par_method = "mle",
selcrit = "aic",
keep_data = TRUE,
cores = 1,
var_types = rep("c", 3)),
weights = numeric(),
keep_data = TRUE,
cores = 1)
copula_uw <- vine(dat = data,
margins_controls = list(mult = 1, xmin =NaN, xmax = NaN, bw = NA, deg = 2),
copula_controls = list(family_set = "parametric",
weights = Weight_2,
par_method = "mle",
selcrit = "aic",
keep_data = TRUE,
cores = 1,
var_types = rep("c", 3)),
weights = numeric(),
keep_data = TRUE,
cores = 1)
copula_sw$copula
copula_uw$data
copula_uw$copula
copula_sw$copula
load("D:/0 Others/Software/repo/NHANES_copula_coen_V0/clean_data/nhanes_data_12d_log_sw.Rdata")
library(dplyr)
library(survey)
library(ggplot2)
library(ggpubr)
library(reshape2)
library(tidyr)
library(dplyr)
library(combinat)
library(rvinecopulib)
source("functions/calculate_metric.R")
source("functions/calculate_frequency.R")
combi <- permn(1:5) # 120
i = 19
nhanes_data_sw_log$Race <- ordered(nhanes_data_sw_log$Race, levels = combi[[i]])
levels(nhanes_data_log$Race)
combi <- permn(1:5) # 120
i = 19
nhanes_data_sw_log$Race <- ordered(nhanes_data_sw_log$Race, levels = combi[[i]])
levels(nhanes_data_sw_log$Race)
nhanes_data_sw_log$Gender <- ordered(nhanes_data_sw_log$Gender, levels = c(1,2))
levels(nhanes_data_sw_log$Gender)
obs_data <- nhanes_data_sw_log %>%
select(-WTMEC2YR)
sample_w <- nhanes_data_sw_log$WTMEC2YR/5 # five releases
start_time <- Sys.time()
nhanes_copula_sw <- vine(dat = obs_data,
margins_controls = list(mult = 1, xmin =NaN, xmax = NaN, bw = NA, deg = 2),
copula_controls = list(family_set = "parametric",
par_method = "mle",
selcrit = "aic",
keep_data = TRUE,
cores = 1,
var_types = c("d","d",rep("c", 10))),
weights = sample_w,
keep_data = TRUE,
cores = 1)
end_time <- Sys.time()
cat("time of copula fitting: ", end_time - start_time, "weighted") # 16.11191 weighted
save(nhanes_copula_sw, file = "results/nhanes_copula_Lscale_weighted.Rdata")
sessionInfo()
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
library(tidyr)
library(dplyr)
library(combinat)
library(reshape2)
library(ggplot2)
library(ggpubr)
library(ggside)
library(rvinecopulib)
source("functions/calculate_metric.R")
source("functions/calculate_frequency.R") # functions for the batch calculation of frequency of discrete var
# data
load("results/nhanes_copula_Lscale.Rdata")
load("clean_data/nhanes_data_12d_5r.Rdata") # observation data, original scale
load("clean_data/nhanes_data_12d_5r.Rdata") # observation data, original scale