-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4_1_sparse_diffs.R
More file actions
executable file
·154 lines (113 loc) · 3.4 KB
/
4_1_sparse_diffs.R
File metadata and controls
executable file
·154 lines (113 loc) · 3.4 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
# setwd("/Users/gregfaletto/Documents/GitHub/presto")
if(!is.null(dev.list())){
dev.off()
}
rm(list=ls())
library(simulator)
library(MASS)
library(parallel)
library(cowplot)
library(ggplot2)
library(stargazer)
dir_main <- getwd()
dir_ordnet <- paste(dir_main, "/ordinalNet modified", sep="")
setwd(dir_ordnet)
source("cdIn.R")
source("cdOut.R")
source("links.R")
source("mirlsNet.R")
source("misc.R")
source("ordinalNet-methods.R")
source("ordinalNet.R")
source("ordinalNetCV.R")
source("ordinalNetTune.R")
setwd(dir_main)
dir_code <- paste(dir_main, "/Simulations", sep="")
setwd(dir_code)
source("model_functions.R")
source("method_functions.R")
source("eval_functions.R")
source("sim_eval_function.R")
setwd(dir_main)
t0 <- Sys.time()
set.seed(2390812)
# Initialize parallel processing--only works on Mac or Unix.
n_cores <- 7
stopifnot(n_cores <= detectCores())
if(n_cores == 7){
nsims <- 100
} else{
nsims <- 700
}
# About 0.88 minutes per simulation
intcpt_list <- list(c(0, 3, 5), c(0, 3.5, 5.5), c(0, 4, 6))
sparse_sim <- new_simulation("sparse_sim", "Relaxed Proportional Odds")
sparse_sim <- generate_model(sparse_sim, relax_prop_odds_model_rand, n = 2500,
p = 10, K = 4, intercepts=intcpt_list, beta = rep(.5, 10), dev_size=.5,
dev_prob=list(1/3, 1/2), vary_along=c("intercepts", "dev_prob"))
sparse_sim <- simulate_from_model(sparse_sim, nsim = nsims, index = 1:n_cores)
print("")
print("")
print("")
print("")
print("")
print("")
print("")
print("")
print("Done generating data! Now running methods (in parallel)...")
print("Time elapsed:")
print(Sys.time() - t0)
print("")
print("")
print("")
print("")
print("")
print("")
print("")
print("")
sparse_sim <- run_method(sparse_sim, list(logit_meth, prop_odds_meth,
fused_polr, fused_polr_l2), parallel=list(socket_names=n_cores))
print("")
print("")
print("Done running methods! Now evaluating...")
print("Time elapsed:")
print(Sys.time() - t0)
print("")
print("")
print("")
sparse_sim <- evaluate(sparse_sim, list(prop_rare_obs, rare_prob_mse_gen))
save_simulation(sparse_sim)
print("Done! Total time for simulations:")
t1 <- Sys.time()
print(t1 - t0)
sparse_plots_1_3 <- create_sparse_plots(subset_simulation(sparse_sim,
methods=c("logit_meth", "prop_odds_meth", "fused_polr")))
# Figure 6 (sparsity 1/3)
fig_6 <- sparse_plots_1_3$main_plot
# Figure 7 (sparsity 1/3)
fig_7 <- sparse_plots_1_3$supp_plot
sparse_plots_1_2 <- create_sparse_plots(subset_simulation(sparse_sim,
methods=c("logit_meth", "prop_odds_meth", "fused_polr")), plots=c(2, 4, 6))
# Figure 1 (sparsity 1/2)
fig_1 <- sparse_plots_1_2$main_plot
# Figure 5 (sparsity 1/2)
fig_5 <- sparse_plots_1_2$supp_plot
ret <- df_sim_stats(subset_simulation(sparse_sim, methods=c("logit_meth",
"prop_odds_meth", "fused_polr")), methods_to_compare=c("logit_meth",
"prop_odds_meth" ))
# Table 3
stargazer(ret$t_d_df, summary=FALSE)
# Table 4
stargazer(ret$summary_df, summary=FALSE)
# Ridge presto results
# Figure 10
fig_10 <- create_sparse_plot2_ridge(sparse_sim, plots=1)
# Figure 11
fig_11 <- create_sparse_plot2_ridge(sparse_sim, plots=2)
ret_ridge <- df_sim_stats(subset_simulation(sparse_sim, methods=c("logit_meth",
"prop_odds_meth", "fused_polr", "fused_polr_l2")),
methods_to_compare=c("logit_meth", "prop_odds_meth", "fused_polr_l2"))
# Table 3
stargazer(ret_ridge$t_d_df, summary=FALSE)
# Table 4
stargazer(ret_ridge$summary_df, summary=FALSE)