Description Usage Arguments Details Value Author(s) See Also Examples

Flipping of models

`lda`

models are invariant to flipping,
i.e. the predicted posterior probabilities and classes do
not change if the LD scores `lda$x`

are
multiplied by -1.

PCA (`prcomp`

) models are invariant to
flipping of both a loading and its score.

1 2 3 4 5 6 7 8 9 10 11 12 13 |

`object` |
a model to flip |

`dims` |
dimensions which should be mirrored |

`...` |
further parameters |

`flip`

is a post-processing method for models. It
flips (mirrors) dimensions of the model space.

the flipped/mirrored model

Claudia Beleites

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | ```
## flip 1st dimension
model <- lda (Species ~ ., data = iris)
pred <- predict (model)
plot (pred$x, col = iris$Species, pch = 19, cex = 0.3, asp = 1)
model.flip <- flip (model, 1)
pred.flip <- predict (model.flip)
points (pred.flip$x, col = iris$Species, cex = 0.5)
## check difference between original model's predictions and rotated model's predictions
diff <- pred$posterior - pred.flip$posterior
summary (diff)
boxplot (diff)
## mirror x axis
model <- pcalda (X = iris [,1:4], grouping = iris$Species, comps=1:3)
pred <- predict (model)
plot (pred$x, col = iris$Species, pch = 19, cex = 0.3, asp = 1)
model.flip <- flip (model, 1)
pred.flip <- predict (model.flip)
points (pred.flip$x, col = iris$Species, cex = 0.5)
## check difference between original model's predictions and flipped model's predictions
diff <- pred$posterior - pred.flip$posterior
summary (diff)
boxplot (diff)
## mirror x axis of plslda scores
model <- plslda (X = iris [,1:4], grouping = iris[,5], ncomp=2)
pred <- predict (model)
plot (pred$x, col = iris$Species, pch = 19, cex = 0.3, asp = 1)
model.flip <- flip (model, 1)
pred.flip <- predict (model.flip)
points (pred.flip$x, col = iris$Species, cex = 0.5)
## check difference between original model's predictions and flipped model's predictions
diff <- pred$posterior - pred.flip$posterior
summary (diff)
boxplot (diff)
## flip 1st dimension (loading & score)
model <- prcomp (iris [-5])
model.flip <- flip (model, 1)
pairs (model$x, col = iris$Species, pch = 19, cex = 0.3, asp = 1)
pairs (model.flip$x, col = iris$Species, pch = 19, cex = 0.3, asp = 1)
matplot (model$rotation, type = "l")
abline (h = 0)
matpoints (model.flip$rotation, type = "b")
## check difference between original model's predictions and rotated model's predictions
diff <- tcrossprod (model$x, model$rotation) - tcrossprod (model.flip$x, model.flip$rotation)
summary (diff)
boxplot (diff)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.