factoGraph: Factorial graphs

Description Usage Arguments Details Author(s) See Also Examples

View source: R/factoGraph.R

Description

Realise all optimised factorial graphs

Usage

1
2
3
4
factoGraph(res, file = "", dim = 1:2, hab = NULL, ellipse = TRUE, Iselec = "contrib", 
           Vselec = "cos2", Rselec = "cos2", Cselec = "cos2", Mselec = "cos2", 
           Icoef = 1, Vcoef = 1, Rcoef = 1, Ccoef = 1, Mcoef = 1, 
           figure.title = "Figure", graph = TRUE, cex = 0.7, options = NULL)

Arguments

res

an object of class PCA, CA or MCA

file

the file path where to write the description in Rmarkdown language. If not specified, the description is written in the console.

dim

a 2 dimensional numerical vector giving the factorial dimensions to use for the representation (by default the first plane)

hab

a variable name or index to use to color the individuals (or rows) among the variable categories.

ellipse

a boolean : if TRUE, ellipses are plotted with the coloration of individuals (or rows).

Iselec

the individuals to select ; see the details section

Vselec

the variables to select ; see the details section

Rselec

the rows to select (for a CA res object) ; see the details section

Cselec

the columns to select (for a CA res object) ; see the details section

Mselec

the supplementary variables to select ; see the details section

Icoef

a numerical coefficient to adjust the individuals selection rule ; see the details section

Vcoef

a numerical coefficient to adjust the variables selection rule ; see the details section

Rcoef

a numerical coefficient to adjust the rows selection rule (for a CA res object) ; see the details section

Ccoef

a numerical coefficient to adjust the columns selection rule (for a CA res object) ; see the details section

Mcoef

a numerical coefficient to adjust the supplementary variables selection rule ; see the details section

figure.title

the text label to add before graph title

graph

a boolean : if TRUE, graphs are plotted.

cex

an optional argument for the generic plot functions, used to adjust the size of the elements plotted.

options

a character string that gives the output options fir the figures. If NULL, options="r, echo = FALSE, fig.align = 'center', fig.height = 3.5, fig.width = 5.5" for linux and Mac and options="r, echo = FALSE, fig.height = 3.5, fig.width = 5.5" for Windows

Details

The Iselec argument (respectively Vselec, Rselec or Cselec) is used in order to select a part of the elements that are drawn and described. For example, you can use either :
- Iselec = 1:5 then the individuals (respectively the variables, the rows or the columns) numbered 1 to 5 are drawn.
- Iselec = c("name1","name5") then the individuals (respectively the variables, the rows or the columns) named name1 and name5 are drawn.
- Iselec = "contrib 10" then the 10 active or illustrative individuals (respectively the variables, the rows or the columns) that have the highest contribution on the 2 dimensions of the plane are drawn.
- Iselec = "contrib" then the optimal number of active or illustrative individuals (respectively the variables, the rows or the columns) that have the highest contribution on the 2 dimensions of the plane are drawn.
- Iselec = "cos2 5" then the 5 active or illustrative individuals (respectively the variables, the rows or the columns) that have the highest cos2 on the 2 dimensions of the plane are drawn.
- Iselec = "cos2 0.8" then the active or illustrative individuals (respectively the variables, the rows or the columns) that have a cos2 higher to 0.8 on the plane are drawn.
- Iselec = "cos2" then the optimal number of active or illustrative individuals (respectively the variables, the rows or the columns) that have the highest cos2 on the 2 dimensions of the plane are drawn.

The Icoef argument (respectively Vcoef, Rcoef or Ccoef) is used in order to adjust the selection of the elements when based on Iselec = "contrib" or Iselec = "cos2". For example :
- if Icoef = 2, the threshold is 2 times higher, and thus 2 times more restrictive.
- if Icoef = 0.5, the threshold is 2 times lower, and thus 2 times less restrictive.

Author(s)

Simon Thuleau and Francois Husson

See Also

graphInd, graphHab, graphCA, graphVar, graphSup

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
require(FactoMineR)
data(decathlon)
res.pca = PCA(decathlon, quanti.sup = c(11:12), quali.sup = c(13), graph = FALSE)
factoGraph(res.pca)

## Not run: 
require(FactoMineR)
data(children)
res.ca = CA(children, row.sup = 15:18, col.sup = 6:8, graph = FALSE)
factoGraph(res.ca)

data(tea)
res.mca = MCA(tea, quanti.sup = 19,quali.sup = 20:36, graph = FALSE)
factoGraph(res.mca)

## End(Not run)

Example output

Loading required package: FactoMineR

```{r, echo = FALSE, fig.align = 'center', fig.height = 3.5, fig.width = 5.5}
drawn <-
c("Casarsa", "Karpov", "Drews", "Sebrle", "BOURGUIGNON", "Clay", 
"NOOL", "YURKOV", "Parkhomenko", "Korkizoglou", "Warners", "Lorenzo", 
"Uldal", "Macey", "WARNERS", "Averyanov", "Nool", "MARTINEAU", 
"Karlivans")
par(mar = c(4.1, 4.1, 1.1, 2.1))
plot.PCA(res, select = drawn, axes = 1:2, choix = 'ind', invisible = 'quali', title = '', cex = cex)
```

**Figure.1 - Individuals factor map (PCA)**
*The labeled individuals are those with the higher contribution to the plane construction.*

The Wilks test p-value indicates which variable factors are the best separated on the plane (i.e. which one explain the best the distance between individuals).
Competition 
   0.366311 
```{r, echo = FALSE, comment = ''}
wilks.p <-
structure(0.366311033108412, .Names = "Competition")
wilks.p
```
There only is one possible qualitative variable to illustrate the distance between individuals : *Competition*.

```{r, echo = FALSE, fig.align = 'center', fig.height = 3.5, fig.width = 5.5}
sample = sample(rownames(res$call$X), length(rownames(res$call$X)))
res$call$X = res$call$X[sample,]
res$ind$coord = res$ind$coord[sample[!sample %in% rownames(res$ind.sup$coord)],]
res$ind.sup$coord = res$ind.sup$coord[sample[sample %in% rownames(res$ind.sup$coord)],]
drawn <-
c("Casarsa", "Karpov", "Drews", "Sebrle", "BOURGUIGNON", "Clay", 
"NOOL", "YURKOV", "Parkhomenko", "Korkizoglou", "Warners", "Lorenzo", 
"Uldal", "Macey", "WARNERS", "Averyanov", "Nool", "MARTINEAU", 
"Karlivans")
hab <-
"Competition"
par(mar = c(4.1, 4.1, 1.1, 2.1))
plotellipses(res, axes = 1:2, invisible = 'quali', select = drawn, keepvar = hab, title = '', cex = cex)
```

**Figure.2 - Individuals factor map (PCA)**
*The labeled individuals are those with the higher contribution to the plane construction.*
*The individuals are coloured after their category for the variable* Competition.

```{r, echo = FALSE, fig.align = 'center', fig.height = 3.5, fig.width = 5.5}
drawn <-
c("Points", "400m", "Shot.put", "Discus", "Long.jump", "100m", 
"110m.hurdle")
par(mar = c(4.1, 4.1, 1.1, 2.1))
plot.PCA(res, select = drawn, axes = 1:2, choix = 'var', title = '', cex = cex)
```

**Figure.3 - Variables factor map (PCA)**
*The variables in black are considered as active whereas those in blue are illustrative.*
*The labeled variables are those the best shown on the plane.*

```{r, echo = FALSE, fig.align = 'center', fig.height = 3.5, fig.width = 5.5}
drawn <-
"Decastar"
par(mar = c(4.1, 4.1, 1.1, 2.1))
plot.PCA(res, select = drawn, axes = 1:2, choix = 'ind', invisible = c('ind', 'ind.sup'), title = '', cex = cex)
```

**Figure.4 - Qualitative factor map (PCA)**
*The labeled factors are those the best shown on the plane.*

```{r, echo = FALSE, fig.align = 'center', fig.height = 3.5, fig.width = 5.5}
r.drawn <-
c("circumstances", "fear", "unemployment", "work", "hard", "world", 
"future", "economic", "comfort", "war", "health", "employment", 
"to_live")
c.drawn <-
c("high_school_diploma", "university", "unqualified", "cep")
par(mar = c(4.1, 4.1, 1.1, 2.1))
plot.CA(res, selectRow = r.drawn, selectCol = c.drawn, axes = 1:2, choix = 'CA', invisible = c('var', 'quali'), title = '', cex = cex)
```

**Figure.1 - Overlayed factor map (CA)**
*The rows in light blue are considered as active whereas those in dark blue are illustrative.*
*The columns in light red are considered as active whereas those in dark red are illustrative.*
*The labeled rows are those the best shown on the plane.*
*The labeled columns are those the best shown on the plane.*

```{r, echo = FALSE, fig.align = 'center', fig.height = 3.5, fig.width = 5.5}
drawn <-
"190"
par(mar = c(4.1, 4.1, 1.1, 2.1))
plot.MCA(res, select = drawn, axes = 1:2, choix = 'ind', invisible = c('var', 'quali'), title = '', cex = cex)
```

**Figure.1 - Individuals factor map (MCA)**
*The labeled individuals are those with the higher contribution to the plane construction.*

The Wilks test p-value indicates which variable factors are the best separated on the plane (i.e. which one explain the best the distance between individuals).
    friendliness        frequency              sex            age_Q 
    1.471754e-05     2.368748e-05     4.404320e-04     1.061993e-03 
             SPC    sophisticated         slimming escape.exoticism 
    1.123895e-02     2.570418e-02     3.072810e-01     3.283072e-01 
effect.on.health         exciting     spirituality         relaxing 
    3.551545e-01     4.368702e-01     4.755738e-01     4.779167e-01 
```{r, echo = FALSE, comment = ''}
wilks.p <-
structure(c(1.47175432170243e-05, 2.36874768021478e-05, 0.00044043196568011, 
0.00106199310586252, 0.0112389509946806, 0.0257041788313188, 
0.307281023552957, 0.328307213780579, 0.355154544183406, 0.436870228328203, 
0.475573798969532, 0.477916701687802), .Names = c("friendliness", 
"frequency", "sex", "age_Q", "SPC", "sophisticated", "slimming", 
"escape.exoticism", "effect.on.health", "exciting", "spirituality", 
"relaxing"))
wilks.p
```
The best qualitative variable to illustrate the distance between individuals on this plane is : *friendliness*.

```{r, echo = FALSE, fig.align = 'center', fig.height = 3.5, fig.width = 5.5}
sample = sample(rownames(res$call$X), length(rownames(res$call$X)))
res$call$X = res$call$X[sample,]
res$ind$coord = res$ind$coord[sample[!sample %in% rownames(res$ind.sup$coord)],]
res$ind.sup$coord = res$ind.sup$coord[sample[sample %in% rownames(res$ind.sup$coord)],]
drawn <-
"190"
hab <-
"friendliness"
par(mar = c(4.1, 4.1, 1.1, 2.1))
plotellipses(res, axes = 1:2, invisible = c('var', 'quali'), select = drawn, keepvar = hab, title = '', cex = cex)
```

**Figure.2 - Individuals factor map (MCA)**
*The labeled individuals are those with the higher contribution to the plane construction.*
*The individuals are coloured after their category for the variable* friendliness.

```{r, echo = FALSE, fig.align = 'center', fig.height = 3.5, fig.width = 5.5}
drawn <-
c("chain store", "tea shop", "p_upscale", "tea bag", "unpackaged", 
"chain store+tea shop", "tearoom", "Not.tearoom", "resto")
par(mar = c(4.1, 4.1, 1.1, 2.1))
plot.MCA(res, selectMod = drawn, axes = 1:2, choix = 'ind', invisible = 'ind', title = '', cex = cex)
```

**Figure.3 - Variables factor map (MCA)**
*The factors in red are considered as active whereas those in green are illustrative.*
*The labeled variables are those the best shown on the plane.*

```{r, echo = FALSE, fig.align = 'center', fig.height = 3.5, fig.width = 5.5}
drawn <-
"age"
par(mar = c(4.1, 4.1, 1.1, 2.1))
plot.MCA(res, select = drawn, axes = 1:2, choix = 'quanti.sup', title = '', cex = cex)
```

**Figure.4 - Quantitative factor map (MCA)**
*The labeled variables are those the best shown on the plane.*

FactoInvestigate documentation built on May 5, 2018, 5:04 p.m.