Please could someone point me in the right direction as I appear to be having a total mental block with fairly basic PCA problem! I have a large dataframe where rows represent independent observations and columns are variables. I am wanting to perform PCA sequentially on blocks of nrows at a time and produce a graphical output of the loadings for the first 2 EOFs for each variable. I'm sure I've performed a very similar routine in the past, but the method is currently escaping me. Any help gratefully received! 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
Gavin Simpson
2005-May-16 09:14 UTC
[R] Mental Block with PCA of multivariate time series!
Laura Quinn wrote:> Please could someone point me in the right direction as I appear to be > having a total mental block with fairly basic PCA problem! > > I have a large dataframe where rows represent independent > observations and columns are variables. I am wanting to perform PCA > sequentially on blocks of nrows at a time and produce a graphical output > of the loadings for the first 2 EOFs for each variable. > > I'm sure I've performed a very similar routine in the past, but the method > is currently escaping me. > > Any help gratefully received!Hi Laura, data(iris) iris.dat <- iris[,1:4] pca.1 <- prcomp(iris.dat[1:50, ], scale = TRUE) pca.2 <- prcomp(iris.dat[51:100, ], scale = TRUE) pca.3 <- prcomp(iris.dat[100:150, ], scale = TRUE) biplot(pca.1) etc... There is a better way of subsetting this data set as the 5th col of iris is a factor and we could use the subset argument to prcomp to do the subsetting without having to know that there are 50 rows per species. Take a look at that argument if you have a variable that defines the blocks for you. Is this what you were after? All the best, Gav -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [T] +44 (0)20 7679 5522 ENSIS Research Fellow [F] +44 (0)20 7679 7565 ENSIS Ltd. & ECRC [E] gavin.simpsonATNOSPAMucl.ac.uk UCL Department of Geography [W] http://www.ucl.ac.uk/~ucfagls/cv/ 26 Bedford Way [W] http://www.ucl.ac.uk/~ucfagls/ London. WC1H 0AP. %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Hi all, You can use the sepan function in the library ade4. Maybe it's a bit difficult but it provides interesting perspectives. This function uses arguments 'ktab' (K-table) which correspond to a list of data frames with the same row.names in common. ?ktab # example : two propoistions data(meaudret) # table mil <- meaudret$mil # description of the block plandat <- as.factor(meaudret$plan$dat) #------------------------------- # first proposition: #------------------------------- # Ktab preparation list1 <- NULL for(i in 1:nlevels(plandat)){ list1[[i]] <- dudi.pca(meaudret$mil[plandat==levels(plandat)[i],],center=T,scale=T,scannf=F,nf=2) } ktab1 <- ktab.list.dudi(list1) # sequential analyses sepan1 <- sepan(ktab1) # graphical representations plot(sepan1) kplot(sepan1) #------------------------------------------------------------------------------------ # second proposition: more difficult but more interesting :) #------------------------------------------------------------------------------------ # within analysis ?within.pca wit1 <- within.pca(meaudret$mil, meaudret$plan$dat, scan = FALSE, scal = "partial") # Ktab preparation kta1 <- ktab.within(wit1, colnames = rep(c("S1","S2","S3","S4","S5"), 4)) kta2 <- t(kta1) # sequential analyses sepan2 <- sepan(kta2) # graphical representations plot(sepan2) kplot(sepan2) You can conclude your analysis with specific K-table analyses (e.g. STATIS, MFA, MCOA, GPA). ... it's very funny methods .... :) hopes this help Pierre At 08:32 16/05/2005 +0100, Laura Quinn wrote:>Please could someone point me in the right direction as I appear to be >having a total mental block with fairly basic PCA problem! > >I have a large dataframe where rows represent independent >observations and columns are variables. I am wanting to perform PCA >sequentially on blocks of nrows at a time and produce a graphical output >of the loadings for the first 2 EOFs for each variable. > >I'm sure I've performed a very similar routine in the past, but the method >is currently escaping me. > >Any help gratefully received! > >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@env.leeds.ac.uk > >______________________________________________ >R-help@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.htmlPierre BADY <°)))))>< Université Claude Bernard Lyon 1 UMR CNRS 5023, LEHF bat Alphonse Forel 43 boulevard du 11 novembre 1918 F-69622 VILLEURBANNE CEDEX FRANCE TEL : +33 (0)4 72 44 62 34 FAX : +33 (0)4 72 43 28 92 MEL : pierre.bady@univ-lyon1.fr http://pierre.bady.free.fr (in construction) [[alternative HTML version deleted]]
Jean Thioulouse
2005-May-16 13:12 UTC
[R] Mental Block with PCA of multivariate time series!
Laura Quinn <laura at env.leeds.ac.uk> wrote:>I am wishing to investigate the temporal evolution of the pca: if we >assume that every 50 rows of my data frame is representitive of, for >instance, 1 day of data, I am hoping to automate a process whereby a pca >is performed on every 50 rows of data and the loading for PC1 and PC2 for >each variable (i.e. each column) is represented as a point on a plot - so >a years' data will be represented as two lines (representing PC1 and PC2) >on a time series plot for each variable.Hi Laura, You might try to take a look at the "between", "within" and "pta" functions of the ade4 package : http://pbil.univ-lyon1.fr/ade4html/between.html http://pbil.univ-lyon1.fr/ade4html/within.html http://pbil.univ-lyon1.fr/ade4html/pta.html They can be used to analyse a data set with this kind of structure. Choosing how to analyse it depends on what you are looking for. Jean -- Jean Thioulouse - Labo de Biometrie et Biologie Evolutive, UMR CNRS 5558 Universite Lyon 1, 43 Boulevard du 11 Novembre 1918, Batiment G. Mendel 69622 Villeurbanne Cedex, France. Tel/Fax : (33) 4 72 43 27 56 http://pbil.univ-lyon1.fr/JTHome.html