在R中运行LDA函数时继续出错,我正在使用LDA的MASS库

时间:2016-05-22 22:43:53

标签: r lda

我在R中遇到LDA功能有问题。任何帮助都会很棒!。

 > bond <- read.csv("BondRating.csv")
 > head(bond)

RATING OBS CODERTG LOPMAR LFIXCHAR LGEARRAT LTDCAP LLEVER LCASHLTD LACIDRAT LCURRAT LRECTURN LASSLTD

1    AAA ,  8,       1, -1.323,    0.998,   -0.936,  0.281,-0.042,   -0.187  0.001,   0.863,    1.349,   1.704,

2    AAA,   9,       1, -2.100,    1.516,   -1.654,  0.159, 0.251,    0.342,   -0.077,   0.347,    1.762,   2.515,

> lda(RATING~.,data = bond)

Error in lda.default(x, grouping, ...) : 

变量2似乎在组内是不变的

 'data.frame':  14 obs. of  13 variables:
$ RATING  : Factor w/ 7 levels "A","AA","AAA",..: 3 3 2 2 1 1 6 6 5 5 ...
$ OBS     : int  8 9 23 24 37 38 52 53 67 68 ...
$ CODERTG : int  1 1 2 2 3 3 4 4 5 5 ...
$ LOPMAR  : num  -1.32 -2.1 -1.74 -1.78 -1.7 ...
$ LFIXCHAR: num  0.998 1.516 1.626 1.153 3.691 ...
$ LGEARRAT: num  -0.936 -1.654 -1.207 -0.45 -3.155 ...
$ LTDCAP  : num  0.281 0.159 0.23 0.389 0.04 0.369 0.249 0.257 0.233 0.288 ...
$ LLEVER  : num  -0.042 0.251 -0.066 0.171 -0.936 0.013 -0.101 -0.049 -0.244 -0.024 ...
$ LCASHLTD: num  -0.187 0.342 -0.266 -0.898 1.573 ...
$ LACIDRAT: num  0.001 -0.077 -0.229 -0.073 0.122 0.07 -0.709 -0.225 0.022 -0.006 ...
$ LCURRAT : num  0.863 0.347 0.543 0.44 0.998 0.781 0.787 0.476 0.726 0.569 ...
$ LRECTURN: num  1.35 1.76 1.72 2.23 2.03 ...
$ LASSLTD : num  1.7 2.52 1.92 1.25 3.49 ...

1 个答案:

答案 0 :(得分:1)

删除CODERTG,冗余信息,因为它与RATING相同

 lda(RATING~OBS+CODERTG+LOPMAR+LFIXCHAR+LGEARRAT+LTDCAP+LLEVER+LCASHLTD+LACIDRAT+LCURRAT+LRECTURN+LASSLTD, data=bond)

Call:
lda(RATING ~ OBS + LOPMAR + LFIXCHAR + LGEARRAT + LTDCAP + LLEVER + 
LCASHLTD + LACIDRAT + LCURRAT + LRECTURN + LASSLTD, data = bond)

Prior probabilities of groups:
    A        AA       AAA         B        BA       BAA         C 
 0.1428571 0.1428571 0.1428571 0.1428571 0.1428571 0.1428571 0.1428571