dissrf: Relative Frequency Groups.

View source: R/dissrf.R

dissrfR Documentation

Relative Frequency Groups.


Relative Frequency (RF) groups are equally sized groups obtained by partitioning sorted cases into k consecutive groups. Function dissrf returns the medoid indexes of the RF groups and related statistics. Function seqrf is for sequence data and returns in addition the RF medoid sequences.


       grp.meth = "prop",
       squared = FALSE,
       pow = NULL)

       grp.meth = "prop",
       squared = FALSE,
       pow = NULL)

## S3 method for class 'dissrf'
summary(object, dist.idx = 1:10, ...)

## S3 method for class 'seqrf'
summary(object, format="SPS", dist.idx = 1:10, ...)



Matrix or distance object. Pairwise dissimilarities between analyzed cases.


State sequence stslist object as produced by seqdef.


Integer: Number of groupings (RF groups). When NULL, k is set as the minimum between 100 and the sum of weights over 10.


Real vector (of length nrow(diss)), character string, or NULL. Sorting variable used to compute the frequency groups. If NULL, the original data order is used. If "mds" (default), the first MDS factor of diss (diss^2 when squared=TRUE) is used. Ties are randomly ordered. For seqrf only, can also be one of "from.start" and "from.end".


Vector (of length nrow(diss)) of non-negative weights. If NULL (default), equal weights except when weighted is set as TRUE in seqrf.


Logical. Should weights be used when there are weights in seqdata? (default is TRUE)


Character string. One of "prop", "first", and "random". Grouping method. See details.


Logical. Should medoids (and computation of sortv when applicable) be based on squared dissimilarities? (default is FALSE)


Double. Dissimilarity power exponent (typically 1 or 2) for computation of pseudo R2 and F. When NULL, pow is set as 1 when squared = FALSE, and as 2 otherwise.


further arguments passed to or from other methods such as print.stslist


Object of class dissrf or seqrf


String. One of "SPS" (default) or "STS". Display format of the medoid sequences.


Indexes of RF groups for which summary statistics of distances to the medoids are displayed. Default is 1:10. Set as 0 to plot statistics for all RF groups.


Function dissrf partitions the n cases (rows of the diss matrix) into k equally sized groups (RF groups). First, the cases are sorted according to the sortv variable. Then the groups are built by consecutively grouping the first n/k cases, then the next n/k cases, and so on. In seqrf, one of sort methods "from.start" and "from.end" can be specified as sortv argument.

Ties in the sortv variable are handled by order using the default method, which produces stable outcome. To use a different method, compute a suited variable without ties (e.g. using order with the wanted method for ties) and pass it as sortv argument.

The grp.meth argument applies when the group size (n/k) is not integer. With grp.meth="first", the integer part of n/k is used as basic group size and the size of the first groups is augmented by one unit so that the sum of the group sizes equals n. With grp.meth="random", randomly selected groups have their size augmented by one unit, and with grp.meth="prop" (default), cases at the limit between groups are proportionally assigned to each of the two groups.

For seqrf, when weights=NULL and weighted=TRUE, weights is set as the weights attribute of seqdata.

When weights is non-null (dissrf) or when wheighted=TRUE and there are weights in seqdata (seqrf), only grp.meth="prop" applies.

The function computes indicative statistics of the resulting partition, namely a pseudo R2 and a pseudo F statistics. These statistics compare the mean distance to the group medoid with the mean distance to the overall medoid. When pow is 2, mean squared dissimilarities are used and when pow is 1 the R2 and F ratios are based on mean of non-squared dissimilarities. An indicative p-value of the F statistics is computed using the F distribution. This p-value should be interpreted with caution since F is not a true F value.


dissrf returns a list of class dissrfprop when grp.meth="prop" and of class dissrfcrisp otherwise. In both cases the list also receives class "dissrf". The elements of the list are:


index of the group medoids


names (diss colnames) of the group medoids


working matrix used by the "prop" procedure (class dissrfprop only)


list with for each successive group the distances from its elements to the group medoid


list with for each successive group the index of its elements


list with for each successive group the weights of its elements in the group


relative group size, which may be different when grp.meth is "first" or "random"


vector with for each case the index of its group medoid (class dissrfcrisp only)


vector with for each case the distance to its group medoid (class dissrfcrisp only)


vector of group membership (class dissrfcrisp only)


positions for the boxplots of distances to group medoids


Pseudo R2: Mean distance to the group medoids over mean distance to the overall medoid


Pseudo F statistics


p-value of the pseudo F (to be used with caution since F is not a true F value)


ncase (number of cases), wsum (sum of weights), k (number of groups), gsize (group size)


grouping method used

seqrf returns a list of class seqrfprop when grp.meth="prop" and of class seqrfcrisp otherwise. In both cases the list also receives class "seqrf". The elements of the list are:


RF medoid sequences as a state sequence stslist object


the associated dissrf object

There are print and summary methods for objects of class dissrf and seqrf, and a plot method for objects of class seqrf


Gilbert Ritschard.


Fasang, Anette Eva and Tim F. Liao. 2014. "Visualizing Sequences in the Social Sciences: Relative Frequency Sequence Plots." Sociological Methods & Research 43(4):643-676.

See Also

plot.seqrf, seqrfplot, dissrep, and seqrep


## Defining a sequence object with the data in columns 10 to 25
## (family status from age 15 to 30) in the biofam data set
biofam.lab <- c("Parent", "Left", "Married", "Left+Marr",
"Child", "Left+Child", "Left+Marr+Child", "Divorced")

## Here, we use only 100 cases selected such that all elements
## of the alphabet be present.
## (More cases and a larger k would be necessary to get a meaningful example.)
biofam.seq <- seqdef(biofam[501:600, 10:25], labels=biofam.lab,
diss <- seqdist(biofam.seq, method="LCS")

## Using 12 groups, default MDS sorting,
##  and original method by Fasang and Liao (2014)
dissrf(diss=diss, k=12, grp.meth="first")

## Using 12 groups, weights, default MDS sorting,
##  and default "prop" method
w <- attr(biofam.seq, "weights")
dissrf(diss=diss, k=12, weights=w)

## With a user specified sorting variable
## Here time spent in parental home, which has ties
parentTime <- seqistatd(biofam.seq)[, 1]
b.srf <- seqrf(biofam.seq, diss=diss, k=12, sortv=parentTime)

## print, summary, and plot methods
plot(b.srf, which.plot="both")

TraMineR documentation built on Sept. 19, 2023, 1:07 a.m.