train function in caret is masked by same function in AMORE, cannot make “AMORE” method work using caret [duplicate]

StackOverflow https://stackoverflow.com//questions/21031099

  •  21-12-2019
  •  | 
  •  

Question

Here is code I ran in Rstudio:

library(caret)
set.seed(1)
demo <-data.frame(x1 = runif(100),x2 <- rnorm(100),y <- rbinom(100,1,0.3))
modelout <- try(train(y~.,data = demo,
                  method = "AMORE"),silent = FALSE)

The output looks like this:

Loading required package: AMORE
Attaching package: ‘AMORE’
The following object is masked from ‘package:caret’:
   train
Error in order(x$nhid) : argument 1 is not a vector
In addition: There were 50 or more warnings (use warnings() to see the first 50)

The warning message is related to the "train" function in "AMORE" package. if i type

>train

in the command window after I ran the above code, I get the body of this function which is apparent from the AMORE package.

function (net, P, T, Pval = NULL, Tval = NULL, error.criterium = "LMS", 
   report = TRUE, n.shows, show.step, Stao = NA, prob = NULL, 
   n.threads = 0L) 
{...
}
<environment: namespace:AMORE>

I searched my path and apparently AMORE is shown up before caret:

>search()

[1] ".GlobalEnv"        "package:AMORE"     "package:caret"     "package:ggplot2"           "package:lattice"  
 [6] "tools:rstudio"     "package:stats"     "package:graphics"  "package:grDevices" "package:utils"    
[11] "package:datasets"  "package:methods"   "Autoloads"         "package:base"

and below is my sessioninfo:

R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] AMORE_0.2-14    caret_6.0-21    ggplot2_0.9.3.1 lattice_0.20-24

loaded via a namespace (and not attached):
[1] car_2.0-19         codetools_0.2-8    colorspace_1.2-4   compiler_3.0.2     dichromat_2.0-0   
[6] digest_0.6.4       foreach_1.4.1      grid_3.0.2         gtable_0.1.2       iterators_1.0.6   
[11] labeling_0.2       MASS_7.3-29        munsell_0.4.2      nnet_7.3-7         plyr_1.8          
[16] proto_0.3-10       RColorBrewer_1.0-5 reshape2_1.2.2     scales_0.2.3       stringr_0.6.2     
[21] tools_3.0.2

How should I solve the problem so R will use the "train" function in "caret" rather than the one in "AMORE"? thanks for your time and thank you in advance for any help.

JT

Was it helpful?

Solution 2

I figured it out by create a copy of the function. Yes this is a namespace issue. if I redefined a function trainc <- caret::train, and use trainc rather train in the code the problem is solved. Just curious why cannnot direct use caret::train! thanks for SethB's help though.

OTHER TIPS

Specify the namespace.

caret::train()

library(caret)
set.seed(1)
demo <-data.frame(x1 = runif(100),x2 <- rnorm(100),y <- rbinom(100,1,0.3))
modelout <- try(caret::train(y~.,data = demo,
                  method = "AMORE"),silent = FALSE)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top