> x <- read.csv("数量化2類.csv")
> x
case x1 x2 group
1 1 1 1 1
2 2 1 2 1
3 3 1 2 1
4 4 1 2 1
5 5 1 3 1
6 6 2 1 1
7 7 2 1 1
8 8 2 1 2
9 9 2 2 2
10 10 2 3 1
11 11 2 3 2
12 12 3 1 2
13 13 3 2 2
14 14 3 3 2
15 15 3 3 2
>
> attach(x)
>
> #青木 ダミー変数版と一致: x1 x2 をfactor()
> install.packages(MASS)
> library(MASS)
>
> fx1=factor(x1)
> fx2=factor(x2)
> fy=factor(group)
>
>
> s3 <- lda(fy~fx1+fx2,data=x)
> print(s3)
Call:
lda(fy ~ fx1 + fx2, data = x)
Prior probabilities of groups:
1 2
0.5333333 0.4666667
Group means:
fx12 fx13 fx22 fx23
1 0.3750000 0.0000000 0.3750000 0.2500000
2 0.4285714 0.5714286 0.2857143 0.4285714
Coefficients of linear discriminants:
LD1
fx12 2.2703062
fx13 4.0575686
fx22 0.9081225
fx23 0.4154177
> table(x[,4],predict(s3)$class)
1 2
1 7 1
2 1 6
>
> print(predict(s3))
$class
[1] 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2
Levels: 1 2
$posterior
1 2
1 0.998067712 0.001932288
2 0.982661776 0.017338224
3 0.982661776 0.017338224
4 0.982661776 0.017338224
5 0.994708071 0.005291929
6 0.673202197 0.326797803
7 0.673202197 0.326797803
8 0.673202197 0.326797803
9 0.184363290 0.815636710
10 0.428457861 0.571542139
11 0.428457861 0.571542139
12 0.025924475 0.974075525
13 0.002911804 0.997088196
14 0.009592345 0.990407655
15 0.009592345 0.990407655
$x
LD1
1 -2.4313209
2 -1.5231984
3 -1.5231984
4 -1.5231984
5 -2.0159031
6 -0.1610146
7 -0.1610146
8 -0.1610146
9 0.7471079
10 0.2544031
11 0.2544031
12 1.6262477
13 2.5343702
14 2.0416655
15 2.0416655
> plot(predict(s3)$x,col=x$group)
>
> plot(fy,predict(s3)$x)
>
> plot(s3,dimen=1)