Questions tagged [prcomp]

The R Stats Package function prcomp is used to perform a principal components analysis on the given data matrix. It returns the results as an object of class ```prcomp```.

The calculation is done by a singular value decomposition of the (centered and possibly scaled) data matrix, not by using eigen on the covariance matrix. This is generally the preferred method for numerical accuracy. The print method for these objects prints the results in a nice format and the plot method produces a scree plot.

Vignette: link

source code: link

44 questions
1
vote
0 answers

prcomp( .. ,retx=TRUE), do I get the new data to train over?

I am having some issues in interpreting the results from prcomp(). Say I have a centered and scaled data.table called dat, with N columns and M rows. Indeed every column represents a feature and every row a record. I also got a M-dimensional vector…
marco
  • 569
  • 1
  • 4
  • 19
1
vote
0 answers

How to calculate an index or a score from principal components in R?

How do I go about calculating an index/score from principal component analysis? Here is a reproducible example set.seed(1) dat <- data.frame( Diet = sample(1:2), Outcome1 = sample(1:10), Outcome2 = sample(11:20), Outcome3 = sample(21:30), …
DiscoR
  • 247
  • 2
  • 11
1
vote
1 answer

How to get first 8 components from PCA using pcromp package?

I am implementing a PCA using prcomp. pcaunemp <- prcomp(rawtChange,center = TRUE, scale=FALSE) I am using the lm function for regression like so: reg <- lm(tr[5:365,1] ~ tr[1:361,1] + tr[2:362,1] + tr[3:363,1] + tr[4:364,1]) If I want to only use…
Thelonious Monk
  • 426
  • 5
  • 19
1
vote
2 answers

Plotting a subset of data from a prcomp matrix without re-running prcomp

I am asking a question to a similar post posted up 2 years ago, with no full answer to it (subset of prcomp object in R). P.S. sorry for commenting on it for an answer.. Basically, my question is the same. I have generated a PCA table using prcomp…
MeganS92
  • 13
  • 3
1
vote
0 answers

PCA scores vs. Varimax-rotated PCA scores

I have performed PCA using prcomp in R with my databases of 75-76 indicator variables and 7232 companies, including NAs. Before applying the function, I centred my data, but did not rescale them because they are all indicator variables. (Is my…
Maite CD
  • 21
  • 5
0
votes
1 answer

What is the line in a 3D pca and its meaning?

Recently, I focused on 3D PCA. And I know how to produce 3D PCA plots through different packages in R, such as plotly, rgl and so on. But I have a small question from the picture below: I don't know how to add vertical lines in R just as the picture…
花落思量错
  • 352
  • 1
  • 11
0
votes
0 answers

How to specify overall plot size for fviz_pca_biplot of factoextra

I have created a PCA biplot using the code below. I need to specify the plot as a certain size (9 cm x 9cm), but have not figured out how to do so. I tried defining variables for the width and height and adding them using theme(plot.width..., but no…
0
votes
0 answers

How to color pca plot with csv file?

I have a csv file with TpM values in this format: Gene sample1 FUN_016238-T1 6.8690496 FUN_003161-T1 1.3314202 And on with many genes and 28 samples. I have been able to do prcomp on this data following normalization pca_master_norm <-…
mmgit
  • 1
  • 1
0
votes
0 answers

Why is PCA analysis in R using order as a variable?

I am doing PCA analysis in R. I am not by any means a programmer so please have some patience me if I'm too vague or use incorrect terminology :) So, for context, I am doing PCA of a giant dataset of US counties, with a ton of demographic…
0
votes
1 answer

principal component analysis (PCA) on panel data in R using prcomp

I'm working with a large cross-country panel dataset. I would like to apply Principal Component Analysis for each country in my sample. As I understand it, the prcomp function does not work on panel data frames directly. I could create a subset for…
user3227641
  • 157
  • 7
0
votes
1 answer

PCA clustering and analysis of clusters in R

I am trying to perform a PCA on a dataset which contains a survey results. The survey was conducted on companies (companies are in rows) and they were asked multiple questions (questions and answers are in columns). Most of the questions were based…
0
votes
1 answer

Best option for missing value imputation for prcomp()

I have a data set of genotypes for approximately 200 individual genomes (columns) for nearly 1,000,000 loci (rows). Due to poor sequencing data, most rows contain 1-2 missing genotypes. If I use df_new = na.omit(df) my new data frame contains only…
Max
  • 487
  • 5
  • 19
0
votes
2 answers

unable to change labels in PCA prcomp from row numbers to site names

I have followed the answers in https://stackoverflow.com/questions/38900698/how-to-change-labels-from-pca-using-prcomp-to-sample-names but am unable to get it to work. I have set up a dummy file (called tf4) with 7 columns and 12 rows and imported…
Rachel
  • 1
  • 2
0
votes
0 answers

pca ggplot with hierarchical clustering on shiny

Il try to create a shiny app that print a pca ggplot with hierarchical clustering and the following error appears: Warning: Error in : You're passing a function as global data. Have you misspelled the data argument in ggplot(). what could be the…
0
votes
0 answers

Plotting PCA data on different components

Not sure if this is due to my limited knowledge of R or just plain impossible but here is my problem. I have a dataset made of a bunch of chemical signatures for a number of samples. In order to find possible correlations, I ran a PCA and now I'd…
Raffaello Nardin
  • 151
  • 2
  • 11