[Archetypes-commits] r62 - in pkg: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Aug 1 14:01:13 CEST 2012


Author: manuel
Date: 2012-08-01 14:01:13 +0200 (Wed, 01 Aug 2012)
New Revision: 62

Modified:
   pkg/DESCRIPTION
   pkg/NAMESPACE
   pkg/NEWS
   pkg/R/archetypes-map.R
   pkg/man/archmap.Rd
   pkg/man/archmap_projections.Rd
Log:
Added extended simplex projection with archetypes arranged in relation to their distances.

Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION	2012-06-21 17:01:14 UTC (rev 61)
+++ pkg/DESCRIPTION	2012-08-01 12:01:13 UTC (rev 62)
@@ -1,43 +1,44 @@
-Package: archetypes
-Type: Package
-Title: Archetypal Analysis
-Version: 2.1-0
-Date: 2011-10-25
-Depends:
-    methods,
-    stats,
-    modeltools,
-    nnls (>= 1.1)
-Suggests:
-    MASS,
-    vcd,
-    mlbench,
-    ggplot2
-Authors at R:
-    c(person("Manuel", "J. A. Eugster", role = c("aut", "cre"),
-             email = "manuel.eugster at stat.uni-muenchen.de"),
-      person("Friedrich", "Leisch", role = "aut"))
-Description: The main function archetypes implements a
-    framework for archetypal analysis supporting arbitary
-    problem solving mechanisms for the different conceputal
-    parts of the algorithm.
-License: GPL (>= 2)
-Revision: 44
-Collate:
-    'archetypes-barplot.R'
-    'generics.R'
-    'archetypes-class.R'
-    'archetypes-kit-blocks.R'
-    'archetypes-kit.R'
-    'archetypes-movie.R'
-    'archetypes-panorama.R'
-    'pcplot.R'
-    'archetypes-pcplot.R'
-    'archetypes-robust.R'
-    'archetypes-screeplot.R'
-    'archetypes-step.R'
-    'archetypes-weighted.R'
-    'archetypes-xyplot.R'
-    'memento.R'
-    'skeletonplot.R'
-    'archetypes-map.R'
+Package: archetypes
+Type: Package
+Title: Archetypal Analysis
+Version: 2.1-1
+Date: 2011-10-25
+Depends:
+    methods,
+    stats,
+    modeltools,
+    nnls (>= 1.1)
+Suggests:
+    MASS,
+    vcd,
+    mlbench,
+    ggplot2,
+    TSP
+Authors at R: c(person("Manuel", "J. A. Eugster", role = c("aut", "cre"),
+    email = "manuel.eugster at stat.uni-muenchen.de"),
+    person("Friedrich", "Leisch", role = "aut"))
+Description: The main function archetypes implements a
+    framework for archetypal analysis supporting arbitary
+    problem solving mechanisms for the different conceputal
+    parts of the algorithm.
+License: GPL (>= 2)
+Revision: 44
+Collate:
+    'archetypes-barplot.R'
+    'generics.R'
+    'archetypes-class.R'
+    'archetypes-kit-blocks.R'
+    'archetypes-kit.R'
+    'archetypes-movie.R'
+    'archetypes-panorama.R'
+    'pcplot.R'
+    'archetypes-pcplot.R'
+    'archetypes-robust.R'
+    'archetypes-screeplot.R'
+    'archetypes-step.R'
+    'archetypes-weighted.R'
+    'archetypes-xyplot.R'
+    'memento.R'
+    'skeletonplot.R'
+    'archetypes-map.R'
+    'deploy.R'

Modified: pkg/NAMESPACE
===================================================================
--- pkg/NAMESPACE	2012-06-21 17:01:14 UTC (rev 61)
+++ pkg/NAMESPACE	2012-08-01 12:01:13 UTC (rev 62)
@@ -16,6 +16,7 @@
 export(simplex_projection)
 export(skeletonplot)
 export(stepArchetypes)
+export(tspsimplex_projection)
 export(weightedArchetypes)
 export(xyplot)
 exportMethods(parameters)

Modified: pkg/NEWS
===================================================================
--- pkg/NEWS	2012-06-21 17:01:14 UTC (rev 61)
+++ pkg/NEWS	2012-08-01 12:01:13 UTC (rev 62)
@@ -3,7 +3,10 @@
 
   o Fixed bug in movieplot2.
 
+  o Added extended simplex projection 'tspsimplex_projection' (based
+    on TSP) for archetypal maps.
 
+
 Changes in archetypes version 2.1-0
 
   o Roxygen2-ified; added the Build-dep field to the DESCRIPTION

Modified: pkg/R/archetypes-map.R
===================================================================
--- pkg/R/archetypes-map.R	2012-06-21 17:01:14 UTC (rev 61)
+++ pkg/R/archetypes-map.R	2012-08-01 12:01:13 UTC (rev 62)
@@ -7,6 +7,8 @@
 #' @param object An \code{\link{archetypes}} object
 #' @param projection Projection function; see
 #'   \code{\link{archmap_projections}}
+#' @param projection_args Arguments passed to the projection function;
+#'   see \code{\link{archmap_projections}} 
 #' @param rotate Rotation angle to rotate the projection
 #' @param cex Character expansion of archetypes
 #' @param col Color of observations
@@ -30,13 +32,23 @@
 #'   ## Simplex projection:
 #'   archmap(a, col = skel$Gender)
 #'
+#'   ## Simplex projection with archetypes arranged according to their
+#'   ## distances:
+#'   archmap(a, col = skel$Gender,
+#'           projection = tspsimplex_projection)
+#'   archmap(a, col = skel$Gender,
+#'           projection = tspsimplex_projection,
+#'           projection_args = list(equidist = TRUE))
+#'
 #'   ## MDS projection:
-#'   archmap(a, projection = atypes_projection, col = skel$Gender)
+#'   archmap(a, col = skel$Gender,
+#'           projection = atypes_projection)
 #'
 #' @family archmap
 #'
 #' @export
-archmap <- function(object, projection = simplex_projection, rotate = 0,
+archmap <- function(object, projection = simplex_projection,
+                    projection_args = list(), rotate = 0,
                     cex = 1.5, col = 1, pch = 1, xlab = "", ylab = "",
                     axes = FALSE, asp = TRUE, ...) {
 
@@ -49,7 +61,7 @@
     }
 
     ## Projection:
-    cmds <- projection(parameters(object))
+    cmds <- do.call(projection, c(list(parameters(object)), projection_args))
 
 
     ## Rotation:
@@ -98,16 +110,39 @@
 #' @rdname archmap_projections
 #' @export
 simplex_projection <- function(x, r = 10) {
-  n <- nrow(x)
+  phi <- seq(-pi, pi, length.out = nrow(x) + 1)
+  phi <- phi[-1]
 
-  phi <- seq(-pi, pi, length.out = n + 1)
+  cbind(x = r * cos(phi),
+        y = r * sin(phi))
+}
 
-  x <- r * cos(phi)
-  y <- r * sin(phi)
 
-  m <- cbind(x, y)
 
-  m[-1, ]
+#' @param equidist Arrange archetypes equidistantly or in relation to
+#'   their distance
+#' @param ... Parameters for the \code{\link[TSP]{solve_TSP}} function
+#' @rdname archmap_projections
+#' @export
+tspsimplex_projection <- function(x, r = 10, equidist = FALSE, ...) {
+  stopifnot(require("TSP"))
+ 
+  d <- dist(x)
+  xo <- as.integer(solve_TSP(TSP(d), ...))
+  
+  if ( equidist ) {
+    phi <- seq(-pi, pi, length.out = nrow(x) + 1)
+    phi <- phi[-1][xo]
+  } else {
+    d <- as.matrix(d)
+    phi <- mapply(function(i, j) d[i, j], xo, c(tail(xo, -1), xo[1]))
+    phi <- c(0, cumsum(phi) / sum(phi))
+    phi <- phi * 2 * pi - pi
+    phi <- phi[-1]
+  }
+
+  cbind(x = r * cos(phi),
+        y = r * sin(phi))
 }
 
 

Modified: pkg/man/archmap.Rd
===================================================================
--- pkg/man/archmap.Rd	2012-06-21 17:01:14 UTC (rev 61)
+++ pkg/man/archmap.Rd	2012-08-01 12:01:13 UTC (rev 62)
@@ -3,8 +3,9 @@
 \title{Archetypal maps}
 \usage{
   archmap(object, projection = simplex_projection,
-    rotate = 0, cex = 1.5, col = 1, pch = 1, xlab = "",
-    ylab = "", axes = FALSE, asp = TRUE, ...)
+    projection_args = list(), rotate = 0, cex = 1.5,
+    col = 1, pch = 1, xlab = "", ylab = "", axes = FALSE,
+    asp = TRUE, ...)
 }
 \arguments{
   \item{object}{An \code{\link{archetypes}} object}
@@ -12,6 +13,9 @@
   \item{projection}{Projection function; see
   \code{\link{archmap_projections}}}
 
+  \item{projection_args}{Arguments passed to the projection
+  function; see \code{\link{archmap_projections}}}
+
   \item{rotate}{Rotation angle to rotate the projection}
 
   \item{cex}{Character expansion of archetypes}
@@ -49,11 +53,21 @@
   ## Simplex projection:
   archmap(a, col = skel$Gender)
 
+  ## Simplex projection with archetypes arranged according to their
+  ## distances:
+  archmap(a, col = skel$Gender,
+          projection = tspsimplex_projection)
+  archmap(a, col = skel$Gender,
+          projection = tspsimplex_projection,
+          projection_args = list(equidist = TRUE))
+
   ## MDS projection:
-  archmap(a, projection = atypes_projection, col = skel$Gender)
+  archmap(a, col = skel$Gender,
+          projection = atypes_projection)
 }
 \seealso{
   Other archmap: \code{\link{atypes_projection}},
-  \code{\link{simplex_projection}}
+  \code{\link{simplex_projection}},
+  \code{\link{tspsimplex_projection}}
 }
 

Modified: pkg/man/archmap_projections.Rd
===================================================================
--- pkg/man/archmap_projections.Rd	2012-06-21 17:01:14 UTC (rev 61)
+++ pkg/man/archmap_projections.Rd	2012-08-01 12:01:13 UTC (rev 62)
@@ -2,16 +2,25 @@
 \alias{archmap_projections}
 \alias{atypes_projection}
 \alias{simplex_projection}
+\alias{tspsimplex_projection}
 \title{Archetypal map projections}
 \usage{
   simplex_projection(x, r = 10)
 
+  tspsimplex_projection(x, r = 10, equidist = FALSE, ...)
+
   atypes_projection(x)
 }
 \arguments{
   \item{x}{Archetypes matrix}
 
   \item{r}{Radius of the simplex projection}
+
+  \item{equidist}{Arrange archetypes equidistantly or in
+  relation to their distance}
+
+  \item{...}{Parameters for the
+  \code{\link[TSP]{solve_TSP}} function}
 }
 \value{
   Matrix with the projected archetypes



More information about the Archetypes-commits mailing list