Docsity

3D Example, Matrix Background, Eigenvalues and Eigenvectors | STAT 530, Study notes of Statistics

Toggle sidebar
bg1
1
STAT 530/J530 B.Habing Univ. of S.C. 1
STAT 530/J530
September 18th, 2008
Instructor: Brian Habing
Department of Statistics
LeConte 203
Telephone: 803-777-3578
STAT 530/J530 B.Habing Univ. of S.C. 2
3-D Example
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=Z*SROOT+MUMAT;
CREATE mvnormdata FROM x;
APPEND FROM x;
QUIT;
STAT 530/J530 B.Habing Univ. of S.C. 3
Goal
Find the coefficients (a’s) of the x’s so
that:
Y=a1X1+a2X2+···+aqXq
has the largest possible variance subject
to the condition that the length of the
coefficient vector is 1.
pf3
pf4
pf5

Partial preview of the text

Download 3D Example, Matrix Background, Eigenvalues and Eigenvectors | STAT 530 and more Study notes Statistics in PDF only on Docsity!

STAT 530/J530 B.Habing Univ. of S.C. (^1)

STAT 530/J

September 18 th^ , 2008

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)

3-D Example

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)

Goal

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)

Example Cont.

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)

Example Cont.

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)

Some Matrix Background

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)

Example Cont.

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)

Scree Plot

plot(princomp(x,cor=F))

STAT 530/J530 B.Habing Univ. of S.C. (^12)

In Matrix Notation

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)

Reversing It

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)

Checking What Was Lost

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)

What if we only kept 4 PC’s?

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}