Type: | Package |
Title: | Analysis of Check-All-that-Apply (CATA) Data |
Version: | 0.1.0.27 |
Date: | 2025-02-24 |
Author: | J.C. Castura |
Maintainer: | J.C. Castura <jcastura@compusense.com> |
Description: | Package contains functions for analyzing check-all-that-apply (CATA) data from consumer and sensory tests. Cochran's Q test, McNemar's test, and Penalty-Lift analysis are provided; for details, see Meyners, Castura & Carr (2013) <doi:10.1016/j.foodqual.2013.06.010>. Cluster analysis can be performed using b-cluster analysis, then evaluated using various measures; for details, see Castura, Meyners, Varela & Næs (2022) <doi:10.1016/j.foodqual.2022.104564>. Methods are adapted to cluster consumers based on their product-related hedonic responses; for details, see Castura, Meyners, Pohjanheimo, Varela & Næs (2023) <doi:10.1111/joss.12860>. Permutation tests based on the L1-norm methods are provided; for details, see Chaya, Castura & Greenacre (2025) <doi:10.48550/arXiv.2502.15945>. |
URL: | https://CRAN.R-project.org/package=cata |
Depends: | R (≥ 4.4.0) |
Imports: | stats, utils, graphics |
License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
LazyData: | TRUE |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.2 |
NeedsCompilation: | no |
Packaged: | 2025-02-25 04:42:20 UTC; jcastura |
Repository: | CRAN |
Date/Publication: | 2025-02-25 08:20:02 UTC |
Adjusted Rand index
Description
Calculate the adjusted Rand index (ARI) between two sets of cluster memberships.
Usage
ARI(x, y, signif = FALSE, n = 1000)
Arguments
x |
vector of cluster memberships (integers) |
y |
vector of cluster memberships (integers) |
signif |
conduct significance test; default is |
n |
number of replicates in Monte Carlo significance test |
Value
list of the following:
ari
adjusted Rand indexnari
normalized adjusted Rand indexsim.mean
average value of null distribution (should be closed to zero)sim.var
variance of null distributionp.value
P value of observed ARI (or NARI) value
Author(s)
J.C. Castura
References
Hubert, L., & Arabie, P. (1985). Comparing partitions. Journal of Classification, 2, 193–218. doi:10.1007/BF01908075.
Qannari, E.M., Courcoux, P., & Faye, P. (2014). Significance test of the adjusted Rand index. Application to the free sorting task. Food Quality and Preference, 32, 93-97. doi:10.1016/j.foodqual.2013.05.005.
Examples
x <- sample(1:3, 20, replace = TRUE)
y <- sample(1:3, 20, replace = TRUE)
ARI(x, y, signif = FALSE)
Consumer CATA data set: bread
Description
Consumer data from 161 assessors (consumers) who evaluated 6 products (breads) using a check-all-that-apply (CATA) question and the 9-point hedonic scale.
Format
List with items:
$cata
: CATA data array (161 consumers\times
6 breads\times
31 sensory attributes)$liking
: 9-point hedonic scale data matrix (161 consumers\times
6 breads)$ideal.cata
: CATA data matrix for ideal bread evaluations (161 consumers\times
31 sensory attributes)$liking
: 9-point hedonic scale data vector for ideal bread (length: 161 consumers)
Responses to CATA questions are each coded 1
if the assessor checks the
attribute for the product; otherwise, it is coded 0
References
Meyners, M., Castura, J.C., & Carr, B.T. (2013). Existing and new approaches for the analysis of CATA data. Food Quality and Preference, 30, 309-319, doi:10.1016/j.foodqual.2013.06.010
Examples
data(bread)
# view CATA frequency table
apply(bread$cata, 2:3, sum)
Consumer CATA data set: squashes
Description
Check-all-that-apply (CATA) data set from 100 assessors (consumers) who evaluated 11 products (blackcurrant squashes) using 34 terms.
Format
Array of data coded 1
if the assessor checked the term for the attribute
and 0
otherwise.
Dimension 1 : 100 assessors
Dimension 2 : 11 products
Dimension 3 : 34 terms
A response is coded 1
if the attribute is checked; otherwise it is coded 0
.
References
Ng, M., Chaya, C., & Hort, J. (2013). Beyond liking: Comparing the measurement of emotional response using EsSense Profile and consumer defined check-all-that-apply methodologies. Food Quality and Preference, 28, 193-205, doi:10.1016/j.foodqual.2012.08.012
Examples
data(squashes)
# view CATA frequency table
apply(squashes, 2:3, sum)
Convert 3d array of CATA data to 4d array of CATA differences
Description
Converts a three-dimensional array (I
assessors, J
products, M
attributes) to a four-dimensional array of product
comparisons (I
assessors, J(J-1)/2
product comparisons, two outcomes (of type b
or c
), M
attributes)
Usage
barray(X, values = "bc", type.in = "binary", type.out = "binary")
Arguments
X |
three-dimensional array ( |
values |
|
type.in |
type of data submitted; default ( |
type.out |
currently only |
Value
A four-dimensional array of product comparisons having I
assessors, J(J-1)/2
product comparisons, outcomes (see values
parameter), M
attributes
Author(s)
J.C. Castura
References
Castura, J.C., Meyners, M., Varela, P., & Næs, T. (2022). Clustering consumers based on product discrimination in check-all-that-apply (CATA) data. Food Quality and Preference, 104564. doi:10.1016/j.foodqual.2022.104564.
Examples
data(bread)
# Get the 4d array of CATA differences for the first 8 consumers
b <- barray(bread$cata[1:8,,])
Wrapper function for b-cluster analysis
Description
By default, bcluster
calls a function to perform b-cluster analysis
by a non-hierarchical iterative ascent algorithm, then inspects results if
there are multiple runs.
Usage
bcluster(X, inspect = TRUE, inspect.plot = TRUE, algorithm = "n",
measure = "b", G = NULL, M = NULL, max.iter = 500, X.input = "data",
tol = exp(-32), runs = 1, seed = 2021)
Arguments
X |
three-way array with |
inspect |
default ( |
inspect.plot |
default ( |
algorithm |
default is |
measure |
default is |
G |
number of clusters (required for non-hierarchical algorithm) |
M |
initial cluster memberships |
max.iter |
maximum number of iteration allowed (default |
X.input |
available only for non-hierarchical algorithm; its value is
either |
tol |
non-hierarchical algorithm stops if variance over 5 iterations is
less than |
runs |
number of runs (defaults to |
seed |
for reproducibility (default is |
Value
list with elements:
runs
: b-cluster analysis results frombcluster.n
orbcluster.h
(in a list ifruns>1
)inspect
: result frominspect
(the plot from this function is rendered ifinspect.plot
isTRUE
)
Author(s)
J.C. Castura
References
Castura, J.C., Meyners, M., Varela, P., & Næs, T. (2022). Clustering consumers based on product discrimination in check-all-that-apply (CATA) data. Food Quality and Preference, 104564. doi:10.1016/j.foodqual.2022.104564.
Examples
data(bread)
# b-cluster analysis on the first 8 consumers and the first 5 attributes
(b1 <- bcluster(bread$cata[1:8,,1:5], G=2, seed = 123))
# Since the seed is the same, the result will be identical to
# (b2 <- bcluster.n(bread$cata[1:8,,1:5], G=2, seed = 123))
b3 <- bcluster(bread$cata[1:8,,1:5], G=2, runs = 5, seed = 123)
b-cluster analysis by hierarchical agglomerative strategy
Description
Perform b-clustering using the hierarchical agglomerative clustering strategy.
Usage
bcluster.h(X, measure = "b", runs = 1, seed = 2021)
Arguments
X |
three-way array; the |
measure |
currently only |
runs |
number of runs (defaults to |
seed |
for reproducibility (default is |
Value
An object of class hclust
from hierarchical b-cluster
analysis results (a list of such objects if runs>1
), where each hclust
object has the structure described in hclust
as well as
the item retainedB
(a vector indicating the retained sensory
differentiation at each iteration (merger)).
Author(s)
J.C. Castura
References
Castura, J.C., Meyners, M., Varela, P., & Næs, T. (2022). Clustering consumers based on product discrimination in check-all-that-apply (CATA) data. Food Quality and Preference, 104564. doi:10.1016/j.foodqual.2022.104564.
Examples
data(bread)
# hierarchical b-cluster analysis on first 8 consumers and first 5 attributes
b <- bcluster.h(bread$cata[1:8,,1:5])
plot(as.dendrogram(b),
main = "Hierarchical b-cluster analysis",
sub = "8 bread consumers on 5 attributes")
b-cluster analysis by non-hierarchical iterative ascent clustering strategy
Description
Non-hierarchical b-cluster analysis transfers assessors iteratively to reach a local maximum in sensory differentiation retained.
Usage
bcluster.n(X, G, M = NULL, measure = "b", max.iter = 500, runs = 1,
X.input = "data", tol = exp(-32), seed = 2021)
Arguments
X |
CATA data organized in a three-way array (assessors, products, attributes) |
G |
number of clusters (required for non-hierarchical algorithm) |
M |
initial cluster memberships (default: |
measure |
|
max.iter |
maximum number of iteration allowed (default |
runs |
number of runs (defaults to |
X.input |
either |
tol |
algorithm stops if variance over 5 iterations is less than
|
seed |
for reproducibility (default is |
Value
An object of class bclust.n
(or a list of such objects
if runs>1
), where each such object has the following components:
cluster
: vector of the final cluster membershipstotalB
: value of the total sensory differentiation in data setretainedB
: value of sensory differentiation retained in b-cluster analysis solutionprogression
: vector of sensory differentiation retained in each iterationiter
: number of iterations completedfinished
: boolean indicates whether the algorithm converged beforemax.iter
Author(s)
J.C. Castura
References
Castura, J.C., Meyners, M., Varela, P., & Næs, T. (2022). Clustering consumers based on product discrimination in check-all-that-apply (CATA) data. Food Quality and Preference, 104564. doi:10.1016/j.foodqual.2022.104564.
Examples
data(bread)
# b-cluster analysis on the first 8 consumers and the first 5 attributes
(b <- bcluster.n(bread$cata[1:8, , 1:5], G=2))
Cochran's Q test
Description
Conduct Cochran's Q test assuming equal columns proportions for matched binary responses versus the alternative hypothesis of unequal column proportions.
Usage
cochranQ(X, quiet = FALSE, digits = getOption("digits"))
Arguments
X |
matrix of |
quiet |
if |
digits |
for rounding |
Details
Method returns test statistic, degrees of freedom, and p value from Cochran's Q test.
Value
Cochran's Q test results (statistic, degrees of freedom, p-value)
Author(s)
J.C. Castura
References
Cochran, W.G. (1950). The comparison of percentages in matched samples. Biometrika, 37, 256-266, doi:10.2307/2332378
Meyners, M., Castura, J.C., & Carr, B.T. (2013). Existing and new approaches for the analysis of CATA data. Food Quality and Preference, 30, 309-319, doi:10.1016/j.foodqual.2013.06.010
See Also
Examples
data(bread)
# Cochran's Q test on the first 50 consumers on the first attribute ("Fresh")
cochranQ(bread$cata[1:50, , 1], digits=3)
# Same, returning only test statistics for the first 4 attributes
t(res <- apply(bread$cata[1:50, , 1:4], 3, cochranQ, quiet=TRUE, digits=3))
Apply top-k box coding to scale data
Description
Apply top-k box coding to scale data. Using defaults give top-2 box (T2B) coding.
Usage
code.topk(X, zero.below = 8, one.above = 7)
Arguments
X |
input matrix |
zero.below |
default is |
one.above |
default is |
Value
matrix X
with top-k coding applied
Author(s)
J.C. Castura
References
Castura, J.C., Meyners, M., Pohjanheimo, T., Varela, P., & Næs, T. (2023). An approach for clustering consumers by their top-box and top-choice responses. Journal of Sensory Studies, e12860. doi:10.1111/joss.12860
Examples
# Generate some data
set.seed(123)
X <- matrix(sample(1:9, 100, replace = TRUE), nrow = 5)
# apply top-2 box (T2B) coding
code.topk(X, zero.below = 8, one.above = 7)
Evaluate Quality of Cluster Analysis Solution
Description
Evaluate the quality of cluster analysis solutions using measures related to within-cluster product discrimination, between-cluster non-redundancy, overall diversity (coverage), average RV, sensory differentiation retained, and within-cluster homogeneity.
Usage
evaluateClusterQuality(X, M, alpha = .05, M.order = NULL,
quiet = FALSE, digits = getOption("digits"), ...)
Arguments
X |
three-way array; the |
M |
cluster memberships |
alpha |
significance level for two-tailed tests (default: |
M.order |
can be used to change the cluster numbers (e.g. to label
cluster 1 as cluster 2 and vice versa); defaults to |
quiet |
if |
digits |
significant digits (to display) |
... |
other parameters for |
Value
A list containing cluster analysis quality measures:
$solution
:Pct.b
= percentage of the total sensory differentiation retained in the solutionmin(NR)
= smallest observed between-cluster non-redundancyDiv_G
= overall diversity (coverage)H_G
= overall homogeneity (weighted average of within-cluster homogeneity indices)avRV
= average RV coefficient for all between-cluster comparisons
$clusters
:ng
= number of cluster membersbg
= sensory differentiation retained in clusterxbarg
= average citation rate in clusterHg
= homogeneity index within cluster (seehomogeneity
)Dg
= within-cluster product discrimination
$nonredundancy.clusterpairs
:square data frame showing non-redundancy for each pair of clusters (low values indicate high redundancy)
$rv.clusterpairs
:square data frame with RV coefficient for each pair of clusters (high values indicate higher similarity in product configurations)
Author(s)
J.C. Castura
References
Castura, J.C., Meyners, M., Varela, P., & Næs, T. (2022). Clustering consumers based on product discrimination in check-all-that-apply (CATA) data. Food Quality and Preference, 104564. doi:10.1016/j.foodqual.2022.104564.
See Also
Examples
data(bread)
evaluateClusterQuality(bread$cata[1:8,,1:5], M = rep(1:2, each = 4))
Calculate the b-measure
Description
Function to calculate the b-measure, which quantifies the sensory differentiation retained.
Usage
getb(X.b, X.c, oneI = FALSE, oneM = FALSE)
Arguments
X.b |
three-way ( |
X.c |
array of same dimension as |
oneI |
indicates whether calculation is for one assessor (default:
|
oneM |
indicates whether calculation is for one attribute (default:
|
Value
b-measure
Author(s)
J.C. Castura
References
Castura, J.C., Meyners, M., Varela, P., & Næs, T. (2022). Clustering consumers based on product discrimination in check-all-that-apply (CATA) data. Food Quality and Preference, 104564. doi:10.1016/j.foodqual.2022.104564.
Examples
data(bread)
bread.bc <- barray(bread$cata[1:8,,1:5])
getb(bread.bc[,,1,], bread.bc[,,2,])
Calculate within-cluster homogeneity
Description
Within a group of N
consumers, the Homogeneity index lies between
1/N
(no homogeneity) to 1
(perfect homogeneity).
Usage
homogeneity(X, oneI = FALSE, oneM = FALSE)
Arguments
X |
three-way array; the |
oneI |
indicates whether calculation is for one assessor (default:
|
oneM |
indicates whether calculation is for one attribute (default:
|
Value
homogeneity index
References
Llobell, F., Cariou, V., Vigneau, E., Labenne, A., & Qannari, E.M. (2019). A new approach for the analysis of data and the clustering of subjects in a CATA experiment. Food Quality and Preference, 72, 31-39, doi:10.1016/j.foodqual.2018.09.006
Examples
data(bread)
# homogeneity index for the first 7 consumers on the first 6 attributes
homogeneity(bread$cata[1:7,,1:6])
Inspect/summarize many b-cluster analysis runs
Description
Inspect many runs of b-cluster analysis. Calculate sensory differentiation retained and recurrence rate.
Usage
inspect(X, G = 2, bestB = NULL, bestM = NULL, inspect.plot = TRUE)
Arguments
X |
list of multiple runs of b-cluster analysis results from
|
G |
number of clusters (required for non-hierarchical algorithm) |
bestB |
total sensory differentiation retained in the best solution. If
not provided, then |
bestM |
cluster memberships for best solution. If not provided, then
the best solution is determined from the runs provided (in |
inspect.plot |
default ( |
Value
A data frame with unique solutions in rows and the following columns:
B
: Sensory differentiation retainedPctB
: Percentage of the total sensory differentiation retainedB.prop
: Proportion of sensory differentiation retained compared to best solutionRaw.agree
: raw agreement with best solutionCount
: number of runs for which this solution was observedIndex
: list index (i.e., run number) of first solution solution inX
corresponding to this row
Author(s)
J.C. Castura
References
Castura, J.C., Meyners, M., Varela, P., & Næs, T. (2022). Clustering consumers based on product discrimination in check-all-that-apply (CATA) data. Food Quality and Preference, 104564. doi:10.1016/j.foodqual.2022.104564.
Examples
data(bread)
res <- bcluster.n(bread$cata[1:8, , 1:5], G = 3, runs = 3)
(ires <- inspect(res))
# get index of solution retaining the most sensory differentiation (in these runs)
indx <- ires$Index[1]
# cluster memberships for solution of this solution
res[[indx]]$cluster
MAD distances between objects
Description
Computes and returns inter-object median of absolute deviations (MADs) based differences.
Usage
mad.dist(X)
Arguments
X |
objects-by-terms matrix |
Value
object of class dist
giving inter-object MAD distances
Author(s)
J.C. Castura
References
Chaya, C., Castura, J.C., & Greenacre, M.J. (2025). One citation, one vote! A new approach for analyzing check-all-that-apply (CATA) data in sensometrics, using L1 norm methods. doi:10.48550/arXiv.2502.15945
Examples
data(bread)
CATA.freq <- apply(bread$cata, 2:3, sum)
# median-center columns (attributes)
CATA.swept <- sweep(CATA.freq, 2, apply(CATA.freq, 2, median))
# cluster analysis of products using complete linkage
dist.Products <- mad.dist(CATA.swept)
plot(as.dendrogram(hclust(dist.Products, method = "complete")), main = "Product clusters")
# cluster analysis of attributes using complete linkage
dist.Att <- mad.dist(t(CATA.swept))
plot(as.dendrogram(hclust(dist.Att, method = "complete")), main = "Attribute clusters")
Permutation tests for CATA data
Description
Permutation tests for check-all-that-apply (CATA) data following the 'one citation, one vote' principle. Returns CATA frequency and percentage tables per condition and permutation test results specified.
Usage
madperm(X, B = 99, seed = .Random.seed, tests = 1:5, alpha = 0.05, control.fdr = FALSE,
verbose = FALSE)
Arguments
X |
a three-way (or four-way) array with |
B |
permutations in null distribution; ensure |
seed |
specify a numeric seed for reproducibility; if not provided, a random seed is generated |
tests |
numeric vector specifying which tests to conduct; default
|
alpha |
Type I error rate (default: |
control.fdr |
control False Discovery Rate (using Benjamini-Hochberg (BH) step-up
procedure)? (default: |
verbose |
return null distribution(s) and function call? (default: |
Value
list, one per condition:
CATA.table
: table of CATA citation percentages (P \times T
)CATA.freq
: CATA frequency table (P \times T
)Permutation test results specified by the
tests
parameterGlobal.Results
: list of multivariate (global) resultsUnivariate.Results
: list ofT
univariate resultsElementwise.Results
: list ofPT
elementwise resultsMultivariate.Paired.Results
: list ofP(P-1)/2
multivariate paired resultsUnivariate.Paired.Results
: list ofP(P-1)T/2
univariate paired results
also, if verbose
is TRUE
:
Null.Dist
list of null distributions for tests specifiedCall
:madperm
function call
Author(s)
J.C. Castura
References
Chaya, C., Castura, J.C., & Greenacre, M.J. (2025). One citation, one vote! A new approach for analyzing check-all-that-apply (CATA) data in sensometrics, using L1 norm methods. doi:10.48550/arXiv.2502.15945
Examples
data(bread)
# add product names
X <- bread$cata[1:100,,1:5]
dimnames(X)[[2]] <- paste0("P", dimnames(X)[[2]])
# permutation tests for the first 100 consumers and 5 attributes
# will be run with default parameter values for illustrative purposes only
res <- madperm(X, B = 99, seed = 123)
print(res) # inspect results
McNemar's test
Description
Pairwise tests are conducted using the two-tailed binomial test. These tests can be conducted after Cochran's Q test.
Usage
mcnemarQ(X, quiet = FALSE, digits = getOption("digits"))
Arguments
X |
matrix of |
quiet |
if |
digits |
for rounding |
Value
Test results for all McNemar pairwise tests conducted via the binomial test
Author(s)
J.C. Castura
References
Cochran, W.G. (1950). The comparison of percentages in matched samples. Biometrika, 37, 256-266. doi:10.2307/2332378
McNemar, Q. (1947). Note on the sampling error of the difference between correlated proportions or percentages. Psychometrika, 12(2), 153-157. doi:10.1007/BF02295996
Meyners, M., Castura, J.C., & Carr, B.T. (2013). Existing and new approaches for the analysis of CATA data. Food Quality and Preference, 30, 309-319, doi:10.1016/j.foodqual.2013.06.010
See Also
Examples
data(bread)
# McNemar's exact pairwise test for all product pairs
# on the first 50 consumers and the first attribute ("Fresh")
mcnemarQ(bread$cata[1:50, , 1])
# Same, returning only results for the first 4 attributes
(res <- apply(bread$cata[1:50, , 1:4], 3, mcnemarQ, quiet=TRUE, simplify=FALSE))
Penalty-Lift Analysis
Description
Penalty-Lift analysis for CATA variables, which is the difference between the average hedonic response when CATA attribute is checked vs. the average hedonic response when CATA attribute is not checked.
Usage
plift(X, Y, digits = getOption("digits"), verbose = FALSE)
Arguments
X |
either a matrix of CATA data with |
Y |
matrix of hedonic data with |
digits |
for rounding |
verbose |
set to |
Value
Penalty lift per attribute, with counts and averages if verbose
is TRUE
.
Author(s)
J.C. Castura
References
Meyners, M., Castura, J.C., & Carr, B.T. (2013). Existing and new approaches for the analysis of CATA data. Food Quality and Preference, 30, 309-319, doi:10.1016/j.foodqual.2013.06.010
Examples
data(bread)
# penalty lift, based only on the first 12 consumers
# for the first attribute ("Fresh")
plift(bread$cata[1:12,,1], bread$liking[1:12, ], digits = 3)
# for the first 3 attributes with counts and averages
plift(bread$cata[1:12,,1:3], bread$liking[1:12, ], digits = 3, verbose = TRUE)
Calculate RV
Coefficient
Description
Calculate RV
coefficient
Usage
rv.coef(X, Y, method = 1)
Arguments
X |
input matrix (same dimensions as |
Y |
input matrix (same dimensions as |
method |
|
Value
RV
coefficient
Author(s)
J.C. Castura
References
Robert, P., & Escoufier, Y. (1976). A unifying tool for linear multivariate statistical methods: the RV-coefficient. Journal of the Royal Statistical Society: Series C (Applied Statistics), 25, 257-265. doi:10.2307/2347233
Examples
# Generate some data
set.seed(123)
X <- matrix(rnorm(8), nrow = 4)
Y <- matrix(rnorm(8), nrow = 4)
# get the RV coefficient
rv.coef(X, Y)
Salton's cosine measure
Description
Calculate Salton's cosine measure
Usage
salton(X, Y)
Arguments
X |
input matrix (same dimensions as |
Y |
input matrix (same dimensions as |
Value
Salton's cosine measure
Author(s)
J.C. Castura
References
Salton, G., & McGill, M.J. (1983). Introduction to Modern Information Retrieval. Toronto: McGraw-Hill.
Examples
# Generate some data
set.seed(123)
X <- matrix(rnorm(8), nrow = 4)
Y <- matrix(rnorm(8), nrow = 4)
# get Salton's cosine measure
salton(X, Y)
Plot variation in retained sensory differentiation
Description
Plot variation in retained sensory differentiation of cluster memberships obtained from b-cluster analysis. This plot can be used to help the decision of how many clusters to retain.
Usage
selectionPlot(x, pctB = NULL, x.input = "deltaB", indx = NULL,
ylab = "change in B (K to G)", xlab = NULL)
Arguments
x |
input vector which is either deltaB (default; change
in sensory differentiation retained) or B (sensory differentiation
retained) if |
pctB |
vector of percentage of the total sensory differentiation retained |
x.input |
indicates what |
indx |
numeric value indicating which point(s) to emphasize |
ylab |
label shown on y axis and at selection point |
xlab |
label for points along x axis |
Author(s)
J.C. Castura
References
Castura, J.C., Meyners, M., Varela, P., & Næs, T. (2022). Clustering consumers based on product discrimination in check-all-that-apply (CATA) data. Food Quality and Preference, 104564. doi:10.1016/j.foodqual.2022.104564.
Examples
set.seed(123)
G2 <- bcluster.n(bread$cata[1:8, , 1:5], G = 2, runs = 3)
G3 <- bcluster.n(bread$cata[1:8, , 1:5], G = 3, runs = 3)
G4 <- bcluster.n(bread$cata[1:8, , 1:5], G = 4, runs = 3)
best.indx <- c(which.max(unlist(lapply(G2, function(x) x$retainedB))),
which.max(unlist(lapply(G3, function(x) x$retainedB))),
which.max(unlist(lapply(G4, function(x) x$retainedB))))
G1.bc <- barray(bread$cata[1:8, , 1:5])
G1.B <- getb(G1.bc[,,1,], G1.bc[,,2,])
BpctB <- data.frame(retainedB = c(G1.B,
G2[[best.indx[1]]]$retainedB,
G3[[best.indx[2]]]$retainedB,
G4[[best.indx[3]]]$retainedB))
BpctB$pctB <- 100*BpctB$retainedB / G2[[1]]$totalB
BpctB$deltaB <-
c(100*(1-BpctB$retainedB[-nrow(BpctB)] / BpctB$retainedB[-1]), NA)
BpctB <- BpctB[-nrow(BpctB),]
opar <- par(no.readonly=TRUE)
par(mar = rep(5,4))
selectionPlot(BpctB$deltaB, BpctB$pctB, indx = 2)
par(opar)
Converts 3d array of CATA data to a tall 2d matrix format
Description
Converts a three-dimensional array (I
assessors, J
products, M
attributes) to a two-dimensional matrix with
(I
assessors, J
products) rows and (M
attributes) columns, optionally preceded by two columns of row headers.
Usage
toMatrix(X, header.rows = TRUE, oneI = FALSE, oneM = FALSE)
Arguments
X |
three-dimensional array ( |
header.rows |
|
oneI |
indicates whether calculation is for one assessor (default:
|
oneM |
indicates whether calculation is for one attribute (default:
|
Value
A matrix with I
assessors \times J
products in rows
and M
attributes in columns (preceded by 2 columns)
of headers if header.rows = TRUE
Examples
data(bread)
# convert CATA results from the first 8 consumers and the first 4 attributes
# to a tall matrix
toMatrix(bread$cata[1:8,,1:4])
Converts 3d array of CATA data to a wide 2d matrix format
Description
Converts a three-dimensional array (I
assessors, J
products, M
attributes) to a two-dimensional matrix
(J
products, (I
assessors, M
attributes))
Usage
toWideMatrix(X)
Arguments
X |
three-dimensional array ( |
Value
A matrix with J
products in rows and I
assessors \times M
attributes in columns
Author(s)
J.C. Castura
Examples
data(bread)
# convert CATA results from the first 8 consumers and the first 4 attributes
# to a wide matrix
toWideMatrix(bread$cata[1:8,,1:4])
Apply top-c choices coding to a vector of scale data from a respondent
Description
Apply top-c choices coding to a vector of scale data from a respondent
Usage
topc(x, c = 2, coding = "B")
Arguments
x |
input matrix |
c |
number of top choices considered to be 'success'; other choices are
considered to be 'failure' and are coded |
coding |
|
Value
matrix X
with top-k coding applied
Author(s)
J.C. Castura
References
Castura, J.C., Meyners, M., Pohjanheimo, T., Varela, P., & Næs, T. (2023). An approach for clustering consumers by their top-box and top-choice responses. Journal of Sensory Studies, e12860. doi:10.1111/joss.12860
Examples
# Generate some data
set.seed(123)
X <- matrix(sample(1:9, 100, replace = TRUE), nrow = 5)
# apply top-2 choice (T2C) coding
apply(X, 1, topc)