我正在做一些迴歸分析,並且我遇到了MASS
庫中的lda
函數的一些奇怪行爲。具體而言,它似乎無法接受字符串,因爲它的參數是formula
。這對基地glm
功能來說似乎不成問題。我用iris
構建了一個小例子來說明這一點。上述爲什麼lda()不接受字符串,因爲它是'公式'參數?
library(MASS)
myForm<-"Species~Petal.Length"
# Disregard the warnings from this line, they're an artifact of the example. It works.
lgrIris<-glm(formula=myForm, data=iris, family="binomial")
# Breaks.
ldaIris<-lda(formula=myForm, data=iris)
最後一行拋出:
Error in lda.default(formula = myForm, data = iris) :
argument "x" is missing, with no default
其中,從documentation來看,似乎表明lda
並不認爲它已經提供了formula
說法。有誰知道這是爲什麼發生,或者如何解決它?
可以使用'as.formula':'LDA(式= as.formula(myForm的),數據=光圈) ' –
輝煌,謝謝。我對R相對比較陌生,不知道有一個本地的「公式」類型。 –