1 Data Sample #
use tempdb
go
if object_id('dbo.pc') is not null
drop table dbo.pc;
create table dbo.pc(
varchar(20)
, 蟲 int
, int
, int
);
insert dbo.pc values('A', 1, 2, 3);
insert dbo.pc values('B', 2, 1, 2);
insert dbo.pc values('C', 3, 3, 1);
insert dbo.pc values('D', 4, 5, 5);
insert dbo.pc values('E', 5, 4, 4);
<- c(85,30,40,75,55,55,70,30)
<- c(60,40,30,60,45, 65,40,20)
d <- data.frame(,)
head(d)
p <- princomp(d) #prcomp:螻覯″一伎, princomp:轟願 覿伎伎
summary(p)
biplot(p)
plot(p)
> p
Call:
princomp(x = d)
Standard deviations:
Comp.1 Comp.2
22.746992 8.736382
2 variables and 8 observations.
> summary(p)
Importance of components:
Comp.1 Comp.2
Standard deviation 22.7469916 8.7363823
Proportion of Variance 0.8714537 0.1285463
Cumulative Proportion 0.8714537 1.0000000
> p$loadings [1:2, 1:2]
Comp.1 Comp.2
-0.8228691 0.5682310
-0.5682310 -0.8228691
> p$scores
Comp.1 Comp.2
[1,] -33.209538 4.7038937
[2,] 23.412882 -10.0914296
[3,] 20.866501 3.8195713
[4,] -24.980847 -0.9784163
[5,] 0.000000 0.0000000
[6,] -11.364620 -16.4573817
[7,] -9.501881 12.6378104
[8,] 34.777502 6.3659521
> #豕譬
> p$scores[,1] * -1
[1] 33.209538 -23.412882 -20.866501 24.980847 0.000000 11.364620
[7] 9.501881 -34.777502
- 譯殊焔覿 Score 覿瑚 覦. 蠏碁 -1 螻燕伎が.
- 豌覯讌 譯殊焔 襯 螻壱覃 (-0.822869 * (85-55) + -0.5682310 * (60-45)) * -1 .
螻襯 覦螳覃..
<- c(85,30,40,75,55,55,70,30)
<- c(60,40,30,60,45, 65,40,20)
d <- data.frame(,)
cov.mat <- cov.wt(d, cor=TRUE)$cov
e.vec <- eigen(cor.mat)$vectors
comp1 <- e.vec[1,1]*( - mean()) + e.vec[2,1]*( - mean())
comp2 <- e.vec[1,2]*( - mean()) + e.vec[2,2]*( - mean())