-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpuhti_hmsc_mcmc.R
39 lines (30 loc) · 1.16 KB
/
puhti_hmsc_mcmc.R
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
#!/usr/bin/env Rscript
# set custom library path for Hmsc
.libPaths(c("/projappl/project_2001175/rpackages-r-env-singul-4.0.2", .libPaths()))
libpath <- .libPaths()[1]
library(Hmsc)
library(ape)
args = commandArgs(trailingOnly=TRUE)
# test if there are three arguments: if not, return an error
if (length(args)!=3) {
stop("Wrong number of arguments", call.=FALSE)
}
model_name <- as.character(args[1])
samples <- as.numeric(args[2])
thin <- as.numeric(args[3])
nChains <- 4
model <- readRDS(paste0("models_unfit/", as.character(model_name),
".rds"))
model <- sampleMcmc(model,
samples = samples,
thin=thin,
adaptNf=rep(ceiling(0.4*samples*thin),model$nr),
transient = ceiling(0.5*samples*thin),
nChains = nChains,
nParallel = nChains)
filename <- paste("models_fit/", model_name,
"_thin_", as.character(thin),
"_samples_", as.character(samples),
"_chains_", as.character(nChains),
".rds", sep = "")
saveRDS(model, filename)