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

View source: R/contributions.R View source: R/contributions.R

Contributions of Variates to Model Predictions

1 2 3 4 5 6 7 8 9 10 | ```
contributions(object, newdata, dims = TRUE, ...)
## S3 method for class 'lda'
contributions(object, newdata,
dims = TRUE, prior = object$prior, ...)
## S3 method for class 'pcalda'
contributions(object,
newdata = stop("newdata is required: ", "pcalda models do not store the original data"),
dims = TRUE, ...)
``` |

`object` |
a model |

`newdata` |
data to use for calculating contributions |

`dims` |
dimensions in model space of which the contributions should be calculated |

`...` |
further parameters |

`prior` |
For |

Linear models procduce scores according to

*S = (X - center) x
coefficients*

from the data matrix X, the center of the model and the model coefficients (scaling, rotation, loadings, latent variables, ...)

To study the behaviour of the model it is often useful to
calculate the element-wise product of centered data and
the for each latent variable (component, discriminant
function, ...). This is done by `contributions`

an array of dimension (`nrow (newdata)`

x ```
ncol
(newdata)
```

x `length (dims)`

)

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 | ```
## contributions 1st discriminant function
model <- lda (Species ~ ., data = iris)
contrib.LD1 <- contributions (model, dims = 1)
contrib.LD1[1:6,,]
dim (contrib.LD1)
layout (1:3, 3, 1)
for (class in levels (iris$Species))
boxplot (contrib.LD1 [iris$Species == class,,], ylim = range (contrib.LD1))
## all contributions
contrib.LD <- contributions (model)
dim (contrib.LD)
contrib.LD[1:6,,]
if (require ("reshape2")) {
contrib.df <- melt (contrib.LD, value.name = "contribution")
} else {
contrib.df <- array2df (contrib.LD, label.x = "contribution")
}
contrib.df$Species <- iris$Species [contrib.df$row]
head (contrib.df)
if (require ("lattice")){
bwplot (contribution ~ Species | variate, data = contrib.df, layout = c (4, 1))
}
## sum contributions to get scores
diff <- predict (model)$x - apply (contrib.LD, c (1, 3), sum)
summary (diff)
boxplot (diff)
1+1
``` |

cbmodels documentation built on May 31, 2017, 2:11 a.m.

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.