On Mon, 1 Mar 2004, Christoph Lehmann wrote:
> I used princomp on a dataset x[!sub,]. How can I get the scores for
> another dataset, say x[sub,]? I didn't succeed using predict()
What did you try? Whatever it was, predict() is the correct idea:
> data(USArrests)
> pc.cr <- princomp(USArrests, cor = TRUE)
> predict(pc.cr, USArrests[1:10,])
Comp.1 Comp.2 Comp.3 Comp.4
Alabama 0.98556588 1.13339238 -0.44426879 0.156267145
Alaska 1.95013775 1.07321326 2.04000333 -0.438583440
Arizona 1.76316354 -0.74595678 0.05478082 -0.834652924
Arkansas -0.14142029 1.11979678 0.11457369 -0.182810896
California 2.52398013 -1.54293399 0.59855680 -0.341996478
Colorado 1.51456286 -0.98755509 1.09500699 0.001464887
Connecticut -1.35864746 -1.08892789 -0.64325757 -0.118469414
Delaware 0.04770931 -0.32535892 -0.71863294 -0.881977637
Florida 3.01304227 0.03922851 -0.57682949 -0.096284752
Georgia 1.63928304 1.27894240 -0.34246008 1.076796812
based on the example on the help page.
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595