2017-03-06 315 views
0
# load the library and data 
library('MASS') 
library('sqldf') 
data(fgl, package = 'MASS') 
df <- data.frame(fgl) 
# (a)select chosen glass types 
#adf <- sqldf("select * from df where type='WinF' or type='WinNF' or  type='Veh' or type='Head'") 
adf <- subset(df, type=="WinF"|type=="WinNF"|type=="Veh"|type=="Head") 

traindata <- adf[1:128,] 
testdata <- adf[129:192,] 
#typetesting <- adf$type[129:192,] 
# LDA 
# fit the qad model based on the training 
qdamodel = qda(type~RI+Na+Mg+Al+Si+K+Ca+Ba+Fe, data=traindata) 

太小,我有一個錯誤錯誤一些組是「QDA」

Error in qda.default(x, grouping, ...) : 
    some group is too small for 'qda' 

我同時使用sqldfsubset功能,但他們沒有工作。謝謝。

回答

2

變量type是6個級別的一個因素: 「Winf的」, 「輛」 頭」, 「WinNF」, 「精讀」 和 「TABL」 當你做到這一點。

adf <- subset(df, type=="WinF"|type=="WinNF"|type=="Veh"|type=="Head") 

你保持這些級別的行數爲4,但變量本身仍然有6級,所以剩餘的級別不在您的示例中,這是qda的投訴內容。回到字符變量中:

adf$type <- as.character(adf$type) 

然後再做剩下的分析。