Skip to content

Commit

Permalink
Expose EMAlgorithm to the UI.
Browse files Browse the repository at this point in the history
  • Loading branch information
AEBilgrau committed Jan 9, 2019
1 parent c7b4815 commit 892a140
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
S3method(plot,theta)
S3method(print,theta)
S3method(summary,theta)
export(EMAlgorithm)
export(SimulateGMCMData)
export(SimulateGMMData)
export(Uhat)
Expand All @@ -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)
Expand Down
18 changes: 13 additions & 5 deletions R/EMAlgortihm.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,29 @@
#' \code{x[i, ]} is realized from the \code{j}'th component.}
#' @author Anders Ellern Bilgrau <anders.ellern.bilgrau@@gmail.com>
#' @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))
#' 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)])
#'
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.")
}
Expand Down
3 changes: 3 additions & 0 deletions inst/NEWS.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
12 changes: 9 additions & 3 deletions man/EMAlgorithm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 892a140

Please sign in to comment.