# NOT RUN {
d <- CompositeData(mtcars[, c("mpg", "hp", "wt", "disp")],
thresholds = list(one = with(mtcars, c(
mpg = max(mpg),
hp = max(hp),
wt = min(wt),
disp = min(disp)))),
higherisbetter = c(TRUE, TRUE, FALSE, FALSE))
## create the distance scores
## and prepare to create the composite
dres <- prepareComposite(d)
## create composite based on summing the (standardized)
scomp <- sumComposite(dres, "square", "sum")
## use model to generate predictions on new data
predictCS(scomp,
newdata = mtcars[1, c("mpg", "hp", "wt", "qsec")],
groups = "one")
## create composite based on mahalanobis distances
mcomp <- mahalanobisComposite(dres)
## use model to generate predictions on new data
predictCS(mcomp,
newdata = mtcars[1, c("mpg", "hp", "wt", "qsec")],
groups = "one")
## note in this too simple example, there are negative variance estimates
## create composite based on factor scores
fcomp <- factorComposite(dres, type = "onefactor")
## use model to generate predictions on new data
predictCS(fcomp,
newdata = mtcars[1:5, c("mpg", "hp", "wt", "disp")],
groups = rep("one", 5))
# }
Run the code above in your browser using DataLab