doparallel package in caret train model under linux - r

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??

Related

Installing caret package in R

When I tried to load package of "caret" for my logistic regression model in R, the error message says "package or namespace load failed for ‘caret’.....". Is it an issue of my R version? I have 1.1.456 version.
install.packages("caret")
library(caret)
crossValSettings <- trainControl(method = "repeatedcv", number = 10,savePredictions = TRUE)

How to use 2 different functions in 2 different libraries that have the same name

I'm trying to explore the difference in how the gam function works in the mgcv package versus the gam package. But I'm not able to run both gam functions in one R session. I thought if I preface with mgcv::gam or gam::gam it would be able to run the right function, but it looks like I have to detach mgcv in order to run the gam function in the gam package.
library(ISLR)
library(mgcv)
library(gam)
# I get an error message when it runs this
gam.m3 <- gam::gam(wage~s(year,4)+s(age,5)+education,data=Wage)
# No error message when I detach mgcv
detach(package:mgcv)
gam.m3 <- gam::gam(wage~s(year,4)+s(age,5)+education,data=Wage)
Is there a way I can run both gam functions in one session?
Below is the output:
> library(ISLR)
> library(mgcv)
> library(gam)
> #I get an error message when it runs this
> gam.m3 <- gam::gam(wage~s(year,4)+s(age,5)+education,data=Wage)
Error in terms.formula(reformulate(term[i])) :
invalid model formula in ExtractVars
> #No error message when I detach mgcv
> detach(package:mgcv)
> gam.m3 <- gam::gam(wage~s(year,4)+s(age,5)+education,data=Wage)
Warning message:
In model.matrix.default(mt, mf, contrasts) :
non-list contrasts argument ignored
Update: I re-ran this with a clean R session and the story is different. Before, I cleared the workspace but did not have a clear R session. Now, if I run with a clean session the gam.m3 model seems to work. BUT - if I change the order of the library load, and load gam before mgcv, I get the same error. When mgcv is loaded after gam is loaded, I do get this message:
The following objects are masked from ‘package:gam’:
gam, gam.control, gam.fit, s
So I guess just part of the deal of loading mgcv is that you can no longer use certain functions in gam? That is annoying. FYI I get the analogous warning message when loading gam after mgcv is loaded - that certain objects will be masked from package:mgcv.
As shown in my answer to your other question, you can't use gam::s.
However, you can tell R to evaluate the call in the gam package namespace:
library(ISLR)
library(gam)
fit1 <- gam(wage~s(year,4)+s(age,5)+education,data=Wage)
library(mgcv)
gam::gam(wage~s(year,4)+s(age,5)+education,data=Wage)
#errors
fit2 <- eval(quote(gam(wage~s(year,4)+s(age,5)+education,data=Wage)),
envir = asNamespace("gam"))
#works
all.equal(coef(fit1), coef(fit2))
#[1] TRUE

Calling newDArch in darch package

I am reading Learning bayes model with R, and I installed darch package. I get an error when running below code
library(darch)
darch <- newDArch(c(2,4,1),batchSize = 2,genWeightFunc = generateWeights)
The error is Error: could not find function "newDArch"
Can someone help me. Thank!

Running GAM function from mgcv package with R 3.2.2

I have recently run into a problem running a GAM model from a previously working code. I believe it is related to an updated R-Version and an updated Version of the mgcv package. It would be great to know if anyone has the same problem or has a solution to it.
I am currently running R version 3.2.2 (2015-08-14) -- "Fire Safety"
on Windows. I am using the mgcv Package 1.8-7. Below is an example code that re-produces the error message, when run on my computer.
###Load package
library(mgcv)
This is mgcv 1.8-7.
###Simulate some example data
set.seed(2) ## simulate some data...
dat <- gamSim(1,n=400,dist="normal",scale=2)
###Run normal model
b <- gam(y~s(x0)+s(x1)+s(x2)+s(x3),data=dat, family=gaussian())
This works.
###change the smoothness selection method to REML
b0 <- gam(y~s(x0)+s(x1)+s(x2)+s(x3),data=dat,method="REML")
Gives the following error message:
Error in .C(C_gdi1, X = as.double(x[good, ]), E = as.double(Sr), Eb = as.double(Eb), : Incorrect number of arguments (48), expecting 47 for 'gdi1'
Thanks for your help!
I have re-installed R and the mgcv package and it seems as if this has resolved the issue.

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