
Last chance! 50% off unlimited learning
Sale ends in
Internal function to prepare data for prediction
predictCS(object, newdata, groups)
An object of S4 class “MahalanobisScores”, “SumScores”, or “FactorScores” containing a model and results to be used to get predictions on new data.
A data frame with identical variable names as was used to build the initial model.
A vector with the same length as the data frame in newdata
,
has rows, containing the groups each row belongs to. See CompositeData
for more details.
An object of S4 class “CompositeReady”
# 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