Hi, Is it possible to recreate "smoothed" data sets in R, by performing a PCA and then reconstructing a data set from say the first 2/3 EOFs? I've had a look in the help pages and don't seem to find anything relevant. Thanks in advance, Laura Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: laura at env.leeds.ac.uk
Laura Quinn a ?crit :> Hi, > > Is it possible to recreate "smoothed" data sets in R, by performing a PCA > and then reconstructing a data set from say the first 2/3 EOFs? > > I've had a look in the help pages and don't seem to find anything > relevant.See function reconst in package ade4. Best, Renaud -- Dr Renaud Lancelot, v?t?rinaire C/0 Ambassade de France - SCAC BP 834 Antananarivo 101 - Madagascar e-mail: renaud.lancelot at cirad.fr tel.: +261 32 40 165 53 (cell) +261 20 22 665 36 ext. 225 (work) +261 20 22 494 37 (home)
On Tue, 2005-03-01 at 20:30 +0000, Laura Quinn wrote:> Hi, > > Is it possible to recreate "smoothed" data sets in R, by performing a PCA > and then reconstructing a data set from say the first 2/3 EOFs? > > I've had a look in the help pages and don't seem to find anything > relevant. >It's not in the R help, but in the books about PCA in help references. This can be done, not quite directly. Most of the hassle comes from the centring, and I guess in your case, from scaling of the results. I guess it is best to first scale the results like PCA would do, then make the low-rank approximation, and then de-scale: x <- scale(x, scale = TRUE) pc <- prcomp(x) Full rank will be: xfull <- pc$x %*% pc$rotation The eigenvalues already are incorporated in pc$x, and you don't have to care about them. Then rank=3 approximation will be: x3 <- pc$x[,1:3] %*% pc$rotation[,1:3] Then you have to "de-scale": x3 <- sweep(x3, 2, attr(x, "scaled:scale", "*") x3 <- sweep(x3, 2, attr(x, "scaled:center", "+") And here you are. I wouldn't call this a smoothing, though. Library 'vegan' can do this automatically for PCA run with function 'rda', but there the scaling of raw results is non-conventional (though "biplot"). cheers, jari oksanen -- Jari Oksanen <jarioksa at sun3.oulu.fi>
Hi Laura, You might want to have a look at function decevf in package pastecs. It uses eigenvector filtering to reconstruct a signal using only the most representative eigenvectors. It is applied for time series but you could easily modify the code to use it for spatial data also. Bests, Angel Laura Quinn wrote:> Hi, > > Is it possible to recreate "smoothed" data sets in R, by performing a PCA > and then reconstructing a data set from say the first 2/3 EOFs? > > I've had a look in the help pages and don't seem to find anything > relevant. > > Thanks in advance, > Laura > > Laura Quinn > Institute of Atmospheric Science > School of Earth and Environment > University of Leeds > Leeds > LS2 9JT > > tel: +44 113 343 1596 > fax: +44 113 343 6716 > mail: laura at env.leeds.ac.uk > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > . >