Package ‘e1071’
February 2, 2017
Version 1.6-8
Title Misc Functions of the Department of Statistics, Probability
Theory Group (Formerly: E1071), TU Wien
Imports graphics, grDevices, class, stats, methods, utils
Suggests cluster, mlbench, nnet, randomForest, rpart, SparseM, xtable,
Matrix, MASS
Description Functions for latent class analysis, short time Fourier
transform, fuzzy clustering, support vector machines,
shortest path computation, bagged clustering, naive Bayes
classifier, …
License GPL-2
LazyLoad yes
NeedsCompilation yes
Author David Meyer [aut, cre],
Evgenia Dimitriadou [aut, cph],
Kurt Hornik [aut],
Andreas Weingessel [aut],
Friedrich Leisch [aut],
Chih-Chung Chang [ctb, cph] (libsvm C++-code),
Chih-Chen Lin [ctb, cph] (libsvm C++-code)
Maintainer David Meyer
Repository CRAN
Date/Publication 2017-02-02 12:37:10
R topics documented:
allShortestPaths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
bclust . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
bincombinations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
bootstrap.lca . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
boxplot.bclust . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
classAgreement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1
2 R topics documented:
cmeans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
countpattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
cshell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Discrete . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
e1071-deprecated . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
fclustIndex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
hamming.distance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
hamming.window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
hanning.window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
hsv_palette . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
ica . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
impute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
interpolate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
kurtosis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
lca . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
matchClasses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
matchControls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
moment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
naiveBayes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
permutations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
plot.stft . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
plot.svm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
plot.tune . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
predict.svm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
probplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
rbridge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
read.matrix.csr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
rectangle.window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
rwiener . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
sigmoid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
skewness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
stft . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
svm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
tune . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
tune.control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
tune.wrapper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
write.svm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Index 60
allShortestPaths 3
allShortestPaths Find Shortest Paths Between All Nodes in a Directed Graph
Description
allShortestPaths finds all shortest paths in a directed (or undirected) graph using Floyd’s algo-
rithm. extractPath can be used to actually extract the path between a given pair of nodes.
Usage
allShortestPaths(x)
extractPath(obj, start, end)
Arguments
x matrix or distance object
obj return value of allShortestPaths
start integer, starting point of path
end integer, end point of path
Details
If x is a matrix, then x[i,j] has to be the length of the direct path from point i to point j. If no
direct connection from point i to point j exist, then x[i,j] should be either NA or Inf. Note that
the graph can be directed, hence x[i,j] need not be the same as x[j,i]. The main diagonal of
x is ignored. Alternatively, x can be a distance object as returned by dist (corresponding to an
undirected graph).
Value
allShortestPaths returns a list with components
length A matrix with the total lengths of the shortest path between each pair of points.
middlePoints A matrix giving a point in the middle of each shortest path (or 0 if the direct
connection is the shortest path), this is mainly used as input for extractPath.
extractPath returns a vector of node numbers giving with the shortest path between two points.
Author(s)
Friedrich Leisch
References
Kumar, V., Grama, A., Gupta, A. and Karypis, G. Introduction to Parallel Programming – Design
and Analysis of Algorithms, Benjamin Cummings Publishing, 1994, ISBN 0-8053-3170-0
4 bclust
Examples
## build a graph with 5 nodes
x <- matrix(NA, 5, 5)
diag(x) <- 0
x[1,2] <- 30; x[1,3] <- 10
x[2,4] <- 70; x[2,5] <- 40
x[3,4] <- 50; x[3,5] <- 20
x[4,5] <- 60
x[5,4] <- 10
print(x)
## compute all path lengths
z <- allShortestPaths(x)
print(z)
## the following should give 1 -> 3 -> 5 -> 4
extractPath(z, 1, 4)
bclust Bagged Clustering
Description
Cluster the data in x using the bagged clustering algorithm. A partitioning cluster algorithm such as
kmeans is run repeatedly on bootstrap samples from the original data. The resulting cluster centers
are then combined using the hierarchical cluster algorithm hclust.
Usage
bclust(x, centers=2, iter.base=10, minsize=0,
dist.method=”euclidian”,
hclust.method=”average”, base.method=”kmeans”,
base.centers=20, verbose=TRUE,
final.kmeans=FALSE, docmdscale=FALSE,
resample=TRUE, weights=NULL, maxcluster=base.centers, …)
hclust.bclust(object, x, centers, dist.method=object$dist.method,
hclust.method=object$hclust.method, final.kmeans=FALSE,
docmdscale = FALSE, maxcluster=object$maxcluster)
## S3 method for class ‘bclust’
plot(x, maxcluster=x$maxcluster, main, …)
centers.bclust(object, k)
clusters.bclust(object, k, x=NULL)
Arguments
x Matrix of inputs (or object of class “bclust” for plot).
centers, k Number of clusters.
bclust 5
iter.base Number of runs of the base cluster algorithm.
minsize Minimum number of points in a base cluster.
dist.method Distance method used for the hierarchical clustering, see dist for available dis-
tances.
hclust.method Linkage method used for the hierarchical clustering, see hclust for available
methods.
base.method Partitioning cluster method used as base algorithm.
base.centers Number of centers used in each repetition of the base method.
verbose Output status messages.
final.kmeans If TRUE, a final kmeans step is performed using the output of the bagged cluster-
ing as initialization.
docmdscale Logical, if TRUE a cmdscale result is included in the return value.
resample Logical, if TRUE the base method is run on bootstrap samples of x, else directly
on x.
weights Vector of length nrow(x), weights for the resampling. By default all observa-
tions have equal weight.
maxcluster Maximum number of clusters memberships are to be computed for.
object Object of class “bclust”.
main Main title of the plot.
… Optional arguments top be passed to the base method in bclust, ignored in
plot.
Details
First, iter.base bootstrap samples of the original data in x are created by drawing with replace-
ment. The base cluster method is run on each of these samples with base.centers centers. The
base.method must be the name of a partitioning cluster function returning a list with the same
components as the return value of kmeans.
This results in a collection of iter.base * base.centers centers, which are subsequently clus-
tered using the hierarchical method hclust. Base centers with less than minsize points in there
respective partitions are removed before the hierarchical clustering.
The resulting dendrogram is then cut to produce centers clusters. Hence, the name of the argument
centers is a little bit misleading as the resulting clusters need not be convex, e.g., when single
linkage is used. The name was chosen for compatibility with standard partitioning cluster methods
such as kmeans.
A new hierarchical clustering (e.g., using another hclust.method) re-using previous base runs can
be performed by running hclust.bclust on the return value of bclust.
Value
bclust and hclust.bclust return objects of class “bclust” including the components
hclust Return value of the hierarchical clustering of the collection of base centers (Ob-
ject of class “hclust”).
6 bincombinations
cluster Vector with indices of the clusters the inputs are assigned to.
centers Matrix of centers of the final clusters. Only useful, if the hierarchical clustering
method produces convex clusters.
allcenters Matrix of all iter.base * base.centers centers found in the base runs.
Author(s)
Friedrich Leisch
References
Friedrich Leisch. Bagged clustering. Working Paper 51, SFB “Adaptive Information Systems and
Modeling in Economics and Management Science”, August 1999. http://epub.wu.ac.at/1272/
1/document.pdf
See Also
hclust, kmeans, boxplot.bclust
Examples
data(iris)
bc1 <- bclust(iris[,1:4], 3, base.centers=5)
plot(bc1)
table(clusters.bclust(bc1, 3))
centers.bclust(bc1, 3)
bincombinations Binary Combinations
Description
Returns a matrix containing the 2p vectors of length p.
Usage
bincombinations(p)
Arguments
p Length of binary vectors
Author(s)
Friedrich Leisch
http://epub.wu.ac.at/1272/1/document.pdf
http://epub.wu.ac.at/1272/1/document.pdf
bootstrap.lca 7
Examples
bincombinations(2)
bincombinations(3)
bootstrap.lca Bootstrap Samples of LCA Results
Description
This function draws bootstrap samples from a given LCA model and refits a new LCA model for
each sample. The quality of fit of these models is compared to the original model.
Usage
bootstrap.lca(l, nsamples=10, lcaiter=30, verbose=FALSE)
Arguments
l An LCA model as created by lca
nsamples Number of bootstrap samples
lcaiter Number of LCA iterations
verbose If TRUE some output is printed during the computations.
Details
From a given LCA model l, nsamples bootstrap samples are drawn. For each sample a new LCA
model is fitted. The goodness of fit for each model is computed via Likelihood Ratio and Pearson’s
Chisquare. The values for the fitted models are compared with the values of the original model l.
By this method it can be tested whether the data to which l was originally fitted come from an LCA
model.
Value
An object of class bootstrap.lca is returned, containing
logl, loglsat The LogLikelihood of the models and of the corresponding saturated models
lratio Likelihood quotient of the models and the corresponding saturated models
lratiomean, lratiosd
Mean and Standard deviation of lratio
lratioorg Likelihood quotient of the original model and the corresponding saturated model
zratio Z-Statistics of lratioorg
pvalzratio, pvalratio
P-Values for zratio, computed via normal distribution and empirical distribu-
tion
chisq Pearson’s Chisq of the models
8 boxplot.bclust
chisqmean, chisqsd
Mean and Standard deviation of chisq
chisqorg Pearson’s Chisq of the original model
zchisq Z-Statistics of chisqorg
pvalzchisq, pvalchisq
P-Values for zchisq, computed via normal distribution and empirical distribu-
tion
nsamples Number of bootstrap samples
lcaiter Number of LCA Iterations
Author(s)
Andreas Weingessel
References
Anton K. Formann: “Die Latent-Class-Analysis”, Beltz Verlag 1984
See Also
lca
Examples
## Generate a 4-dim. sample with 2 latent classes of 500 data points each.
## The probabilities for the 2 classes are given by type1 and type2.
type1 <- c(0.8,0.8,0.2,0.2)
type2 <- c(0.2,0.2,0.8,0.8)
x <- matrix(runif(4000),nr=1000)
x[1:500,] <- t(t(x[1:500,])