Hey all, I can't seem to get the princurve package to produce correct results, even in the simplest cases. For example, if you just generate a 1 period noiseless sine wave, and ask for the principal curve and plot, the returned curve is clearly wrong (doesn't follow the sine wave). Here's my code: library(princurve) x <- runif(1000,0,2*pi); x <- cbind(x/(2*pi), sin(x)) fit1 <- principal.curve(x, plot = TRUE) Anyone have any suggestions? If you run this code, do you get the correct principal curve? Any help would be really appreciated! -guy33 -- View this message in context: http://r.789695.n4.nabble.com/Problem-with-Princurve-tp3535721p3535721.html Sent from the R help mailing list archive at Nabble.com.
On May 19, 2011, at 9:43 AM, guy33 wrote:> Hey all, > > I can't seem to get the princurve package to produce correct > results, even > in the simplest cases. For example, if you just generate a 1 period > noiseless sine wave, and ask for the principal curve and plot, the > returned > curve is clearly wrong (doesn't follow the sine wave). Here's my > code: > > library(princurve) > x <- runif(1000,0,2*pi); x <- cbind(x/(2*pi), sin(x)) > fit1 <- principal.curve(x, plot = TRUE) > > Anyone have any suggestions?The rule for contributed packages which you feel can be demonstrated to give incorrect results is to contact the maintainer of the package. In this case I wonder if you even know what you are doing, however. Reading the help page for that function does not suggest to me that you should be expecting it to "go through the points" "Fits a principal curve which describes a smooth curve that passes through the middle of the data x in an orthogonal sense." The plotted curve does seem to adhere to that description with an emphasis on the last two words.> If you run this code, do you get the correct > principal curve?For the meaning assigned to "correct" by the authors, then yes. David Winsemius, MD West Hartford, CT
On Thu, 2011-05-19 at 06:43 -0700, guy33 wrote:> Hey all, > > I can't seem to get the princurve package to produce correct results, even > in the simplest cases. For example, if you just generate a 1 period > noiseless sine wave, and ask for the principal curve and plot, the returned > curve is clearly wrong (doesn't follow the sine wave). Here's my code: > > library(princurve) > x <- runif(1000,0,2*pi); x <- cbind(x/(2*pi), sin(x)) > fit1 <- principal.curve(x, plot = TRUE) > > Anyone have any suggestions? If you run this code, do you get the correct > principal curve?How about specifying some useful starting points? fit1 <- principal.curve(x, plot = TRUE, trace = TRUE, maxit = 100, start = cbind(sort(x[,1]), rep(1, nrow(x)))) And we need a few more iterations before convergence here. Starting from the first principal component for example might give useful starting points. HTH G> Any help would be really appreciated! > -guy33 > > -- > View this message in context: http://r.789695.n4.nabble.com/Problem-with-Princurve-tp3535721p3535721.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%