Skip to content

Commit e80957a

Browse files
author
aliaksah
committed
libraries in the script updated
1 parent e52604d commit e80957a

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

R_script/reproducible_script.R

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,20 @@ library(FBMS)
227227
###############################################################
228228
# 2.0 Load Zambia data (requires cAIC4)
229229
###############################################################
230+
if (!requireNamespace("lme4", quietly = TRUE)) {
231+
stop("Optional package 'lme4' is required for Example 2. Please install it.")
232+
}
233+
if (!requireNamespace("tictoc", quietly = TRUE)) {
234+
stop("Optional package 'tictoc' is required for Example 2. Please install it.")
235+
}
230236
if (!requireNamespace("cAIC4", quietly = TRUE)) {
231237
stop("Optional package 'cAIC4' is required for Example 2. Please install it.")
232238
}
233239

240+
library(tictoc)
241+
library(lme4)
242+
243+
234244
data(Zambia, package = "cAIC4")
235245
df <- as.data.frame(sapply(Zambia[1:5],scale))
236246

@@ -254,8 +264,6 @@ params$feat$pop.max = 10
254264
###############################################################
255265

256266
# lme4 version
257-
258-
library(lme4)
259267
mixed.model.loglik.lme4 <- function (y, x, model, complex, mlpost_params)
260268
{
261269

@@ -284,23 +292,16 @@ mixed.model.loglik.lme4 <- function (y, x, model, complex, mlpost_params)
284292
# 2.2 Small demonstration run for runtime comparisons
285293
###############################################################
286294

287-
set.seed(3052024)
288295

289-
library(tictoc)
296+
set.seed(03052024)
290297

291298
tic()
292-
result1a <- fbms(
293-
formula = z ~ 1+., data = df,
294-
transforms = transforms,
295-
method = "gmjmcmc", P = 3, N = 30,
296-
probs = gen.probs.gmjmcmc(transforms),
297-
params = gen.params.gmjmcmc(ncol(df) - 1),
298-
family = "custom",
299-
loglik.pi = mixed.model.loglik.lme4,
300-
model_prior = list(r = 1/nrow(df)),
301-
extra_params = list(dr = droplevels(Zambia$dr))
302-
)
303-
time.lme4 <- toc()
299+
result1a <- fbms(formula = z ~ 1+., data = df, transforms = transforms,
300+
method = "gmjmcmc",probs = probs, params = params, P=3, N = 30,
301+
family = "custom", loglik.pi = mixed.model.loglik.lme4,
302+
model_prior = list(r = 1/dim(df)[1]),
303+
extra_params = list(dr = droplevels(Zambia$dr)))
304+
time.lme4 = toc()
304305

305306

306307
cat(c(time.lme4$callback_msg))

0 commit comments

Comments
 (0)