x<-c(1, 1, 0, 0, 0,
1, 1, 0, 0, 0,
1, 1, 0, 0, 0,
1, 0, 1, 0, 0,
1, 0, 1, 0, 0,
1, 0, 1, 0, 0,
1, 0, 0, 1, 0,
1, 0, 0, 1, 0,
1, 0, 0, 1, 0,
1, 0, 0, 0, 1,
1, 0, 0, 0, 1,
1, 0, 0, 0, 1)
X<-matrix(x, nrow=12, ncol=5,T)
X
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 1 0 0 0
## [2,] 1 1 0 0 0
## [3,] 1 1 0 0 0
## [4,] 1 0 1 0 0
## [5,] 1 0 1 0 0
## [6,] 1 0 1 0 0
## [7,] 1 0 0 1 0
## [8,] 1 0 0 1 0
## [9,] 1 0 0 1 0
## [10,] 1 0 0 0 1
## [11,] 1 0 0 0 1
## [12,] 1 0 0 0 1
Xtrans <- t(X)
Xtrans
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
## [1,] 1 1 1 1 1 1 1 1 1 1 1 1
## [2,] 1 1 1 0 0 0 0 0 0 0 0 0
## [3,] 0 0 0 1 1 1 0 0 0 0 0 0
## [4,] 0 0 0 0 0 0 1 1 1 0 0 0
## [5,] 0 0 0 0 0 0 0 0 0 1 1 1
XtransX <- Xtrans%*%X
XtransX
## [,1] [,2] [,3] [,4] [,5]
## [1,] 12 3 3 3 3
## [2,] 3 3 0 0 0
## [3,] 3 0 3 0 0
## [4,] 3 0 0 3 0
## [5,] 3 0 0 0 3
y <- c(5,4,5,8,7,7,3,2,3,7,6,7)
y <- matrix(y, nrow=12, ncol=1,T)
y
## [,1]
## [1,] 5
## [2,] 4
## [3,] 5
## [4,] 8
## [5,] 7
## [6,] 7
## [7,] 3
## [8,] 2
## [9,] 3
## [10,] 7
## [11,] 6
## [12,] 7
Xtransy <- Xtrans%*%y
Xtransy
## [,1]
## [1,] 64
## [2,] 14
## [3,] 22
## [4,] 8
## [5,] 20
#NOMOR 2
M <- c(3, 0, 0, 0,
0, 3, 0, 0,
0, 0, 3, 0,
0, 0, 0, 3)
M <- matrix(M, nrow = 4, ncol = 4, T)
M
## [,1] [,2] [,3] [,4]
## [1,] 3 0 0 0
## [2,] 0 3 0 0
## [3,] 0 0 3 0
## [4,] 0 0 0 3
M_1 <- solve(M)
M_1
## [,1] [,2] [,3] [,4]
## [1,] 0.3333333 0.0000000 0.0000000 0.0000000
## [2,] 0.0000000 0.3333333 0.0000000 0.0000000
## [3,] 0.0000000 0.0000000 0.3333333 0.0000000
## [4,] 0.0000000 0.0000000 0.0000000 0.3333333
M_trans <- t(M_1)
M_trans
## [,1] [,2] [,3] [,4]
## [1,] 0.3333333 0.0000000 0.0000000 0.0000000
## [2,] 0.0000000 0.3333333 0.0000000 0.0000000
## [3,] 0.0000000 0.0000000 0.3333333 0.0000000
## [4,] 0.0000000 0.0000000 0.0000000 0.3333333
XtransX_new <- c(0, 0, 0, 0, 0,
0, 1/3, 0, 0, 0,
0, 0, 1/3, 0, 0,
0, 0, 0, 1/3, 0,
0, 0, 0, 0, 1/3)
XtransX_new <- matrix(XtransX_new, nrow = 5, ncol = 5, T)
XtransX_new
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0 0.0000000 0.0000000 0.0000000 0.0000000
## [2,] 0 0.3333333 0.0000000 0.0000000 0.0000000
## [3,] 0 0.0000000 0.3333333 0.0000000 0.0000000
## [4,] 0 0.0000000 0.0000000 0.3333333 0.0000000
## [5,] 0 0.0000000 0.0000000 0.0000000 0.3333333
XtransX_c <- t(XtransX_new)
XtransX_c
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0 0.0000000 0.0000000 0.0000000 0.0000000
## [2,] 0 0.3333333 0.0000000 0.0000000 0.0000000
## [3,] 0 0.0000000 0.3333333 0.0000000 0.0000000
## [4,] 0 0.0000000 0.0000000 0.3333333 0.0000000
## [5,] 0 0.0000000 0.0000000 0.0000000 0.3333333
b = XtransX_c%*%Xtransy
b
## [,1]
## [1,] 0.000000
## [2,] 4.666667
## [3,] 7.333333
## [4,] 2.666667
## [5,] 6.666667
XtransX_cXtransX <- XtransX_c%*%XtransX
XtransX_cXtransX
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0 0 0 0 0
## [2,] 1 1 0 0 0
## [3,] 1 0 1 0 0
## [4,] 1 0 0 1 0
## [5,] 1 0 0 0 1
#a.
t1 <- matrix(c(1,0,0,0,0), nrow = 1, ncol = 5, T)
t1
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 0 0 0 0
alpha <- t1%*%XtransX_cXtransX
alpha
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0 0 0 0 0
#b.
t2 <- matrix(c(0,1,0,0,0), nrow = 1, ncol = 5, T)
t2
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0 1 0 0 0
toi1 <- t2%*%XtransX_cXtransX
toi1
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 1 0 0 0
#c.
t3 <- matrix(c(0,0,1,0,0), nrow = 1, ncol = 5, T)
t3
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0 0 1 0 0
toi2 <- t3%*%XtransX_cXtransX
toi2
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 0 1 0 0
#d.
t4 <- matrix(c(0,0,0,1,0), nrow = 1, ncol = 5, T)
t4
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0 0 0 1 0
toi3 <- t4%*%XtransX_cXtransX
toi3
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 0 0 1 0
#e.
t5 <- matrix(c(0,0,0,0,1), nrow = 1, ncol = 5, T)
t5
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0 0 0 0 1
toi4 <- t5%*%XtransX_cXtransX
toi4
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 0 0 0 1
Jadi, dapat disimpulkan bahwa β tidak dapat diduga (estimable) karena unsur-unsur dari β yaitu μ, τ_1, τ_2,τ_3,τ_4 tidak dapat diduga (estimable).
#NOMOR 4
#baris pertama matriks X
t1 <- matrix(c(1,1,0,0,0), nrow = 1, ncol = 5, T)
t1
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 1 0 0 0
alphatoi1 <- t1%*%XtransX_cXtransX
alphatoi1
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 1 0 0 0
#baris kedua matriks X
t2 <- matrix(c(1,0,1,0,0), nrow = 1, ncol = 5, T)
t2
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 0 1 0 0
alphatoi2 <- t2%*%XtransX_cXtransX
alphatoi2
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 0 1 0 0
#baris ketiga matriks X
t3 <- matrix(c(1,0,0,1,0), nrow = 1, ncol = 5, T)
t3
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 0 0 1 0
alphatoi3 <- t3%*%XtransX_cXtransX
alphatoi3
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 0 0 1 0
#baris keempat matriks X
t4 <- matrix(c(1,0,0,0,1), nrow = 1, ncol = 5, T)
t4
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 0 0 0 1
alphatoi4 <- t4%*%XtransX_cXtransX
alphatoi4
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 0 0 0 1
#NOMOR 5
XXtransX_cXtrans <- X%*%XtransX_c%*%Xtrans
XXtransX_cXtrans
## [,1] [,2] [,3] [,4] [,5] [,6] [,7]
## [1,] 0.3333333 0.3333333 0.3333333 0.0000000 0.0000000 0.0000000 0.0000000
## [2,] 0.3333333 0.3333333 0.3333333 0.0000000 0.0000000 0.0000000 0.0000000
## [3,] 0.3333333 0.3333333 0.3333333 0.0000000 0.0000000 0.0000000 0.0000000
## [4,] 0.0000000 0.0000000 0.0000000 0.3333333 0.3333333 0.3333333 0.0000000
## [5,] 0.0000000 0.0000000 0.0000000 0.3333333 0.3333333 0.3333333 0.0000000
## [6,] 0.0000000 0.0000000 0.0000000 0.3333333 0.3333333 0.3333333 0.0000000
## [7,] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.3333333
## [8,] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.3333333
## [9,] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.3333333
## [10,] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
## [11,] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
## [12,] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
## [,8] [,9] [,10] [,11] [,12]
## [1,] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
## [2,] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
## [3,] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
## [4,] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
## [5,] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
## [6,] 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
## [7,] 0.3333333 0.3333333 0.0000000 0.0000000 0.0000000
## [8,] 0.3333333 0.3333333 0.0000000 0.0000000 0.0000000
## [9,] 0.3333333 0.3333333 0.0000000 0.0000000 0.0000000
## [10,] 0.0000000 0.0000000 0.3333333 0.3333333 0.3333333
## [11,] 0.0000000 0.0000000 0.3333333 0.3333333 0.3333333
## [12,] 0.0000000 0.0000000 0.3333333 0.3333333 0.3333333
I <- matrix(c(1,0,0,0,0,0,0,0,0,0,0,0,
0,1,0,0,0,0,0,0,0,0,0,0,
0,0,1,0,0,0,0,0,0,0,0,0,
0,0,0,1,0,0,0,0,0,0,0,0,
0,0,0,0,1,0,0,0,0,0,0,0,
0,0,0,0,0,1,0,0,0,0,0,0,
0,0,0,0,0,0,1,0,0,0,0,0,
0,0,0,0,0,0,0,1,0,0,0,0,
0,0,0,0,0,0,0,0,1,0,0,0,
0,0,0,0,0,0,0,0,0,1,0,0,
0,0,0,0,0,0,0,0,0,0,1,0,
0,0,0,0,0,0,0,0,0,0,0,1), nrow = 12, ncol = 12, T)
ytrans <- t(y)
p <-(I-XXtransX_cXtrans)
SSres <- ytrans%*%p%*%y
SSres
## [,1]
## [1,] 2.666667
n <- 12
r <- 4
w <- n-r
s_2 <- SSres/w
s_2
## [,1]
## [1,] 0.3333333
#NOMOR 6
b = XtransX_c%*%Xtransy
t <- matrix(c(1,1,0,0,0), ncol = 1, nrow = 5, T)
ttrans <- t(t)
ttabel <- 2.306
XtransX_c
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0 0.0000000 0.0000000 0.0000000 0.0000000
## [2,] 0 0.3333333 0.0000000 0.0000000 0.0000000
## [3,] 0 0.0000000 0.3333333 0.0000000 0.0000000
## [4,] 0 0.0000000 0.0000000 0.3333333 0.0000000
## [5,] 0 0.0000000 0.0000000 0.0000000 0.3333333
akar <- sqrt(ttrans%*%XtransX_c%*%t)
akar
## [,1]
## [1,] 0.5773503
SKbawah <- ttrans%*%b + ttabel%*%akar
SKbawah
## [,1]
## [1,] 5.998036
SKatas <- ttrans%*%b - ttabel%*%akar
SKatas
## [,1]
## [1,] 3.335297
#NOMOR 7
C <- matrix(c(0,1,-1,0,0,
0,0,1,-1,0,
0,0,0,1,-1), nrow = 3, ncol = 5, T)
C
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0 1 -1 0 0
## [2,] 0 0 1 -1 0
## [3,] 0 0 0 1 -1
Ctrans <- t(C)
b = XtransX_c%*%Xtransy
b
## [,1]
## [1,] 0.000000
## [2,] 4.666667
## [3,] 7.333333
## [4,] 2.666667
## [5,] 6.666667
#Menghitung Cb
Cb <- C%*%b
Cb
## [,1]
## [1,] -2.666667
## [2,] 4.666667
## [3,] -4.000000
#Menghitung (Cb)'(C(X' X)^c C')^(-1) Cb
Cbtrans <- t(Cb)
CXtransX_cCtrans <- C%*%XtransX_c%*%Ctrans
CXtransX_cCtrans
## [,1] [,2] [,3]
## [1,] 0.6666667 -0.3333333 0.0000000
## [2,] -0.3333333 0.6666667 -0.3333333
## [3,] 0.0000000 -0.3333333 0.6666667
invers_CXtransX_cCtrans <- solve(CXtransX_cCtrans)
invers_CXtransX_cCtrans
## [,1] [,2] [,3]
## [1,] 2.25 1.5 0.75
## [2,] 1.50 3.0 1.50
## [3,] 0.75 1.5 2.25
hasil <- Cbtrans%*%invers_CXtransX_cCtrans%*%Cb
hasil
## [,1]
## [1,] 40
u <- hasil/3
Fhit <- u/s_2
Fhit
## [,1]
## [1,] 40
#NOMOR 8
y <- c(5,4,5,8,7,7,3,2,3,7,6,7)
y <- matrix(y, nrow=12, ncol=1,T)
y
## [,1]
## [1,] 5
## [2,] 4
## [3,] 5
## [4,] 8
## [5,] 7
## [6,] 7
## [7,] 3
## [8,] 2
## [9,] 3
## [10,] 7
## [11,] 6
## [12,] 7
Z <- matrix(c(1,0,0,0,
1,0,0,0,
1,0,0,0,
0,1,0,0,
0,1,0,0,
0,1,0,0,
0,0,1,0,
0,0,1,0,
0,0,1,0,
0,0,0,1,
0,0,0,1,
0,0,0,1), nrow = 12, ncol = 4, T)
Ztrans <- t(Z)
ZtransZ <- Ztrans%*%Z
ZtransZ
## [,1] [,2] [,3] [,4]
## [1,] 3 0 0 0
## [2,] 0 3 0 0
## [3,] 0 0 3 0
## [4,] 0 0 0 3
invers_ZtransZ <- solve(ZtransZ)
invers_ZtransZ
## [,1] [,2] [,3] [,4]
## [1,] 0.3333333 0.0000000 0.0000000 0.0000000
## [2,] 0.0000000 0.3333333 0.0000000 0.0000000
## [3,] 0.0000000 0.0000000 0.3333333 0.0000000
## [4,] 0.0000000 0.0000000 0.0000000 0.3333333
Ztransy <- Ztrans%*%y
Ztransy
## [,1]
## [1,] 14
## [2,] 22
## [3,] 8
## [4,] 20
a <- invers_ZtransZ%*%Ztransy
a
## [,1]
## [1,] 4.666667
## [2,] 7.333333
## [3,] 2.666667
## [4,] 6.666667
ytrans <- t(y)
ytransZ <- ytrans%*%Z
ytransZ
## [,1] [,2] [,3] [,4]
## [1,] 14 22 8 20
JKregresipenuh <- ytransZ%*%invers_ZtransZ%*%Ztransy
JKregresipenuh
## [,1]
## [1,] 381.3333
jumlah_y <- (5+4+5+8+7+7+3+2+3+7+6+7)^2
JKregresitereduksi <- jumlah_y/12
JKregresitereduksi
## [1] 341.3333
JKregresihipotesis <- JKregresipenuh-JKregresitereduksi
JKregresihipotesis
## [,1]
## [1,] 40
JKtotal <- ytrans%*%y
JKtotal
## [,1]
## [1,] 384
JKresidual <- JKtotal-JKregresipenuh
JKresidual
## [,1]
## [1,] 2.666667