Home > database >  Problems with partimat plot in R
Problems with partimat plot in R

Time:07-12

I am trying to plot an LDA analysis using partimat function from klaRpackage in R and I am getting this warning message Error in partimat.default(x, grouping, ...) : at least two classes required I am pasting here part of the data to make a reproducible example:

  abrev Linfoprolif CORT Testo  FDL Ac.GRO ifn.g il.4
1       A        2.00 0.53  1.54 1.65      8   192   68
2       A       13.91 0.65  1.34 2.27      6   195   58
3       A       15.65 0.50  0.07 0.97      5   280   67
4       A        4.96 1.51  1.45 2.54      3    30   48
5       A        0.00 3.18  0.01 0.95      3    60   71
6       A       36.23 0.28  0.88 3.63      7   320   50
7       A        9.15 1.20  0.16 1.32      1    52   74
8       A       17.63 1.68  1.29 1.86      1    47   53
9       A        6.52 2.36  0.03 0.92      4    51   75
113     B       20.48 0.38  1.27 2.40      4   278   52
114     B       12.10 0.83  0.11 0.53      2   146   41
115     B       61.56 0.07  0.09 1.09      9   305   52
116     B       35.06 0.59  0.05 0.67      4   220   54
117     B       33.48 0.68  0.99 1.24      3   102   58
118     B       20.56 0.94  0.06 1.71      3    58   45
119     B       26.46 0.12  0.29 1.60      3   210   55
120     B       24.91 0.56  0.11 0.55      5   108   56
121     B       29.22 0.42  2.60 1.55      3    84   69
122     B       19.30 1.63  0.02 0.78      3    62   69
123     B       14.45 0.22  0.79 1.89      4   245   59
373     D       27.13 0.23  1.03  4.23     6   261  100
374     D        0.00 0.43  0.08 15.34     1    58   69
375     D       17.42 0.27  2.07  7.09     5   184   80
376     D       37.34 0.91  0.08  6.18     6   210   81
377     D       28.19 0.20  3.34  6.82     6   269  105
378     D        8.53 0.61  0.05  5.31     4    98  115

I followed the code posted here like this: partimat(abrev ~ Linfoprolif CORT Testo FDL Ac.GRO, ifn.g ifn.g, data=d_e_disc, method="lda")

I can't find my error. Any help is wecome

CodePudding user response:

Your response variable abrev must be factor , so you have to make it of class factor

d_e_disc $abrev <- as.factor(d_e_disc $abrev)

# then apply your code above

CodePudding user response:

@Mohamed Desouky found your problem, abrev should be a factor! Also, there is a small typo in your formula (","), So here you can see a reproducible example to make sure you can reproduce your problem:

library(klaR)
partimat(factor(abrev) ~ Linfoprolif   CORT   Testo   FDL Ac.GRO   ifn.g   ifn.g, data=d_e_disc, method="lda")

Created on 2022-07-11 by the reprex package (v2.0.1)

  •  Tags:  
  • r lda
  • Related