
Plot Optimal Model from Classification with Parallel Factor Analysis
plotcpfa.RdPlots optimal model based on results from a 'wrapcpfa' object generated by
function cpfa.
Usage
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, ...)Arguments
- object
An object of class 'wrapcpfa' from function
cpfa.- cmeasure
Classification performance measure used to select the optimal number of components. Options include
c("err", "acc", "tpr", "fpr", "tnr", "fnr", "ppv", "npv", "fdr", "fom", "fs"). Ifcmeasureis inc("err", "fpr", "fnr", "fdr", "fom"), the number of components that minimizedcmeasureis selected among all classification methods. Otherwise, the number that maximizedcmeasureis selected.- meanvalue
Logical indicating whether to find the optimal number of components based on the mean performance across replications from the results generated by
cpfa. Ifmeanvalue = FALSE, the median is used.- 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
xis a four-way array) specifying the mode whose component weights were predictors for classification when generating the 'wrapcpfa' object using functioncpfa. If the original inputmodelfrom functioncpfawaspca,cmodemust be 1 or 2 when the original inputxwas a two-way matrix. If the original inputxwas a three-way or four-way array,cmodevalues greater than 2 are ignored with a warning.- parallel
Logical indicating if parallel computing should be implemented. Defaults to FALSE, which implements sequential computing.
- cl
Cluster for parallel computing, which is used when
parallel = TRUE. Note that ifparallel = TRUEandcl = NULL, then the cluster is defined asmakeCluster(max(1L, detectCores() - 1L)).- scale.remode
Character that indicates a mode to rescale. Must be one of
c("A", "B", "C", "D"). Sent directly to argumentmodein functionrescalefrom package multiway. See help file forrescalefor additional details. Ignored when functioncpfaargumentmodel = 'pca'. If supplied, argumentscale.abmodemust also be supplied.- newscales
The root mean-square for columns of the mode indicated by
scale.remode. See help file forrescalefor additional details. Ignored when functioncpfaargumentmodel = 'pca'.- scale.abmode
Character that indicates the mode that absorbs the inverse of rescalings applied to the mode indicated by
scale.remode. Must be one ofc("A", "B", "C", "D"). Sent directly to argumentabsorbin functionrescalefrom package multiway. See help file forrescalefor additional details. Ignored when functioncpfaargumentmodel = 'pca'. If supplied, argumentscale.remodemust also be supplied.- sign.remode
Character that indicates a mode to resign. Must be one of
c("A", "B", "C", "D"). Sent directly to argumentmodein functionresignfrom package multiway. See help file forresignfor additional details. Ignored when functioncpfaargumentmodel = 'pca'. If supplied, argumentsign.abmodemust also be supplied.- newsigns
Scalar or vector indicating resignings for columns of the mode indicated by
sign.remode. See help file forresignfor additional details. Ignored when functioncpfaargumentmodel = 'pca'.- sign.abmode
Character that indicates the mode that absorbs the negation of the resignings applied to the mode indicated by
sign.remode. Must be one ofc("A", "B", "C", "D"). Sent directly to argumentabsorbin functionresignfrom package multiway. See help file forresignfor additional details. Ignored when functioncpfaargumentmodel = 'pca'. If supplied, argumentsign.remodemust also be supplied.- ...
Additional arguments to be passed to function
parafacfor fitting a Parafac model or functionparafac2for fitting a Parafac2 model. See help file for functionparafacor for functionparafac2for additional details.
Details
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).
Value
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.
Note
Applications of this function to real datasets can be explored at the following repository: https://github.com/matthewasisgress/multiway-classification/.
Examples
########## Parafac2 example with 4-way array and multiclass response ##########
if (FALSE) { # \dontrun{
# 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)
} # }