-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_benchmark_with_mnp.R
More file actions
76 lines (65 loc) · 2.44 KB
/
Copy pathtest_benchmark_with_mnp.R
File metadata and controls
76 lines (65 loc) · 2.44 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
#!/usr/bin/env Rscript
# Quick benchmark test with MNP NOW AVAILABLE
cat(paste(rep("=", 70), collapse=""), "\n")
cat("QUICK BENCHMARK WITH MNP AVAILABLE\n")
cat(paste(rep("=", 70), collapse=""), "\n\n")
setwd("/home/user/MNLNP")
source("R/run_benchmark_simulation.R")
source("R/generate_data.R")
source("R/fit_mnp_safe.R")
source("R/compare_mnl_mnp.R")
cat("MNP Package Status:\n")
cat(" Installed:", requireNamespace("MNP", quietly = TRUE), "\n")
if (requireNamespace("MNP", quietly = TRUE)) {
cat(" Version:", as.character(packageVersion("MNP")), "\n")
}
cat("\n")
cat("Running QUICK benchmark (30 simulations, ~2-3 minutes)...\n")
cat("Configuration:\n")
cat(" - Sample sizes: 100, 250, 500\n")
cat(" - Correlations: 0, 0.4\n")
cat(" - Effect size: 0.5\n")
cat(" - Reps per condition: 5\n")
cat(" - Total: 30 simulations\n\n")
set.seed(2024)
quick_results <- run_benchmark_simulation(
sample_sizes = c(100, 250, 500),
correlations = c(0, 0.4),
effect_sizes = c(0.5),
n_reps = 5, # Very small for quick test
n_alternatives = 3,
n_vars = 2,
functional_forms = "linear",
parallel = FALSE,
save_results = FALSE,
verbose = TRUE
)
cat("\n")
cat(paste(rep("=", 70), collapse=""), "\n")
cat("RESULTS\n")
cat(paste(rep("=", 70), collapse=""), "\n\n")
cat("MNP Convergence Rates by Sample Size:\n")
for (n in c(100, 250, 500)) {
subset_data <- quick_results[quick_results$sample_size == n, ]
conv_rate <- mean(subset_data$mnp_convergence_rate, na.rm = TRUE)
cat(sprintf(" n = %4d: %5.1f%%\n", n, conv_rate * 100))
}
cat("\nMNL vs MNP Performance (when both converge):\n")
both_converged <- quick_results[quick_results$mnp_convergence_rate > 0, ]
if (nrow(both_converged) > 0) {
avg_mnl_wins <- mean(both_converged$mnl_win_rate, na.rm = TRUE)
cat(sprintf(" MNL win rate: %.1f%%\n", avg_mnl_wins * 100))
cat(sprintf(" MNP win rate: %.1f%%\n", (1 - avg_mnl_wins) * 100))
}
cat("\nAverage RMSE:\n")
cat(sprintf(" MNL: %.4f\n", mean(quick_results$mnl_rmse_mean, na.rm = TRUE)))
cat(sprintf(" MNP: %.4f (when converged)\n",
mean(quick_results$mnp_rmse_mean[quick_results$mnp_convergence_rate > 0],
na.rm = TRUE)))
cat("\n")
cat(paste(rep("=", 70), collapse=""), "\n")
cat("KEY FINDING: MNP NOW CONVERGES WITH PACKAGE INSTALLED!\n")
cat(paste(rep("=", 70), collapse=""), "\n\n")
cat("Saving results...\n")
saveRDS(quick_results, "data/quick_benchmark_with_mnp.rds")
cat("Saved to: data/quick_benchmark_with_mnp.rds\n\n")