线性判别分析

时间:2015-05-28 01:23:23

标签: r multivariate-testing

在此示例中(来自here),使用遥感数据。在该数据集中,观察结果分为五种作物:三叶草,玉米,棉花,大豆和甜菜。称为x1到x4的四个度量组成了描述性变量。

dat <- read.table(header=T, text='
Crop       x1 x2 x3 x4
Corn       16 27 31 33
Corn       15 23 30 30
Corn       16 27 27 26
Corn       18 20 25 23
Corn       15 15 31 32
Corn       15 32 32 15
Corn       12 15 16 73
Soybeans   20 23 23 25
Soybeans   24 24 25 32
Soybeans   21 25 23 24
Soybeans   27 45 24 12
Soybeans   12 13 15 42
Soybeans   22 32 31 43
Cotton     31 32 33 34
Cotton     29 24 26 28
Cotton     34 32 28 45
Cotton     26 25 23 24
Cotton     53 48 75 26
Cotton     34 35 25 78
Sugarbeets 22 23 25 42
Sugarbeets 25 25 24 26
Sugarbeets 34 25 16 52
Sugarbeets 54 23 21 54
Sugarbeets 25 43 32 15
Sugarbeets 26 54  2 54
Clover     12 45 32 54
Clover     24 58 25 34
Clover     87 54 61 21
Clover     51 31 31 16
Clover     96 48 54 62
Clover     31 31 11 11
Clover     56 13 13 71
Clover     32 13 27 32
Clover     36 26 54 32
Clover     53 08 06 54
Clover     32 32 62 16
')

使用所有X变量调整判别函数:

library(MASS)
cropLda <- lda(dat[,-1],dat[,1])

有了这个情节

cropProjection <- cbind(scale(as.matrix(dat[,-1]), scale=FALSE) %*% cropLda$scaling,dat[,1,drop=FALSE])

cropProjection$row_num = 1:nrow(cropProjection)
p <- ggplot(data=cropProjection, aes(x=LD1,y=LD2, col=Crop)) + 
  geom_point() + geom_text(aes(label = row_num))
print(p)

enter image description here

如何提取裁剪的线性判别函数 (sas输出表)

enter image description here

0 个答案:

没有答案