=====================================================

Nama Mahasiswa : โ€™Izzan Nuha Zamroni

NIM : 220605110082

Kelas : C

Mata Kuliah : Linear Algebra

Dosen Pengampuh : Prof.Dr.Suhartono,M.Kom

Jurusan : Teknik Informatika

Universitas : UIN Maulana Malik Ibrahim Malang

=====================================================

library(pracma)
B <- matrix(c(1, 0, 0, 1, 1, 0, 1, 1, 1), 3, 3, byrow = TRUE)
v <- c(2, 4, 0)
inv(B) %*% v
##      [,1]
## [1,]    2
## [2,]    2
## [3,]   -4
library(mvtnorm)
set.seed(123)
sigma <- matrix(c(4,2,2,3), ncol=2)
x <- rmvnorm(n=500, mean=c(0,0), sigma=sigma)
pca<- princomp(x)
 pca
## Call:
## princomp(x = x)
## 
## Standard deviations:
##   Comp.1   Comp.2 
## 2.241521 1.231119 
## 
##  2  variables and  500 observations.
 pca$loadings
## 
## Loadings:
##      Comp.1 Comp.2
## [1,]  0.781  0.625
## [2,]  0.625 -0.781
## 
##                Comp.1 Comp.2
## SS loadings       1.0    1.0
## Proportion Var    0.5    0.5
## Cumulative Var    0.5    1.0
## Library for the Credit data set
library(ISLR)
## Loading the data
data(Credit)
credit.data <- Default[,3:4]
m1 <- mean(credit.data[,1])
m2 <- mean(credit.data[,2])
credit.data2 <- credit.data - c(m1, m2)
credit.data3 <- scale(credit.data2)
pca<- princomp(data.frame(scale(credit.data3)))
pca$loadings
## 
## Loadings:
##         Comp.1 Comp.2
## balance  0.707  0.707
## income   0.707 -0.707
## 
##                Comp.1 Comp.2
## SS loadings       1.0    1.0
## Proportion Var    0.5    0.5
## Cumulative Var    0.5    1.0
T <- pca$loadings
D <- inv(T) %*% t(scale(credit.data3))
credit.data4 <- t(D)
s <- c(-1.96, 1.96)
Non_Outlier_v1 <- mean(credit.data4[,1]) + s * sd(credit.data4[,1])
Non_Outlier_v2 <- mean(credit.data4[,2]) + s * sd(credit.data4[,2])
 Non_Outlier_v1
## [1] -2.608577  2.608577
Non_Outlier_v2
## [1] -0.9372965  0.9372965