无法为签名'“mids”,“numeric”找到函数'complete'的继承方法

时间:2018-03-23 01:19:57

标签: r

我刚刚用conda安装了Rstudio和R,我正在尝试按照本教程: https://www.analyticsvidhya.com/blog/2016/03/tutorial-powerful-packages-imputing-missing-values/

我一直跑到这一步

> completeData <- complete(imputed_Data,2)

我收到了错误:

  

(函数(classes,fdef,mtable)中的错误:无法找到   用于签名'“mids”的函数'complete'的继承方法,   “数字”'

它与我如何安装R有什么关系?你知道怎么解决吗?感谢。

更多信息

> R.Version()$version.string
[1] "R version 3.4.3 (2017-11-30)"
> packageVersion("mice")
[1] '2.46.0'

我尝试了traceback()

> traceback()
3: stop(gettextf("unable to find an inherited method for function %s for signature %s", 
       sQuote(fdef@generic), sQuote(cnames)), domain = NA)
2: (function (classes, fdef, mtable) 
   {
       methods <- .findInheritedMethods(classes, fdef, mtable)
       if (length(methods) == 1L) 
           return(methods[[1L]])
       else if (length(methods) == 0L) {
           cnames <- paste0("\"", vapply(classes, as.character, 
               ""), "\"", collapse = ", ")
           stop(gettextf("unable to find an inherited method for function %s for signature %s", 
               sQuote(fdef@generic), sQuote(cnames)), domain = NA)
       }
       else stop("Internal error in finding inherited methods; didn't return a unique method", 
           domain = NA)
   })(list("mids", "numeric"), function (y, m, ...) 
   standardGeneric("complete"), <environment>)
1: complete(imputed_Data, 2)

> class(imputed_Data)
[1] "mids"

有关完整信息:

我运行的代码是:

library("mice")
library("Amelia")
library("Hmisc")
library("mi")
library("missForest")


data <- iris
iris.mis <- prodNA(iris, noNA = 0.1)
imputed_Data <- mice(iris.mis, m=5, maxit = 50, method = 'pmm', seed = 500)
completeData <- complete(imputed_Data,2)

完整的输出是:

> library("mice")
Loading required package: lattice
> library("Amelia")
Loading required package: Rcpp
## 
## Amelia II: Multiple Imputation
## (Version 1.7.4, built: 2015-12-05)
## Copyright (C) 2005-2018 James Honaker, Gary King and Matthew Blackwell
## Refer to http://gking.harvard.edu/amelia/ for more information
## 
> library("Hmisc")
Loading required package: survival
Loading required package: Formula
Loading required package: ggplot2

Attaching package: 'Hmisc'

The following objects are masked from 'package:base':

    format.pval, units

> library("mi")
Loading required package: Matrix
Loading required package: stats4
mi (Version 1.0, packaged: 2015-04-16 14:03:10 UTC; goodrich)
mi  Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Trustees of Columbia University
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under the General Public License version 2 or later.
Execute RShowDoc('COPYING') for details.

Attaching package: 'mi'

The following objects are masked from 'package:mice':

    complete, pool

> library("missForest")
Loading required package: randomForest
randomForest 4.6-12
Type rfNews() to see new features/changes/bug fixes.

Attaching package: 'randomForest'

The following object is masked from 'package:ggplot2':

    margin

Loading required package: foreach
Loading required package: itertools
Loading required package: iterators
> 
> 
> data <- iris
> iris.mis <- prodNA(iris, noNA = 0.1)
> imputed_Data <- mice(iris.mis, m=5, maxit = 50, method = 'pmm', seed = 500)

 iter imp variable
  1   1  Sepal.Length  Sepal.Width  Petal.Length  Petal.Width  Species
 ...
  50   4  Sepal.Length  Sepal.Width  Petal.Length  Petal.Width  Species
  50   5  Sepal.Length  Sepal.Width  Petal.Length  Petal.Width  Species
> completeData <- complete(imputed_Data,2)
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function 'complete' for signature '"mids", "numeric"'
> 

1 个答案:

答案 0 :(得分:0)

当查看具有名称引发错误的函数的文档时,需要查看已加载的包的“上游”。在该页面中使用我的浏览器搜索功能搜索library时,我看到:

 #install package and load library
> install.packages("Amelia")
> library(Amelia)

还有其他几个包。您需要查看在复制的代码之前加载的任何包。

===编辑====

complete函数实质上存在竞争方法。由于最后加载了mi包,因此调用了complete函数,但它与mice::complete函数略有不同,并且无法识别由{创建的类mids的对象{1}} - 功能。如果强制调用正确的函数,则不会出现错误:

mice