Need help in R (Statistic Programe)

  • Thread starter Thread starter Philip Wong
  • Start date Start date
Click For Summary
SUMMARY

The discussion focuses on using R for plotting principal component (PC) scores with a group variable. The user employs the MASS library and utilizes the princomp function to compute PC scores from a dataset. Key commands include log transformation of data and the use of eqscplot for visualizing scores. The user seeks clarification on the correct approach to factorize the group variable and display the PC scores effectively.

PREREQUISITES
  • Familiarity with R programming language
  • Understanding of principal component analysis (PCA)
  • Experience with data manipulation in R using data frames
  • Knowledge of plotting functions in R, specifically eqscplot
NEXT STEPS
  • Learn how to effectively use the princomp function in R for PCA
  • Explore the MASS library for additional statistical functions
  • Research the use of factor variables in R for plotting
  • Study advanced plotting techniques in R, such as ggplot2 for enhanced visualizations
USEFUL FOR

Data analysts, statisticians, and researchers looking to visualize principal component scores in R, particularly those interested in incorporating group variables into their analyses.

Philip Wong
Messages
95
Reaction score
0
hello,
ok here is the situation, I wanted use R to plot a PC scores using a group variable (which is an external variable) as the plotting score. the command for printing the PC scores is prin$x. Below is some steps I've took so far:

> library(MASS) //loading the library called MASS
> island.df=read.csv(file.choose(),header=T) //feeding in the data file I want to do analyze on
> log.island.df=log((island.df[,4:10])+1) //log transform my data, because it was skewed
> x=island.df //rename my data into x, for easier used future
> prin=princomp(x[,4:10])
> scores=(x~as.factor(group)) //factorize the group variable as the plotting symbol, IS THIS HOW I DO IT? Is there other ways?
> prin$scores[,1:2] //I just want to print the first 2 components.IS this right? did I do something wrong? because I got no clue how the printout should looks like, so I don't know have I done it right or not!
 
Physics news on Phys.org
Or would it be better to use the following command if I want to use the group variable as the plotting symbol:
eqscplot(prin$scores[,1:2],type="n")
text(prin$scores[,1:2],label=as.vector(names))instead of just:
> prin$scores[,1:2] //I just want to print the first 2 components.
 
Last edited:

Similar threads

Replies
5
Views
2K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
1
Views
1K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 6 ·
Replies
6
Views
6K
  • · Replies 6 ·
Replies
6
Views
2K