[英]Error while running DFA in R at the predict function
I'm attempting to run a cv DFA on a set of species X site data (species are columns, sites are rows) with a grouping row named "ZONE". 我正在尝试使用名为“ ZONE”的分组行在一组物种X站点数据(物种是列,站点是行)上运行CV DFA。
I'm using a stock script I've successfully used before, but now I'm getting a new error from the predict function that I can't make heads or tails of. 我使用的是以前成功使用过的股票脚本,但是现在我从无法实现正负的预测函数中收到一个新错误。
My code is simply: 我的代码很简单:
data2.lda<-lda(ZONE~SP1+SP2+SP3+SP4+SP5+SP6+SP7+SP8+SP9+SP10+SP11+SP12+SP13+SP14+SP15
,data=data2.x, Cna.action="na.omit",CV=TRUE)
list(data2.lda)
data2.lda.p<-predict(data2.lda,newdata=data2.lda.x(,c[2:17]))$class
data2.lda.p
the error I receive is: 我收到的错误是:
Error in UseMethod("predict") : no applicable method for 'predict' applied to an object of class "list"
UseMethod(“ predict”)中的错误:没有适用于“预测”的适用方法应用于“列表”类的对象
My data are in the same form as previous uses of this code. 我的数据与该代码以前的用法相同。 Where did I go wrong?
我哪里做错了? Any help is appreciated, thanks!
任何帮助表示赞赏,谢谢!
UPDATE: I've figured out that the issue involves the cross validation portion of the code. 更新:我发现问题涉及代码的交叉验证部分。 Are there additional rules for cross validating an LDA that I'm missing when it comes to coding in R?
在使用R编码时,是否还有其他规则可以交叉验证我所缺少的LDA?
Your problem is that predict
requires a model object for its first argument. 您的问题是,
predict
需要为其第一个参数使用模型对象。 When you run lda
with the CV=T
option, it returns a list object not a model object. 当您使用
CV=T
选项运行lda
时,它将返回一个列表对象而不是模型对象。 The lda
documentation says lda
文档说
If CV = TRUE the return value is a list with components class, the MAP classification (a factor), and posterior, posterior probabilities for the classes.
如果CV = TRUE,则返回值是包含组件类别,MAP分类(一个因子)以及类别的后验概率和后验概率的列表。
Otherwise it is an object of class "lda" containing the following components:
否则,它是包含以下组件的“ lda”类的对象:
As per PCantalupo's answer, I managed to arrive at my goal. 根据PCantalupo的回答,我设法实现了自己的目标。 The cross validation procedure needs to be applied during the predict model, not the original model.
需要在预测模型而不是原始模型中应用交叉验证过程。 The functional code is:
功能代码为:
data2.lda<-lda(ZONE~SP1+SP2+SP3+SP4+SP5+SP6+SP7+SP8+SP9+SP10+SP11+SP12+SP13+SP14+SP15
,data=data2.x, Cna.action="na.omit")
list(data2.lda)
data2.lda.p<-predict(data2.lda,CV=TRUE,newdata=data1[c(2:17)])$class
data2.lda.p
tab<-table(data2.lda.p,data2[,1])
tab
summary(table(data2.lda.p,data2[,1]))
diag(prop.table(tab,1))
sum(diag(prop.table(tab)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.