contributions: contriubutions

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

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

Description

Contributions of Variates to Model Predictions

Usage

 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, ...)

Arguments

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 lda models, priors can be given.

Details

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

Value

an array of dimension (nrow (newdata) x ncol (newdata) x length (dims))

Author(s)

Claudia Beleites

See Also

lda

pcalda

Examples

 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 21, 2017, 12:36 a.m.
Search within the cbmodels package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs in the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.