[Analogue-commits] r308 - in pkg: R inst tests/Examples

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Mar 18 06:14:49 CET 2013


Author: gsimpson
Date: 2013-03-18 06:14:48 +0100 (Mon, 18 Mar 2013)
New Revision: 308

Modified:
   pkg/R/prcurve.R
   pkg/R/smoothSpline.R
   pkg/inst/ChangeLog
   pkg/tests/Examples/analogue-Ex.Rout.save
Log:
prcurve now returns a 'smooths' component, a list of smoothers, one per variable.

Modified: pkg/R/prcurve.R
===================================================================
--- pkg/R/prcurve.R	2013-03-18 02:44:49 UTC (rev 307)
+++ pkg/R/prcurve.R	2013-03-18 05:14:48 UTC (rev 308)
@@ -80,12 +80,15 @@
     converged <- (abs((dist.old - config$dist)/dist.old) <=
                   thresh)
     ## Start iterations ----------------------------------------------
+    ### - store fitted smoothers in list
+    smooths <- vector(mode = "list", length = m)
     while (!converged && iter < maxit) {
         iter <- iter + 1L
         for(j in seq_len(m)) {
-            s[, j] <- fitted(smoother(config$lambda, X[, j],
-                                      complexity = complexity[j],
-                                      choose = FALSE, ...))
+          smooths[[j]] <- smoother(config$lambda, X[, j],
+                                   complexity = complexity[j],
+                                   choose = FALSE, ...)
+            s[, j] <- fitted(smooths[[j]])
         }
         ##
         dist.old <- config$dist
@@ -113,19 +116,28 @@
     if(finalCV) {
         iter <- iter + 1L
         for(j in seq_len(n)) {
-            sFit <- smoother(config$lambda, X[, j],
-                             cv = TRUE, choose = TRUE, ...)
-            s[, j] <- if(sFit$complexity > maxComp) {
-                ## too complex, turn of CV and refit with max df allowed
-                fitted(smoother(config$lambda, X[, j], cv = FALSE,
-                                choose = FALSE,
-                                complexity = maxComp,
-                                ...))
-            } else {
-                fitted(sFit)
-            }
+          smooths[[j]] <- smoother(config$lambda, X[, j],
+                                   cv = TRUE, choose = TRUE, ...)
+          if(smooths[[j]]$complexity > maxComp) {
+            smooths[[j]] <- smoother(config$lambda, X[, j], cv = FALSE,
+                                     choose = FALSE,
+                                     complexity = maxComp,
+                                     ...)
+          }
+          s[, j] <- fitted(smooths[[j]])
+            ## sFit <- smoother(config$lambda, X[, j],
+            ##                  cv = TRUE, choose = TRUE, ...)
+            ## s[, j] <- if(sFit$complexity > maxComp) {
+            ##     ## too complex, turn of CV and refit with max df allowed
+            ##     fitted(smoother(config$lambda, X[, j], cv = FALSE,
+            ##                     choose = FALSE,
+            ##                     complexity = maxComp,
+            ##                     ...))
+            ## } else {
+            ##     fitted(sFit)
+            ## }
         }
-        config <- get.lam(X, s = config$s, stretch = stretch)
+        config <- get.lam(X, s = s, stretch = stretch)
         class(config) <- "prcurve"
         if(plotit) {
             ## plot the iteration
@@ -154,6 +166,7 @@
     config$totalDist <- startConfig$dist
     config$complexity <- complexity
     ## config$fitFUN <- fitFUN
+    config$smooths <- smooths
     config$call <- match.call()
     class(config) <- c("prcurve")
     return(config)

Modified: pkg/R/smoothSpline.R
===================================================================
--- pkg/R/smoothSpline.R	2013-03-18 02:44:49 UTC (rev 307)
+++ pkg/R/smoothSpline.R	2013-03-18 05:14:48 UTC (rev 308)
@@ -24,7 +24,7 @@
     }
     p <- predict(f, x=lambda)$y
     res <- list(lambda = lambda, x = x, fitted.values = p,
-                complexity = f$df)
+                complexity = f$df, model = f)
     class(res) <- "prcurveSmoother"
     return(res)
 }

Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog	2013-03-18 02:44:49 UTC (rev 307)
+++ pkg/inst/ChangeLog	2013-03-18 05:14:48 UTC (rev 308)
@@ -9,6 +9,11 @@
 	a fitted principal curve to be added to an existing PCA
 	plot.
 
+	* prcurve, smoothSpline: `prcurve` now returns a component
+	`smooths`, a list containing the fitted smoothers, one per
+	variable. As a result `smoothSpline` now also returns the
+	fitted `smooth.spline` model.
+
 	* gradientDist: the "prcurve" method was ordering the samples
 	such that they were smooth. No need for the `order` argument
 	now either.

Modified: pkg/tests/Examples/analogue-Ex.Rout.save
===================================================================
--- pkg/tests/Examples/analogue-Ex.Rout.save	2013-03-18 02:44:49 UTC (rev 307)
+++ pkg/tests/Examples/analogue-Ex.Rout.save	2013-03-18 05:14:48 UTC (rev 308)
@@ -1,6 +1,6 @@
 
-R version 2.15.2 Patched (2012-12-05 r61228) -- "Trick or Treat"
-Copyright (C) 2012 The R Foundation for Statistical Computing
+R version 2.15.3 RC (2013-02-25 r62062) -- "Security Blanket"
+Copyright (C) 2013 The R Foundation for Statistical Computing
 ISBN 3-900051-07-0
 Platform: x86_64-unknown-linux-gnu (64-bit)
 
@@ -24,11 +24,10 @@
 > library('analogue')
 Loading required package: vegan
 Loading required package: permute
-This is vegan 2.0-5
+This is vegan 2.0-6
+Loading required package: princurve
 Loading required package: lattice
-Loading required package: grid
-Loading required package: princurve
-This is analogue 0.11-0
+This is analogue 0.11-1
 > 
 > assign(".oldSearch", search(), pos = 'CheckExEnv')
 > cleanEx()
@@ -5882,7 +5881,7 @@
 > 
 > ### Name: plot.prcurve
 > ### Title: Plot a fitted principal curve in PCA space
-> ### Aliases: plot.prcurve
+> ### Aliases: plot.prcurve lines.prcurve
 > ### Keywords: hplot
 > 
 > ### ** Examples
@@ -5895,8 +5894,8 @@
 > 
 > ## Fit the principal curve using varying complexity of smoothers
 > ## for each species
-> aber.pc2 <- prcurve(abernethy2, method = "ca", trace = TRUE,
-+                     vary = TRUE, penalty = 1.4)
+> aber.pc <- prcurve(abernethy2, method = "ca", trace = TRUE,
++                    vary = TRUE, penalty = 1.4)
 --------------------------------------------------------------------------------
 Initial curve: d.sq: 103233.4502
 Iteration   1: d.sq: 4283.4308
@@ -5910,10 +5909,16 @@
 --------------------------------------------------------------------------------
 > 
 > ## Plot the curve
-> plot(aber.pc2, abernethy2)
+> plot(aber.pc, abernethy2)
 > 
+> ## The lines() method can be used to add the principal curve to an
+> ## existing plot
+> ord <- rda(abernethy2)
+> plot(ord)
+> lines(aber.pc, data = abernethy2)
 > 
 > 
+> 
 > cleanEx()
 > nameEx("plot.residLen")
 > ### * plot.residLen
@@ -7361,7 +7366,7 @@
 > ### * <FOOTER>
 > ###
 > cat("Time elapsed: ", proc.time() - get("ptime", pos = 'CheckExEnv'),"\n")
-Time elapsed:  21.325 0.23 22.692 0 0 
+Time elapsed:  20.031 0.239 21.127 0 0 
 > grDevices::dev.off()
 null device 
           1 



More information about the Analogue-commits mailing list