0

I have a small doubt in R pertaining to LDA, Like in spss when i tried to get fishers classification function coefficients of linear discriminant analysis in R with the package MASS, I am getting only coefficients of linear discriminant like the following:

Coefficients of linear discriminants:

                     LD1        LD2             LD3            LD4
   Var1      0.018952518    0.010766163     0.534278507     -2.32E-02
   Var2     -0.000827315   -0.012934214    -0.013986988     -3.14E-01
   Var3     -3.616088667   -0.18684861     -2.962979702      1.36E-01
   Var4      0.000139365   -0.003802969     0.000313853      9.33E-05
   Var5      0.007675119    0.006891405     0.05536683      -9.69E-02


                 LD5            
   Var1        5.64E-02         
   Var2        6.04E-02         
   Var3       -3.69E-01         
   Var4       -3.40E-05         
   Var5       -4.92E-01

But I have 7 groups in my grouping variable, I need to get fishers classification function coefficients for each cluster of all five variables so that I can use them for further analysis in Excel.I intend to get similiar table add below:

Classification Function Coefficients

        Cluster             
               7          8         9      10       11          12      13
   Var1      .630       .580      .555   .571     .598        .714    .642
   Var2      .025       .028      .028   .029     .026        .029    .029
   Var3      .685       .684      .752   .681     .678        .695    .700
   Var4     1.019       .997     1.015   .998     1.023      1.033   1.033
   Var5    17.331     21.253    21.457 21.347     9.166      8.850   8.860
(Constant)-44.687    -57.762   -59.353-58.928   -36.337    -42.367 -42.744

So I want the same output like the above in R, Please help me out:

2 Answers2

4

You can modify the code Fiete suggested or you can use linDA from DiscriMine package;

library(DiscriMiner)
mylda = linDA(iris[,1:4], iris[,5])
summary(mylda)
mylda$functions

               setosa versicolor  virginica
constant     -86.30847 -72.852607 -104.36832
Sepal.Length  23.54417  15.698209   12.44585
Sepal.Width   23.58787   7.072510    3.68528
Petal.Length -16.43064   5.211451   12.76654
Petal.Width  -17.39841   6.434229   21.07911
1

If I understand your question correctly, this might be the solution to your problem:

Classification functions in linear discriminant analysis in R

The post provides a script which generates the classification function coefficients from the discriminant functions and adds them to the results of your lda() function as a separate table.

Community
  • 1
  • 1
Fiete
  • 41
  • 5
  • I ran the code that I found in ur link on my dataset, but I m not able to see the output. Could u guide me to get the classification coefficients table with ur code. – Chaitanya Krishna T Dec 09 '13 at 06:51
  • How did you run it? Did you call the function with the parameters it requires (`legendre.lda(x,groups)`)? Are you sure the data was processed correctly? Do you get an error message? If you table is called `table1`, the results are appended to the original results as `table1$class.funs`. If you did everything correctly, you should be able to see them if you type `print(table1$class.funs)`. – Fiete Dec 09 '13 at 09:53
  • u know i got the table but the thing is that here I need to get respective cluster numbers as col names and respective variable names as row names. and here in the table I m getting NA's for last two variables of each group.and the result should not contain grouping variable. i dont know why, could u help me. – Chaitanya Krishna T Dec 09 '13 at 13:15