



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




STAT 530/J530 B.Habing Univ. of S.C. (^1)
Instructor: Brian Habing Department of Statistics LeConte 203 Telephone: 803-777- E-mail: [email protected]
STAT 530/J530 B.Habing Univ. of S.C. (^2)
PROC IML; sigma = {1 .2 2, .2 1 2, 2 2 10}; mu = {0 0 0}; n = 1000; seed = 91505; q=NROW(sigma); MUMAT=REPEAT(mu,n,1); SROOT=ROOT(sigma); Z=NORMAL(REPEAT(seed,n,q)); x=ZSROOT+MUMAT; CREATE mvnormdata FROM x; APPEND FROM x; QUIT;*
STAT 530/J530 B.Habing Univ. of S.C. (^3)
Find the coefficients (a’s) of the x’s so that:
Y=a 1 X 1 +a 2 X 2 +···+a (^) q Xq
has the largest possible variance subject to the condition that the length of the coefficient vector is 1.
STAT 530/J530 B.Habing Univ. of S.C. (^4)
library(MASS) mu<-c(5,0,-1) sigma<- matrix(c(1,0.2,2,0.2,1,2,2,2,10), ncol=3,byrow=T) x<-mvrnorm(n=1000,mu,sigma)
coef<-princomp(x,cor=F)$loadings[,1]
pc1<-princomp(x,cor=F)$scores[,1]
STAT 530/J530 B.Habing Univ. of S.C. (^5)
We should be able to check that the values are correct using the formula before… so we get:
pc1[1]
x[1,1]coef[1] +x[1,2]coef[2] +x[1,3]coef[3]*
Are they all off?!?
STAT 530/J530 B.Habing Univ. of S.C. (^6)
The dot product of two vectors a and b is a 1 b 1 +a 2 b 2 +···+a (^) qb (^) q
In vector notation this is:
It relates to distance by:
It relates to orthogonality by:
STAT 530/J530 B.Habing Univ. of S.C. (^10)
eigen(cov(x))$vectors princomp(x,cor=F)$loadings
eigen(cov(x))$values round(var(princomp(x,cor=F)$scores),2)
STAT 530/J530 B.Habing Univ. of S.C. (^11)
plot(princomp(x,cor=F))
STAT 530/J530 B.Habing Univ. of S.C. (^12)
Y=a 1 X 1 +a 2 X 2 +···+a (^) q Xq or Y(nxq) =X (^) (nxq) A (^) (qxq)
STAT 530/J530 B.Habing Univ. of S.C. (^13)
If we have Y we should be able to get X... say using regression.
In fact in this case we should get it exactly! Y(nxq) A -1 (qxq) =X (^) (nxq) A (^) (qxq) A-1 (qxq)
X (^) (nxq) =Y(nxq) A-1 (qxq)
STAT 530/J530 B.Habing Univ. of S.C. (^14)
sect3<-as.matrix(oildata[,12:31])
a<-eigen(cov(sect3))$vectors y<-sect3%%a*
summary(lm(sect3[,1]~y))$r.squared
STAT 530/J530 B.Habing Univ. of S.C. (^15)
y4<-y[,1:4] summary(lm(sect3[,1]~y4))$r.squared
sect3est<-sect for (i in 1:20){ sect3est[,i]<- lm(sect3[,i]~y4)$fitted.values}