2017-03-06 305 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) 

然后再做剩下的分析。