AffinityParam-class | R Documentation |
Use affinity propagation from the apcluster package to cluster observations. Note that this requires the installation of the apcluster package.
AffinityParam(
s = NULL,
p = NA,
q = NA,
maxits = 1000,
convits = 100,
lam = 0.9,
nonoise = FALSE
)
## S4 method for signature 'ANY,AffinityParam'
clusterRows(x, BLUSPARAM, full = FALSE)
s |
A function that accepts a matrix of observations by dimensions and returns a similarity matrix.
If |
p , q |
Numeric scalars controlling the input preference, i.e., the resolution of the clustering.
These are passed to the |
maxits , convits , lam , nonoise |
Further arguments to pass to the |
x |
A numeric matrix-like object where rows represent observations and columns represent variables. |
BLUSPARAM |
A AffinityParam object. |
full |
Logical scalar indicating whether the full affinity propagation statistics should be returned. |
To modify an existing AffinityParam object x
,
users can simply call x[[i]]
or x[[i]] <- value
where i
is any argument used in the constructor.
Setting q
(and less typically, p
) allows us to tune the resolution of the clustering.
In particular, when p=NA
, it is computed based on the setting of q
:
If the specified q
lies in [0, 1], p
is defined as the q
-quantile of the finite similarities across all pairs of observations.
When q=NA
, it defaults to 0.5.
If q
is negative, p
is defined as the M + abs(M) * q
where M
is the smallest finite similarity across all pairs.
This yields smaller p
values while still responding to the scale of the similarities.
The resulting value is used as the self-preference, i.e., the diagonal of the availability matrix. Larger values yield more clusters as each data point is more inclined to form its own cluster.
The AffinityParam
constructor will return a AffinityParam object with the specified parameters.
The clusterRows
method will return a factor of length equal to nrow(x)
containing the cluster assignments.
If full=TRUE
, a list is returned with clusters
(the factor, as above) and objects
(a list containing similarity
, the similarity matrix; and apcluster
, the direct output of apcluster
).
Aaron Lun
apcluster
from the apcluster package, which does all of the heavy lifting.
clusterRows(iris[,1:4], AffinityParam())
clusterRows(iris[,1:4], AffinityParam(q=0.9))
clusterRows(iris[,1:4], AffinityParam(s=apcluster::expSimMat()))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.