Description Usage Arguments Details Value Author(s) References See Also Examples
View source: R/functions_predkmeans.R
Uses a Mixtureofexperts algorithm to find cluster centers that are influenced by prediction covariates.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 
X 
An 
R 
Covariates used for clustering. Required unless doing kmeans
clustering (i.e. 
K 
Number of clusters 
mu 
starting values for cluster centers. If NULL (default),
then value is chosen according to 
muStart 
Character string indicating how initial value
of mu should be selected. Only used if mu=NULL. Possible
values are 
sigma2 
starting value of sigma2. If set to 
sigma2fixed 
Logical indicating whether sigma2 should be held fixed. If FALSE, then sigma2 is estimated using Maximum Likelihood. 
maxitEM 
Maximum number of EM iterations for
finding the Mixture of Experts solution. If doing regular
kmeans, this is passed as 
tol 
convergence criterion 
convEM 
controls the measure of convergence for the EM algorithm. Should be one of "mu", "gamma", or "both". Defaults to "both." The EM algorithm stops when the Frobenius norm of the change in mu, the change in gamma, or the change in mu and the change in gamma is less than 'tol'. 
nStarts 
number of times to perform EM algorithm 
maxitMlogit 
Maximum number of iterations in the mlogit optimization (nested within EM algorithm) 
verbose 
numeric vector indicating how much output to produce 
muRestart 
Gives max number of attempts at picking starting values. Only used when muStart='random'. If selected starting values for mu are constant within each cluster, then the starting values are reselected up to muRestart times. 
returnAll 
A list containing all 
... 
Additional arguments passed to 
A thorough description of this method is provided in Keller et al. (2017). The algorithm for sovling the mixture of Experts model is based upon the approach presented by Jordan and Jacobs (1994).
If sigma2
is 0 and sigm2fixed
is TRUE, then standard kmeans clustering (using kmeans
) is done instead.
An object of class predkmeans
, containing the following elements:
res.best 
A list containing the results from the bestfitting solution to the Mixture of Experts problem:

center 
Matrix of cluster centers 
cluster 
Vector of cluster labels assigned to observations 
K 
Number of clusters 
sigma2 
Final value of sigma^2. 
wSS 
Mean withincluster sumofsquares 
sigma2fixed 
Logical indicator of whether sigma2 was held fixed 
Joshua Keller
Keller, J.P., Drton, M., Larson, T., Kaufman, J.D., Sandler, D.P., and Szpiro, A.A. (2017). Covariateadaptive clustering of exposures for air pollution epidemiology cohorts. Annals of Applied Statistics, 11(1):93–113.
Jordan M. and Jacobs R. (1994). Hierarchical mixtures of experts and the EM algorithm. Neural computation 6(2), 181214.
predictML.predkmeans, predkmeansCVest
1 2 3 4 5 6 7 8 9 10 11 12 13  n < 200
r1 < rnorm(n)
r2 < rnorm(n)
u1 < rbinom(n, size=1,prob=0)
cluster < ifelse(r1<0, ifelse(u1, "A", "B"), ifelse(r2<0, "C", "D"))
mu1 < c(A=2, B=2, C=2, D=2)
mu2 < c(A=1, B=1, C=1, D=1)
x1 < rnorm(n, mu1[cluster], 4)
x2 < rnorm(n, mu2[cluster], 4)
R < model.matrix(~r1 + r2)
X < cbind(x1, x2)
pkm < predkmeans(X=cbind(x1, x2), R=R, K=4)
summary(pkm)

sh: 1: cannot create /dev/null: Permission denied
Predictive kmeans object with
4 Clusters
2 Variables
Convergence status: 9
Sigma^2 = 13.18 (Fixed = FALSE)
Withincluster SumofSquares (wSS) = 3155.3
Cluster centers are:
x1 x2
1 3.8235365 0.7720254
2 4.9685580 2.1946215
3 0.1237923 1.5749716
4 0.9317957 0.5545536
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.