问题
In this example (from here), the remote-sensing data are used. In this data set, the observations are grouped into five crops: clover, corn, cotton, soybeans, and sugar beets. Four measures called x1 through x4 make up the descriptive variables.
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
')
Adjusting a discriminant function with all the X variables:
library(MASS)
cropLda <- lda(dat[,-1],dat[,1])
With this plot
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)
How can I extract the Linear Discriminant Function for Crop (sas output table)
来源:https://stackoverflow.com/questions/30495710/linear-discriminant-analysis