diff --git a/NAMESPACE b/NAMESPACE index bc55060..76e1d65 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,6 +3,7 @@ S3method(plot,theta) S3method(print,theta) S3method(summary,theta) +export(EMAlgorithm) export(SimulateGMCMData) export(SimulateGMMData) export(Uhat) @@ -24,6 +25,7 @@ importFrom(graphics,contour) importFrom(graphics,lines) importFrom(graphics,points) importFrom(stats,approxfun) +importFrom(stats,cov) importFrom(stats,cov.wt) importFrom(stats,cov2cor) importFrom(stats,kmeans) diff --git a/R/EMAlgortihm.R b/R/EMAlgortihm.R index f304216..e80195e 100644 --- a/R/EMAlgortihm.R +++ b/R/EMAlgortihm.R @@ -30,11 +30,19 @@ #' \code{x[i, ]} is realized from the \code{j}'th component.} #' @author Anders Ellern Bilgrau #' @seealso \code{\link{rtheta}}, \code{\link{PseudoEMAlgorithm}} +#' @importFrom stats cov #' @examples +#' set.seed(3) +#' true.theta <- rtheta(d = 2, m = 3, method = "old") +#' true.theta$sigma <- lapply(true.theta$sigma, cov2cor) # Scale +#' \dontrun{ +#' plot(true.theta, nlevels = 20, add.ellipses = TRUE) +#' } #' -#' set.seed(10) -#' data <- SimulateGMCMData(n = 1000, d = 2, m = 3) +#' data <- SimulateGMCMData(n = 1000, theta = true.theta) #' start.theta <- rtheta(d = 2, m = 3) +#' start.theta$mu <- t(kmeans(data$z, 3)$centers) # More sensible location estimates +#' start.theta <- as.theta(start.theta) # Coerce the matrix to a list #' res <- GMCM:::EMAlgorithm(data$z, theta = start.theta) #' #' par(mfrow = c(1,2)) @@ -42,9 +50,9 @@ #' col = rainbow(3)[data$K]) #' plot(data$z, cex = 0.5, pch = 16, main = "GMM clustering", #' col = rainbow(3)[apply(res$kappa,1,which.max)]) -#' -EMAlgorithm <- function (x, theta, m, eps = 1e-6, max.ite = 1e5, - trace.theta = FALSE, verbose = FALSE) { +#'@export +EMAlgorithm <- function(x, theta, m, eps = 1e-6, max.ite = 1e5, + trace.theta = FALSE, verbose = FALSE) { if (missing(m) && missing(theta)) { stop("Either m or theta should be provided.") } diff --git a/inst/NEWS.Rd b/inst/NEWS.Rd index 552b5d2..10cccf0 100644 --- a/inst/NEWS.Rd +++ b/inst/NEWS.Rd @@ -5,8 +5,11 @@ \section{Changes in version 1.3.1 (2018-MM-DD)}{ \itemize{ + \item By request, \code{EMAlgorithm} is now exported to the user interface. + A better example is also provided. \item Minor improvements to documentation. } +} \section{Changes in version 1.3 (2018-12-05)}{ \itemize{ diff --git a/man/EMAlgorithm.Rd b/man/EMAlgorithm.Rd index 3067fab..ed3621f 100644 --- a/man/EMAlgorithm.Rd +++ b/man/EMAlgorithm.Rd @@ -47,10 +47,17 @@ to \code{Mclust} in the \code{mclust}-package. If \code{theta} is not given, a k-means clustering is used to determine the initial \code{theta}. } \examples{ +set.seed(3) +true.theta <- rtheta(d = 2, m = 3, method = "old") +true.theta$sigma <- lapply(true.theta$sigma, cov2cor) # Scale +\dontrun{ +plot(true.theta, nlevels = 20, add.ellipses = TRUE) +} -set.seed(10) -data <- SimulateGMCMData(n = 1000, d = 2, m = 3) +data <- SimulateGMCMData(n = 1000, theta = true.theta) start.theta <- rtheta(d = 2, m = 3) +start.theta$mu <- t(kmeans(data$z, 3)$centers) # More sensible location estimates +start.theta <- as.theta(start.theta) # Coerce the matrix to a list res <- GMCM:::EMAlgorithm(data$z, theta = start.theta) par(mfrow = c(1,2)) @@ -58,7 +65,6 @@ plot(data$z, cex = 0.5, pch = 16, main = "Simulated data", col = rainbow(3)[data$K]) plot(data$z, cex = 0.5, pch = 16, main = "GMM clustering", col = rainbow(3)[apply(res$kappa,1,which.max)]) - } \seealso{ \code{\link{rtheta}}, \code{\link{PseudoEMAlgorithm}}