juba / explor

Interfaces for Multivariate Analysis in R
https://juba.github.io/explor/
193 stars 13 forks source link

ellipse #14

Closed mboussaa closed 7 years ago

mboussaa commented 7 years ago

I cannot put the confidence level on the plot using the ellispe. How is it possible?

juba commented 7 years ago

You mean change the ellipse's confidence level ? That's not possible for the moment.

Would it be something useful for you ?

mboussaa commented 7 years ago

Hi @juba, I was not may be clear. I was wondering if it was possible to draw the ellipse's confidence level in my PCA individuals scrore plot... Actually, there is no option I can enable to show it

ju
juba commented 7 years ago

Ellipses in explor are only used when you color your points according to their type (active / supplementary) or by the levels of a qualitative supplementary variable. Ellipses are then optionally used to show the points repartition for each level.

So the option to show ellipses will only appear if you have supplementary individuals or supplementary qualitative variables in your PCA.

mboussaa commented 7 years ago

What I would do using explor is to to draw one confidence ellipse to detect the outliers (individuals outside the ellipse with very high variation) I don't have qualitative or supplementary variables for instance. Do you have any suggestion @juba ? Thank you

mboussaa commented 7 years ago

I would create for example 5 groups. Each group corresponds to a subset of my data with a label. I was thinking about using supplimentary qualitative variables to draw these 5 groups + corresponding ellipses. Is it possible?

juba commented 7 years ago

Yes, absolutely. Add your group variable as supplementary in your PCA, and you should be able to draw ellipses in explor. As for a way to detect outliers using confidence ellipses, I don't really know a way to do this.

megagrunt commented 7 years ago

Hi @juba, I added my group variable as supplementary in my PCA, yet explor won't show the groups in the individuals graph, in can't put colors or ellipses :

image

The groups appear in the variables graph as dots though :

image

Can you please help me on this issue ?

juba commented 7 years ago

Hmm that's strange. Did you try with the development version ? And if it still doesn't work, could you share the code you use to compute your PCA ?

megagrunt commented 7 years ago

I just tried with the development version and it still does not work. You will find enclosed the code i use to compute my PCA. There is not much, i do just use the PCA function of the FactoMineR package. I don't know if it is really usefull but i also joined the data table used for the PCA.

> don
              BAB          BAC          BAF          BAO          BAP          BBA OP
CF1   0.000000798 0.0000000000 0.0000020000 0.0000000000 0.0000000000 0.0000003990  1
CF2   0.000000562 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000  2
CF3   0.000002750 0.0000002120 0.0000046600 0.0000000000 0.0000000000 0.0000004230  3
CF6   0.000000883 0.0000000000 0.0000000981 0.0000000000 0.0000000000 0.0000000981  6
CC1   0.000012100 0.0000016200 0.0000138000 0.0000015400 0.0000006840 0.0000020500  1
CC2   0.000005750 0.0000003030 0.0000194000 0.0000027300 0.0000021200 0.0000093900  2
CC5   0.000020100 0.0000000000 0.0000240000 0.0000008720 0.0000008720 0.0000065400  5
CC6   0.000008380 0.0000017100 0.0000202000 0.0000012000 0.0000000000 0.0000063300  6
CC8   0.000011900 0.0000000000 0.0000195000 0.0000000000 0.0000000000 0.0000008470  8
CC9   0.000009340 0.0000027900 0.0000055800 0.0000005370 0.0000003220 0.0000016100  9
Cor1  0.000002680 0.0000000925 0.0000057300 0.0000001850 0.0000000000 0.0000024000  1
Cor2  0.000003410 0.0000004350 0.0000070000 0.0000005070 0.0000006890 0.0000022100  2
Cor6  0.000000669 0.0000000502 0.0000018200 0.0000000251 0.0000000251 0.0000003180  6
Cor8  0.000007410 0.0000000000 0.0000094100 0.0000006660 0.0000007490 0.0000019100  8
CMO2  0.000014500 0.0000000000 0.0000205000 0.0000000000 0.0000003160 0.0000037900  2
CMO3  0.000004860 0.0000008090 0.0000146000 0.0000000000 0.0000000000 0.0000154000  3
CMO6  0.000007960 0.0000007070 0.0000087600 0.0000000000 0.0000000000 0.0000011300  6
Dar1  0.000008110 0.0000005070 0.0000120000 0.0000003380 0.0000001690 0.0000010100  1
Dar2  0.000006800 0.0000000000 0.0000109000 0.0000004950 0.0000004950 0.0000136000  2
Dar5  0.000011400 0.0000005160 0.0000114000 0.0000015500 0.0000005160 0.0000098000  5
Dar8  0.000014200 0.0000000000 0.0000283000 0.0000037800 0.0000018900 0.0000018900  8
DC1   0.000005660 0.0000008710 0.0000080500 0.0000015200 0.0000013100 0.0000100000  1
DC2   0.000004800 0.0000006850 0.0000305000 0.0000006850 0.0000010300 0.0000110000  2
DC6   0.000007010 0.0000006680 0.0000180000 0.0000000000 0.0000000000 0.0000020000  6
DC8   0.000004910 0.0000000000 0.0000038200 0.0000000000 0.0000008190 0.0000117000  8
Fra2  0.000000000 0.0000000000 0.0000123000 0.0000000000 0.0000000000 0.0000129000  2
Fra6  0.000005630 0.0000005970 0.0000085300 0.0000001710 0.0000000000 0.0000017100  6
Fra8  0.000004600 0.0000007670 0.0000222000 0.0000007670 0.0000007670 0.0000084400  8
Gen2  0.000006100 0.0000000000 0.0000033300 0.0000000000 0.0000002770 0.0000111000  2
Gen6  0.000005740 0.0000004100 0.0000344000 0.0000000000 0.0000000000 0.0000024600  6
Gri1  0.000014800 0.0000015400 0.0000300000 0.0000025700 0.0000018900 0.0000030900  1
Gri2  0.000002240 0.0000002430 0.0000081300 0.0000001820 0.0000002430 0.0000012700  2
Gri5  0.000012600 0.0000015800 0.0000174000 0.0000015800 0.0000015800 0.0000182000  5
Gri6  0.000001730 0.0000000230 0.0000024600 0.0000001150 0.0000000461 0.0000017500  6
Jon1  0.000009420 0.0000015400 0.0000084600 0.0000005770 0.0000005770 0.0000034600  1
Jon2  0.000004090 0.0000008180 0.0000028600 0.0000000000 0.0000000000 0.0000057300  2
Jon4  0.000000988 0.0000000000 0.0000050800 0.0000000000 0.0000000000 0.0000039500  4
Jon6  0.000002160 0.0000007190 0.0000024000 0.0000000000 0.0000000000 0.0000014400  6
L(3)2 0.000036100 0.0000024600 0.0000312000 0.0000016400 0.0000016400 0.0000082100  2
L(3)6 0.000009420 0.0000015700 0.0000317000 0.0000009420 0.0000000000 0.0000025100  6
L(3)9 0.000013300 0.0000028400 0.0000094800 0.0000000000 0.0000000000 0.0000000000  9
L(9)1 0.000012100 0.0000038200 0.0000124000 0.0000009000 0.0000004500 0.0000072000  1
L(9)2 0.000005350 0.0000005040 0.0000067600 0.0000003030 0.0000001010 0.0000006050  2
L(9)6 0.000003790 0.0000001110 0.0000019100 0.0000000000 0.0000000000 0.0000014400  6
Mey1  0.000003800 0.0000004950 0.0000031000 0.0000001870 0.0000000881 0.0000007050  1
Mey2  0.000000586 0.0000000451 0.0000033300 0.0000000000 0.0000000000 0.0000009010  2
Mey3  0.000003630 0.0000008060 0.0000076500 0.0000000000 0.0000004030 0.0000088600  3
Mey6  0.000002880 0.0000007200 0.0000101000 0.0000001440 0.0000000000 0.0000014400  6
Mey7  0.000008710 0.0000022700 0.0000071900 0.0000000000 0.0000000000 0.0000071900  7
Mey8  0.000001510 0.0000004230 0.0000054600 0.0000005650 0.0000003290 0.0000019800  8
Mio1  0.000012400 0.0000012000 0.0000047900 0.0000000000 0.0000000000 0.0000036000  1
Mio2  0.000000372 0.0000000000 0.0000208000 0.0000000000 0.0000000000 0.0000000000  2
NS1   0.000008050 0.0000029300 0.0000227000 0.0000007320 0.0000000000 0.0000000000  1
NS2   0.000001040 0.0000006060 0.0000078000 0.0000000000 0.0000000000 0.0000002600  2
NS6   0.000001270 0.0000004770 0.0000103000 0.0000000000 0.0000000000 0.0000001590  6
Oul1  0.000010200 0.0000051200 0.0000200000 0.0000004260 0.0000008530 0.0000012800  1
Oul2  0.000007450 0.0000005730 0.0000207000 0.0000008020 0.0000006870 0.0000012600  2
Oul6  0.000004520 0.0000000000 0.0000155000 0.0000004720 0.0000004720 0.0000002020  6
RP1   0.000014900 0.0000011900 0.0000128000 0.0000006600 0.0000002640 0.0000052800  1
RP2   0.000011300 0.0000017600 0.0000159000 0.0000002520 0.0000000000 0.0000083100  2
RP3   0.000006090 0.0000000000 0.0000094000 0.0000000000 0.0000000000 0.0000027700  3
RP6   0.000008350 0.0000096000 0.0000284000 0.0000004170 0.0000000000 0.0000075100  6
RP7   0.000025300 0.0000055700 0.0000497000 0.0000000000 0.0000006430 0.0000103000  7
SCMO1 0.000007620 0.0000007620 0.0000163000 0.0000000000 0.0000000000 0.0000068600  1
SCMO2 0.000017800 0.0000000000 0.0000235000 0.0000006340 0.0000006340 0.0000063400  2
SCMO5 0.000009560 0.0000000000 0.0000262000 0.0000005030 0.0000000000 0.0000010100  5
SCMO6 0.000006070 0.0000004140 0.0000027600 0.0000000000 0.0000000000 0.0000011000  6
SP1   0.000012700 0.0000011200 0.0000195000 0.0000071100 0.0000018700 0.0000138000  1
SP2   0.000001290 0.0000000000 0.0000018500 0.0000000000 0.0000000000 0.0000008040  2
SP3   0.000012100 0.0000089000 0.0000210000 0.0000000000 0.0000000000 0.0000000000  3
SP6   0.000005040 0.0000005040 0.0000070600 0.0000000000 0.0000000000 0.0000035300  6
SFL1  0.000017200 0.0000014300 0.0000459000 0.0000043000 0.0000017900 0.0000039400  1
SFL5  0.000009360 0.0000000000 0.0000315000 0.0000051100 0.0000017000 0.0000025500  5
SFL8  0.000013600 0.0000000000 0.0000159000 0.0000003690 0.0000007370 0.0000036900  8
VV1   0.000009760 0.0000000000 0.0000195000 0.0000004650 0.0000002320 0.0000004650  1
VV4   0.000009690 0.0000002780 0.0000026800 0.0000001850 0.0000000309 0.0000001540  4
VV5   0.000006990 0.0000000000 0.0000220000 0.0000020000 0.0000009980 0.0000049900  5
VV6   0.000004500 0.0000022500 0.0000300000 0.0000000000 0.0000000000 0.0000000000  6
VV8   0.000012200 0.0000000000 0.0000338000 0.0000000000 0.0000021500 0.0000007180  8
Vil1  0.000003290 0.0000001430 0.0000194000 0.0000014300 0.0000010700 0.0000017100  1
Vil2  0.000006480 0.0000006820 0.0000286000 0.0000003410 0.0000005970 0.0000011100  2
Vil4  0.000003720 0.0000007970 0.0000043900 0.0000001330 0.0000000000 0.0000002660  4
Vil6  0.000003460 0.0000005380 0.0000171000 0.0000003840 0.0000000768 0.0000011500  6
Vil9  0.000019300 0.0000010900 0.0000277000 0.0000037700 0.0000001450 0.0000005790  9
> pc<-PCA(don,scale.unit=TRUE,quali.sup=7)
mboussaa commented 7 years ago

I got the same issue yesterday as @megagrunt

juba commented 7 years ago

@megagrunt can you tell me the result of

lapply(don, class)
megagrunt commented 7 years ago
> lapply(don, class)
$BAB
[1] "numeric"

$BAC
[1] "numeric"

$BAF
[1] "numeric"

$BAO
[1] "numeric"

$BAP
[1] "numeric"

$BBA
[1] "numeric"

$OP
[1] "integer"
juba commented 7 years ago

And does it work with the following code ?

don$OP <- factor(don$OP)
pc <- PCA(don, scale.unit = TRUE, quali.sup = 7)
explor(pc)
megagrunt commented 7 years ago

It still does not work.

juba commented 7 years ago

Strange... Sorry, one more demand : could you do a :

save(don, file="don.Rdata")

And send me the don.Rdata file here ?

megagrunt commented 7 years ago

How do i manage to access the don.Rdata file ?

juba commented 7 years ago

Well, after using the save function, it should be in your R current working directory. If you don't know where it is, you can use the getwd() function.

megagrunt commented 7 years ago

don.zip

juba commented 7 years ago

Ok, this is quite strange, I just tested with your data, and I can color individual points depending on your quali.sup variable and draw ellipses without problem...

image

After several tests, it doesn't work with the current CRAN version, but it does with the Github one :

 devtools::install_github("juba/explor")

Are you sure it still doesn't work with the dev version for you ?

megagrunt commented 7 years ago

I does work actually, thank you very much !

juba commented 7 years ago

Ah, glad to hear it. Thanks to you for helping debugging this.

@mboussaa could you try with the development version too ? I close the issue for now, but you can reopen it if it stille doesn't work.

mboussaa commented 7 years ago

@juba I will check that. Thank you

mboussaa commented 7 years ago

In fact, to use the dev version How can I proceed ?

juba commented 7 years ago

Install the devtools package, and then run :

 devtools::install_github("juba/explor")
mboussaa commented 7 years ago

Perfect. Merci :)