In R code, generate 200 observations on three random variables X1, X2, X3 define
ID: 3172213 • Letter: I
Question
In R code, generate 200 observations on three random variables X1, X2, X3 defined as follows:
X1 Z1,
X2 = X1 + 0.001 · Z2,
X3 = 10 · Z3,
where Z1, Z2, Z3 are independent standard normal random variables. Set the seed to be 1.
R-Code is:
set.seed(1)
z1<-rnorm(200)
z2<-rnorm(200)
z3<-rnorm(200)
x1<-z1
x2<-x1+0.001*z2
x3<-10*z3
QUESTION:
(1) Write R code - Run a principle component analysis on the vectors X1, X2, X3. In this exercise, center the features but DO NOT scale the features. Display the standard deviations and the loadings
(2) Write R code - Run a principle component analysis on the vectors X1, X2, X3. In this exercise, center AND scale the features. Display the standard deviations and the loadings.
Explanation / Answer
1) z1<-rnorm(200)
z2<-rnorm(200)
z3<-rnorm(200)
x1<-z1
x2<-x1+0.001*z2
x3<-10*z3
pc1<-princomp(formula=~x1+x2+x3,centered=T,scaled=F,cor=T)
summary(pc1)
pc1$loadings
Output :
2) R codes and output
pc2<-princomp(formula=~x1+x2+x3,centered=T,scaled=T,cor=T)
summary(pc2)
pc2$loadings
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.