Running R function jags on cluster - r

I am trying to run a R program on cluster. In the R program,jags function is called from the package R2jags. If I don't use the cluster and simply use R, then the program works fine. However, when I try to submit a job, then I get the following error. If I don't call the function jags and use the cluster then it works just fine.
Loading required package: rjags
Loading required package: coda
Linked to JAGS 4.0.0
Loaded modules: basemod,bugs
Attaching package: ‘R2jags’
The following object is masked from ‘package:coda’:
traceplot
*** caught illegal operation ***
address 0x7fe566be8917, cause 'illegal operand'
Traceback:
1: dyn.load(file)
2: load.module(jags.module[m])
3: jags(model.file = "myfile.txt", data = model.data, inits = model.initial.values, parameters = model.parameters, n.chains = 1, n.iter = 500, n.burnin = 5, n.thin = 5)
An irrecoverable exception occurred. R is aborting now ...
line 15: 34161 Illegal instruction (core dumped) Rscript test1.R

Related

Why does running the tutorial example fail with Rstan?

I installed the RStan successfully, the library loads. I try to run a tutorial example (https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started#example-1-eight-schools). After applying the stan function
fit1 <- stan(
file = "schools.stan", # Stan program
data = schools_data, # named list of data
chains = 4, # number of Markov chains
warmup = 1000, # number of warmup iterations per chain
iter = 2000, # total number of iterations per chain
cores = 1, # number of cores (could use one per chain)
refresh = 0 # no progress shown
)
I get the following error:
*Error in compileCode(f, code, language = language, verbose = verbose) :
C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file1c34165764a4.o:file1c34165764a4.cpp:(.text$_ZN3tbb8internal26task_scheduler_observer_v3D0Ev[_ZN3tbb8internal26task_scheduler_observer_v3D0Ev]+0x1d): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file1c34165764a4.o:file1c34165764a4.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x1d): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file1c34165764a4.o:file1c34165764a4.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x3a): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file1c34165764a4.o:file1c34165764a4.cpp:(.text$_ZN3tbb10interface
Error in sink(type = "output") : invalid connection*
Simply running example(stan_model, run.dontrun=T) gives the same error.
What does this error mean?
Is rtools wrongly installed? My PATH seems to contain the correct folder C:\\rtools42\\x86_64-w64-mingw32.static.posix\\bin;. Is something wrong with the version of my Rstan package? I am struggling to interpret this error?
What to try to solve it?
Apparently Rtools42 in incompatible with the current version Rstan on CRAN. The solution that worked for me is found here: https://github.com/stan-dev/rstan/wiki/Configuring-C---Toolchain-for-Windows#r-42

JAGS not recognizing values stored in R's global environment

I'm running JAGS with R v3.6.1 and Rstudio v1.2 in Windows 10, using package R2jags. JAGS does not appear to find the stored values that I've created in R for MCMC settings such as n.iter, n.burn-in, etc. because my code:
out2 <- jags.parallel (data = data, inits = inits, parameters.to.save = parameters,
model.file = "C:\\Users\\jj1995\\Desktop\\VIP\\Thanakorn\\DLM\\district model.txt", n.chains = n.chain,
n.thin = n.thin, n.iter = n.iter, n.burnin = n.burn)
Produces the error
Error in checkForRemoteErrors(lapply(cl, recvResult)) :
3 nodes produced errors; first error: object 'n.burn' not found
If I replace a stored value's name with a number (n.burnin = 10000), it will return the same error, but for a different MCMC setting. I assume JAGS will also be unable to find the lists and dataframes I've stored in the global environment also. I thought my system's firewall was preventing JAGS from accessing the global environment, so I disabled my antivirus measures and I ran both R and Rstudio as an administrator. This did not solve the problem.

doparallel package in caret train model under linux

I have a problem when I run the train function in caret with parallel processing, for example, when I run a simple R code like:
library(doParallel); cl <- makeCluster(4);
registerDoParallel(cl)
require(caret);data(BloodBrain);
set.seed(123)
fit1 <- train(bbbDescr, logBBB, "knn"); fit1
stopCluster(cl); registerDoSEQ();
I get this error message
Error in e$fun(obj, substitute(ex), parent.frame(), e$data) :
worker initialization failed: there is no package called ‘caret’
I installed last vesion of caret under R 3.3.0.
I installed the R version and caret version on windows, it is work.
any one have any suggestion about this??

R Leaps Package: Regsubsets - coef "Reordr" Fortran error

I'm using the R leaps package to obtain a fit to some data:
(My dataframe df contains a Y variable and 41 predictor variables)
require(leaps)
N=3
regsubsets(Y ~ ., data = df, nbest=1, nvmax=N+1,force.in="X", method = 'exhaustive')-> regfit
coef(regfit,id = N)
When I run the code more than once (the first time works fine) I get the following error when I run the coef command:
Error in .Fortran("REORDR", np = as.integer(object$np), nrbar = as.integer(object$nrbar), :
"reordr" not resolved from current namespace (leaps)
Any help with why this is happening would be much appreciated.
A.
I had to build the package from source inserting the (PACKAGE = 'leaps') argument into the REORDR function in the leaps.R file. It now works fine every time.
The solution is related to:
R: error message --- package error: "functionName" not resolved from current namespace

Locked package namespace

I am using the "BMA" package in R 3.1.0, and get an error when running one of the functions in the package, iBMA.glm. When running the example in the package documentation:
## Not run:
############ iBMA.glm
library("MASS")
library("BMA")
data(birthwt)
y<- birthwt$lo
x<- data.frame(birthwt[,-1])
x$race<- as.factor(x$race)
x$ht<- (x$ht>=1)+0
x<- x[,-9]
x$smoke <- as.factor(x$smoke)
x$ptl<- as.factor(x$ptl)
x$ht <- as.factor(x$ht)
x$ui <- as.factor(x$ui)
### add 41 columns of noise
noise<- matrix(rnorm(41*nrow(x)), ncol=41)
colnames(noise)<- paste('noise', 1:41, sep='')
x<- cbind(x, noise)
iBMA.glm.out<- iBMA.glm( x, y, glm.family="binomial",
factor.type=FALSE, verbose = TRUE,
thresProbne0 = 5 )
summary(iBMA.glm.out)
I get the error:
Error in registerNames(names, package, ".__global__", add) :
The namespace for package "BMA" is locked; no changes in the global variables list may be made.
I get the error in RStudio running R 3.1.0 on Ubuntu.
on Windows 7, from RStudio and the R console I get a similar error:
Error in utils::globalVariables(c("nastyHack_glm.family", "nastyHack_x.df")) :
The namespace for package "BMA" is locked; no changes in the global variables list may be made.
I also get the same error when running my own data in the function. I'm not clear on what this error means and how to work around the error to be actually able to use the function. Any advice would be appreciated!

Resources