| plotcpfa | R Documentation |
Plots optimal model based on results from a 'wrapcpfa' object generated by
function cpfa.
plotcpfa(object, cmeasure = "acc", meanvalue = TRUE, supNum = FALSE,
cmode = NULL, parallel = FALSE, cl = NULL, scale.remode = NULL,
newscales = 1, scale.abmode = NULL, sign.remode = NULL, newsigns = 1,
sign.abmode = NULL, ...)
object |
An object of class 'wrapcpfa' from function |
cmeasure |
Classification performance measure used to select the optimal number of
components. Options include |
meanvalue |
Logical indicating whether to find the optimal number of components based on
the mean performance across replications from the results generated by
|
supNum |
Logical indicating whether to suppress text displaying component weight values within plot cells. If TRUE, values are not displayed. |
cmode |
Integer value of 1, 2, or 3 (or 4 if |
parallel |
Logical indicating whether parallel computing should be used. If TRUE, parallel computing is used. |
cl |
Cluster for parallel computing, which is used when |
scale.remode |
Character that indicates a mode to rescale. Must be one of |
newscales |
The root mean-square for columns of the mode indicated by |
scale.abmode |
Character that indicates the mode that absorbs the inverse of rescalings
applied to the mode indicated by |
sign.remode |
Character that indicates a mode to resign. Must be one of |
newsigns |
Scalar or vector indicating resignings for columns of the mode indicated by
|
sign.abmode |
Character that indicates the mode that absorbs the negation of the resignings
applied to the mode indicated by |
... |
Additional arguments to be passed to function |
Selects the number of components that optimized a performance measure across
all classification methods used by cpfa. With this optimal number of
components, fits the component model that was used by cpfa to
create the input 'wrapcpfa' object. Uses same constraints used in cpfa.
Plots component weights for this optimal model using heatmaps. Darker red
indicates component weights that are more negative while darker green indicates
component weights that are more positive. For three-way Parafac, plots A and B
weights. For four-way Parafac, plots A, B, and C weights. For three-way
Parafac2, plots B weights. For four-way Parafac2, plots B and C weights. For
PCA, plots loadings (i.e., A weights).
Returns one or more heatmap plots of component weights for the optimal component model. Returns list of estimated component weights from the optimal model.
Aweights |
Estimated A mode weights for optimal Parafac or Parafac2 model. For PCA, contains the component loadings. |
Bweights |
Estimated B mode weights for optimal Parafac or Parafac2 model. For PCA, contains the component scores. |
Cweights |
Estimated C mode weights for optimal Parafac or Parafac2 model. For PCA, returns NULL. |
Dweights |
Estimated D mode weights for optimal Parafac or Parafac2 model. For PCA, returns NULL. |
Applications of this function to real datasets can be explored at the following repository: https://github.com/matthewasisgress/multiway-classification/.
Matthew Asisgress <mattgress@protonmail.ch>
See help file for function cpfa for a list of references.
########## Parafac2 example with 4-way array and multiclass response ##########
## Not run:
# set seed and simulate a four-way ragged array related to a multiclass response
set.seed(5)
# define list of arguments specifying distributions for A and G weights
techlist <- list(distA = list(dname = "poisson",
lambda = 3), # for A weights
distG = list(dname = "gamma", shape = 2,
scale = 4)) # for G weights
# define target correlation matrix for columns of D mode weights matrix
cormat <- matrix(c(1, .6, .6, .6, 1, .6, .6, .6, 1), nrow = 3, ncol = 3)
# simulate a four-way ragged array connected to a response
data <- simcpfa(arraydim = c(10, 11, 12, 100), model = "parafac2", nfac = 3,
nclass = 3, nreps = 1e2, onreps = 10, corresp = rep(.6, 3),
meanpred = rep(2, 3), modes = 4, corrpred = cormat,
technical = techlist, smethod = "eigende")
# initialize
alpha <- seq(0, 1, length = 2)
gamma <- c(0, 1)
cost <- c(0.1, 5)
rda.alpha <- seq(0.1, 0.9, length = 2)
delta <- c(0.1, 2)
method <- c("PLR", "SVM", "RDA")
family <- "multinomial"
parameters <- list(alpha = alpha, gamma = gamma, cost = cost,
rda.alpha = rda.alpha, delta = delta)
model <- "parafac2"
nfolds <- 3
nstart <- 3
# constrain first mode weights to be orthogonal, fourth mode to be nonnegative
const <- c("orthog", "uncons", "uncons", "nonneg")
# fit Parafac2 model and use fourth mode weights to tune classification
# methods, to predict class labels, and to return classification
# performance measures pooled across multiple train-test splits
output <- cpfa(x = data$X, y = data$y, model = model, nfac = 3,
nrep = 2, ratio = 0.8, nfolds = nfolds, method = method,
family = family, parameters = parameters,
type.out = "descriptives", seeds = NULL, plot.out = TRUE,
parallel = FALSE, const = const, nstart = nstart, ctol = 1e-2)
# plot heatmap of component weights for optimal model
plotcpfa(output, nstart = nstart, ctol = 1e-3)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.