inst/doc/rmsBMA.R

## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(
  echo       = TRUE,
  fig.align  = "center",
  out.width  = "85%",
  fig.width  = 5.5,
  fig.height = 4.0
)

## ----eval=FALSE---------------------------------------------------------------
# install.packages("rmsBMA")

## -----------------------------------------------------------------------------

library(rmsBMA)

## ----eval=FALSE---------------------------------------------------------------
# ?migration_panel

## -----------------------------------------------------------------------------

migration_panel[1:10,1:7]

## -----------------------------------------------------------------------------

data <- data_preparation(migration_panel,
                         time = "Year_0",
                         id = "Pair_ID",
                         fixed_effects = TRUE,
                         effect = "twoway",
                         standardize = TRUE)
data[1:10,1:6]

## -----------------------------------------------------------------------------

data <- data_preparation(Trade_data,
                         standardize = TRUE)
data[1:10,1:6]

## ----eval=FALSE---------------------------------------------------------------
# ?Trade_data

## ----eval=FALSE---------------------------------------------------------------
# modelSpace10 <- model_space(Trade_data, M = 10, g = "Benchmark")

## ----eval=FALSE---------------------------------------------------------------
# modelSpace10_none <- model_space(Trade_data, M = 10, g = "None", HC = TRUE)

## ----eval=FALSE---------------------------------------------------------------
# modelSpace <- model_space(Trade_data_small, M = 7, g = "UIP")

## -----------------------------------------------------------------------------

bma_results <- bma(modelSpace, round = 3)

## -----------------------------------------------------------------------------

bma_results[[1]]

## -----------------------------------------------------------------------------

bma_results[[2]]

## -----------------------------------------------------------------------------

bma_results[[3]]

## -----------------------------------------------------------------------------

bma_results[[4]]

## -----------------------------------------------------------------------------

for_models <- model_pmp(bma_results)

## -----------------------------------------------------------------------------

for_models <- model_pmp(bma_results, top = 10)

## -----------------------------------------------------------------------------

size_graphs <- model_sizes(bma_results)

## -----------------------------------------------------------------------------

best_8_models <- best_models(bma_results, criterion = 1, best = 8)
best_8_models[[1]]

## -----------------------------------------------------------------------------

best_3_models <- best_models(bma_results, criterion = 2, best = 3)
best_3_models[[4]]

## -----------------------------------------------------------------------------

best_3_models <- best_models(bma_results, criterion = 2, best = 3)
grid::grid.draw(best_3_models[[6]])

## -----------------------------------------------------------------------------

jointness(bma_results)[1:9,1:9]

## ----warning=FALSE------------------------------------------------------------
jointness(bma_results, measure = "LS")[1:9,1:9]

## ----warning=FALSE------------------------------------------------------------
jointness(bma_results, measure = "DW")[1:9,1:9]

## -----------------------------------------------------------------------------

bin_sizes <- matrix(80, nrow = 11, ncol = 1)
coef_plots <- coef_hist(bma_results, BN = 1, num = bin_sizes)
coef_plots[[3]]

## -----------------------------------------------------------------------------

coef_plots2 <- coef_hist(bma_results, kernel = 1)
coef_plots2[[5]]

## -----------------------------------------------------------------------------

library(gridExtra)
grid.arrange(coef_plots[[3]], coef_plots[[5]], coef_plots2[[3]],
             coef_plots2[[5]], nrow = 2, ncol = 2)

## -----------------------------------------------------------------------------

coef_plots3 <- coef_hist(bma_results, weight = "beta", BN = 1, num = bin_sizes)
coef_plots3[[5]]

## -----------------------------------------------------------------------------

distPlots <- posterior_dens(bma_results, prior = "binomial")
grid.arrange(distPlots[[3]], distPlots[[5]], nrow = 2, ncol = 1)

## -----------------------------------------------------------------------------

bma_results2 <- bma(modelSpace, round = 3, EMS = 2)

## -----------------------------------------------------------------------------

bma_results2[[4]]

## -----------------------------------------------------------------------------

size_graphs2 <- model_sizes(bma_results2)

## -----------------------------------------------------------------------------

model_graphs2 <- model_pmp(bma_results2)

## -----------------------------------------------------------------------------

bma_results2[[1]]

## -----------------------------------------------------------------------------

bma_results2[[2]]

## -----------------------------------------------------------------------------

jointness(bma_results2, measure = "HCGHM", rho = 0.5, round = 3)[1:9,1:9]

## -----------------------------------------------------------------------------

bma_results8 <- bma(modelSpace, round = 3, EMS = 8)
bma_results8[[4]]

## -----------------------------------------------------------------------------

size_graphs8 <- model_sizes(bma_results8)

## -----------------------------------------------------------------------------

model_graphs8 <- model_pmp(bma_results8)

## -----------------------------------------------------------------------------

bma_results8[[1]]

## -----------------------------------------------------------------------------

bma_results8[[2]]

## -----------------------------------------------------------------------------

jointness(bma_results8, measure = "HCGHM", rho = 0.5, round = 3)[1:9,1:9]

## -----------------------------------------------------------------------------

bma_results_dil <- bma(
  modelSpace = modelSpace,
  round       = 3,
  dilution    = 1
  )

## -----------------------------------------------------------------------------

size_graphs_dil <- model_sizes(bma_results_dil)

## -----------------------------------------------------------------------------

bma_results_dil01 <- bma(
  modelSpace = modelSpace,
  round       = 3,
  dilution    = 1,
  dil.Par     = 0.1
)
size_graphs_dil01 <- model_sizes(bma_results_dil01)

## -----------------------------------------------------------------------------

bma_results_dil2 <- bma(
  modelSpace = modelSpace,
  round       = 3,
  dilution    = 1,
  dil.Par     = 2
)
size_graphs_dil2 <- model_sizes(bma_results_dil2)

## -----------------------------------------------------------------------------

bma_results_dil2[[2]]

## -----------------------------------------------------------------------------

group_vec <- c(1,0,1,0,0,0,2,2,3,3)

## -----------------------------------------------------------------------------

cbind(modelSpace[[1]],group_vec)

## -----------------------------------------------------------------------------

par_vec <- c(0.8,0.6,0.4)

## -----------------------------------------------------------------------------

bma_results_dil3 <- bma(
  modelSpace = modelSpace,
  Narrative  = 1,
  Nar_vec    = group_vec,
  p          = par_vec,
  round      = 3
)
bma_results_dil3[[1]]

## -----------------------------------------------------------------------------

bma_results_dil3[[2]]

Try the rmsBMA package in your browser

Any scripts or data that you put into this service are public.

rmsBMA documentation built on March 14, 2026, 5:06 p.m.