Skip to content

Commit

Permalink
keep time down
Browse files Browse the repository at this point in the history
  • Loading branch information
ConnorDonegan committed Nov 16, 2024
1 parent ef4234b commit fe22d2b
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 97 deletions.
1 change: 1 addition & 0 deletions cran-comments.md~
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Passed devtools::check and win-builder
8 changes: 4 additions & 4 deletions tests/check-ME-estimates-monte-carlo-output.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"","Par","DGP","Est","Error"
"GLM02","Gamma",-0.5,-0.448383867901742,0.05
"GLM03","Beta",0.5,0.460249847633467,-0.04
"SEM2","Gamma",-0.5,-0.489599181407199,0.01
"SEM3","Beta",0.5,0.501982725320289,0
"SEM2","Gamma",-0.5,-0.458922340470886,0.04
"SEM3","Beta",0.5,0.458214672414099,-0.04
"SEM_ME2","Gamma",-0.5,-0.486704303847752,0.01
"SEM_ME3","Beta",0.5,0.498553276127644,0
48 changes: 30 additions & 18 deletions tests/check-ME-estimates-monte-carlo.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
library(geostan)

## no. iterations
M = 35
M = 15

## a regular grid
ncol = 20
Expand Down Expand Up @@ -41,29 +41,40 @@ res <- sapply(1:M, FUN = function(i) {
ME <- prep_me_data(se = data.frame(x = rep(sigma.me, N)))
if (rho.x > 0) ME <- prep_me_data(se = data.frame(x = rep(sigma.me, N)), car_parts = cars)

fit_sem <- geostan::stan_sar(y ~ x,
fit_sem_me <- geostan::stan_sar(y ~ x,
data = dat,
type = "SDEM",
sar_parts = sars,
ME = ME,
chains = 1,
iter = 1e3,
iter = 600,
quiet = TRUE,
slim = TRUE
) |>
suppressWarnings()

fit_glm0 <- geostan::stan_glm(y ~ x,
slx = ~ x,
data = dat,
## ME = ME, ##
C = cars$C,
chains = 1,
iter = 1e3,
quiet = TRUE,
slim = TRUE
) |>
fit_sem <- geostan::stan_sar(y ~ x,
data = dat,
type = "SDEM",
sar_parts = sars,
## ME = ME, ##
chains = 1,
iter = 600,
quiet = TRUE,
slim = TRUE
) |>
suppressWarnings()
## fit_glm0 <- geostan::stan_glm(y ~ x,
## slx = ~ x,
## data = dat,
## ## ME = ME, ##
## C = cars$C,
## chains = 1,
## iter = 600,
## quiet = TRUE,
## slim = TRUE
## ) |>
## suppressWarnings()
## fit_car <- geostan::stan_car(y ~ x,
## slx = ~ x,
## data = dat,
Expand All @@ -89,9 +100,10 @@ res <- sapply(1:M, FUN = function(i) {
## suppressWarnings()

x <- c(
GLM0 = fit_glm0$summary[c('intercept', 'w.x', 'x', 'rho', 'sigma'), 'mean'],
# GLM0 = fit_glm0$summary[c('intercept', 'w.x', 'x', 'rho', 'sigma'), 'mean'],
# GLM = fit_glm$summary[c('intercept', 'w.x', 'x', 'rho', 'sigma'), 'mean'],
SEM = fit_sem$summary[c('intercept', 'w.x', 'x', 'sar_rho', 'sar_scale'), 'mean'] #,
SEM_ME = fit_sem_me$summary[c('intercept', 'w.x', 'x', 'sar_rho', 'sar_scale'), 'mean'],
SEM = fit_sem$summary[c('intercept', 'w.x', 'x', 'sar_rho', 'sar_scale'), 'mean'] #,
# CAR = fit_car$summary[c('intercept', 'w.x', 'x', 'car_rho', 'car_scale'), 'mean']
)

Expand All @@ -103,10 +115,10 @@ res <- sapply(1:M, FUN = function(i) {
RMSE <- function(est, true) sqrt(mean(est - true)^2)

g_res <- res |>
subset(row.names(res) %in% c('GLM02', 'SEM2'))
subset(row.names(res) %in% c('SEM_ME2', 'SEM2'))
## subset(row.names(res) %in% c('GLM02', 'GLM2', 'SEM2', 'CAR2'))
b_res <- res |>
subset(row.names(res) %in% c('GLM03', 'SEM3'))
subset(row.names(res) %in% c('SEM_ME3', 'SEM3'))
## subset(row.names(res) %in% c('GLM03', 'GLM2', 'SEM3', 'CAR3'))

cat("\n**\nRMSE of ME models: \n**\n")
Expand All @@ -124,7 +136,7 @@ cat("\n**\nME models\nSEM Estimates (rounded) should be close to DGP parameters

est <- apply(res, 1, mean)

est <- est[c('GLM02', 'GLM03', 'SEM2', 'SEM3')]
est <- est[c('SEM2', 'SEM3', 'SEM_ME2', 'SEM_ME3')]

out <- data.frame(
# Mod = attributes(est)$names,
Expand Down
2 changes: 1 addition & 1 deletion tests/check-SEM-CAR-GLM-estimates-monte-carlo.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
library(geostan)

## no. iterations
M = 15
M = 20

# generate y using SLM or SEM
#sar_type <- commandArgs(trailingOnly = TRUE)
Expand Down
2 changes: 1 addition & 1 deletion tests/check-SLM-estimates-monte-carlo.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
library(geostan)

# no. iterations [s > 90 required for impact est. to converge - they are high variance; others converge by 30]
S <- 50
S <- 30

# use measurement error in x
has_me <- FALSE
Expand Down
73 changes: 0 additions & 73 deletions tests/missing-y.R~

This file was deleted.

0 comments on commit fe22d2b

Please sign in to comment.