Professional Documents
Culture Documents
Tugas Analisis Data_Factor Analysis
Tugas Analisis Data_Factor Analysis
Variable
Supermarket Data
3 amspent (mountly ammount spent)
4 meat (meat expenditure)
5 fish (fish expenditure)
6 vegetable (vegetable expenditure)
7 own brand (% spent in own brand product)
9 organic (% spent in organic food)
16 income (yearly household income)
17 age (age of respondent)
Factor Analysis using R
• library(foreign)
• supermarket=read.spss("d:\\supermarket.sav", to.data.frame=TRUE)
• supermarket
• supermarket=supermarket[,c(3,4,5,6,7,9,16,17)]
• supermarket
• kmo <- function(x)
• {
• x <- subset(x, complete.cases(x))
• r <- cor(x)
• r2 <- r^2
• i <- solve(r)
• d <- diag(i)
• p2 <- (-i/sqrt(outer(d, d)))^2
• diag(r2) <- diag(p2) <- 0
• KMO <- sum(r2)/(sum(r2)+sum(p2))
• MSA <- colSums(r2)/(colSums(r2)+colSums(p2))
• return(list(KMO=KMO, MSA=MSA))
• }
uji_bart <- function(x)
{
method <- "Bartlett's test of sphericity"
data.name <- deparse(substitute(x))
x <- subset(x, complete.cases(x))
n <- nrow(x)
p <- ncol(x)
chisq <- (1-n+(2*p+5)/6)*log(det(cor(x)))
df <- p*(p-1)/2
p.value <- pchisq(chisq, df, lower.tail=FALSE)
names(chisq) <- "Khi-squared"
names(df) <- "df"
return(structure(list(statistic=chisq, parameter=df, p.value=p.value,
method=method, data.name=data.name),
class="htest"))
}
cor(supermarket)
uji_bart(supermarket)
kmo(supermarket)
aku <- function(data,cor = TRUE){
##Menentukan matriks korelasi atau kovarian berdasarkan masukan
# user
if (cor == TRUE){
mat = cor(data)}
else mat = cov(data)
##Membentuk scree-plot
#par(new = TRUE)
plot(pc$values,type="l",xlab="Components",ylab="Variances")
plot(pc$values,type="o",xlab="Components",ylab="Variances")
##Mengeluarkan output
cat("\neigenvalues\tproportion\tcumulative")
for(i in 1:p){
cat("\n",pc$values[i],"\t",var[i],"\t",cumvar[i],"\n")
}
cat("\n")
return(list(eigenvectors = pc$vectors))
}
Chi-Square 690.94614
Bartlett
Sphericity Test Derajat bebas 28
P-value 0,000
Berdasarkan tabel diatas , uji barlett’s digunakan untuk menguji ada tidaknya interpendensi
antar variabel
Sedangkan KMO menguji apakah variabel layak dianalsis dengan analsis faktor.
H0 : (variabel tidak layak dianalsis dengan analisis faktor)
H1 : (variabel layak dianalsis dengan analisis faktor)
Principal Component Analysis
Cumulative Proportion
eigenvalues proportion cumulative
3.784452 0.4730566 0.4730566
1.101634 0.1377043 0.6107609
0.9496053 0.1187007 0.7294615
0.7788023 0.09735029 0.8268118
0.585972 0.0732465 0.9000583
0.5201532 0.06501915 0.9650775
0.2411582 0.03014477 0.9952222
0.03822207 0.004777759 1
Proporsi kumulatif yang harus dicapai sebesar lebih dari 70% atau dapat pula dilihat
dari nilai eigen yang lebih dari 1. dari tiga komponen dapat menjelaskan keberagaman
sebesar 72,95%.
The cumulative proportion which has to be attained is greater than 70% or the eigen value is
greater than 1. The first three component could summarize the variation 72,95%.
Principal Component Analysis
Scree Plot
Principal Component Analysis
Principal Component Models
PC1 Y1 0, 45 x1 0, 25 x 2 0,3 x3 0,13 x 4 0,35 x5 0, 27 x6 0, 46 x7 0, 46 x8
Variansi yang dapat dijelaskan dengan menggunakan tiga komponen adalah 72,9%
Factor Analysis
Loading Factor Matrik faktor loading setelah
rotasi
Matrik faktor loading sebelum rotasi
Komp.1 Komp.2 Komp.3 Komp.1 Komp.2 Komp.3
X1 -0.8854315 -0.15163 -0.023775134 X1 -0.733 -0.402 0.33
X2 -0.4907554 -0.40785 0.631886237 X2 -0.206 -0.109 0.867
X3 -0.5884393 0.242994 -0.542548439
X3 -0.684 -0.299 -0.377
X4 -0.256088 -0.68988 -0.493197424
X5 -0.6898408 0.233119 0.041956847 X4 -0.886 0 0
X6 -0.531372 -0.44552 -0.000813588 X5 -0.716 0.14 0
X7 -0.8954701 0.235153 0.078762964 X6 -0.287 -0.506 -0.378
X8 -0.8875122 0.263033 0.064751061 X7 -0.898 0.233 0
X8 -0.904 0.206 0
X1 : amspent (mountly ammount spent)
Comp 1 Comp 2 Comp 3
X2 : meat (meat expenditure) X1, X3, X4,
X3 : fish (fish expenditure) X5, X7, X8 X6 X2
X4 : vegetable (vegetable expenditure)
X5 : own brand (% spent in own brand product) Matriks Loading digunakan untuk
X6 : organic (% spent in organic food) menentuakan suatu faktor Masuk
X7 : income (yearly household income) kedalam komponen 1, 2 atau 3
X8 : age (age of respondent) berdasarkan loading factor.