Gaussian linear atau model linear Gaussian adalah sebuah model statistik yang mengasumsikan bahwa hubungan antara sebuah variabel dependen dengan satu atau lebih variabel independen adalah linear dan bahwa kesalahan (error) yang terjadi dalam model dijelaskan oleh distribusi normal (gaussian). Model ini sering juga disebut sebagai model regresi linear Gaussian
library(matlib)
A <- matrix(c(0, 8, 4, 4, 5, 7, 3, 8,7, 7, 0, 4, 7, 7, 5, 12), 4, 4)
B<- c(-9, -7, -3, 0)
A
## [,1] [,2] [,3] [,4]
## [1,] 0 5 7 7
## [2,] 8 7 7 7
## [3,] 4 3 0 5
## [4,] 4 8 4 12
B
## [1] -9 -7 -3 0
showEqn() digunakan untuk menampilkan persamaan matematika dari matriks dan vektor yang diberikan sebagai argumen. Persamaan ditampilkan dalam format yang mudah dibaca dan dipahami. Fungsi ini dapat berguna dalam analisis matematika dan statistik ketika ingin memeriksa persamaan yang mendasari suatu model.
showEqn(A, B)
## 0*x1 + 5*x2 + 7*x3 + 7*x4 = -9
## 8*x1 + 7*x2 + 7*x3 + 7*x4 = -7
## 4*x1 + 3*x2 + 0*x3 + 5*x4 = -3
## 4*x1 + 8*x2 + 4*x3 + 12*x4 = 0
echelon() digunakan untuk mengubah matriks menjadi bentuk reduksi baris, yaitu bentuk matriks di mana setiap baris non-nol dimulai dengan elemen nol atau 1, dan elemen nol berada di bawah elemen bukan nol di atasnya. Bentuk echelon ini sangat berguna dalam menyelesaikan sistem persamaan linear, menghitung inverse matriks, dan menentukan determinan matriks.
echelon(A, B, verbose=TRUE, fractions=TRUE)
##
## Initial matrix:
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0 5 7 7 -9
## [2,] 8 7 7 7 -7
## [3,] 4 3 0 5 -3
## [4,] 4 8 4 12 0
##
## row: 1
##
## exchange rows 1 and 2
## [,1] [,2] [,3] [,4] [,5]
## [1,] 8 7 7 7 -7
## [2,] 0 5 7 7 -9
## [3,] 4 3 0 5 -3
## [4,] 4 8 4 12 0
##
## multiply row 1 by 1/8
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 7/8 7/8 7/8 -7/8
## [2,] 0 5 7 7 -9
## [3,] 4 3 0 5 -3
## [4,] 4 8 4 12 0
##
## multiply row 1 by 4 and subtract from row 3
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 7/8 7/8 7/8 -7/8
## [2,] 0 5 7 7 -9
## [3,] 0 -1/2 -7/2 3/2 1/2
## [4,] 4 8 4 12 0
##
## multiply row 1 by 4 and subtract from row 4
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 7/8 7/8 7/8 -7/8
## [2,] 0 5 7 7 -9
## [3,] 0 -1/2 -7/2 3/2 1/2
## [4,] 0 9/2 1/2 17/2 7/2
##
## row: 2
##
## multiply row 2 by 1/5
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 7/8 7/8 7/8 -7/8
## [2,] 0 1 7/5 7/5 -9/5
## [3,] 0 -1/2 -7/2 3/2 1/2
## [4,] 0 9/2 1/2 17/2 7/2
##
## multiply row 2 by 7/8 and subtract from row 1
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 0 -7/20 -7/20 7/10
## [2,] 0 1 7/5 7/5 -9/5
## [3,] 0 -1/2 -7/2 3/2 1/2
## [4,] 0 9/2 1/2 17/2 7/2
##
## multiply row 2 by 1/2 and add to row 3
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 0 -7/20 -7/20 7/10
## [2,] 0 1 7/5 7/5 -9/5
## [3,] 0 0 -14/5 11/5 -2/5
## [4,] 0 9/2 1/2 17/2 7/2
##
## multiply row 2 by 9/2 and subtract from row 4
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 0 -7/20 -7/20 7/10
## [2,] 0 1 7/5 7/5 -9/5
## [3,] 0 0 -14/5 11/5 -2/5
## [4,] 0 0 -29/5 11/5 58/5
##
## row: 3
##
## exchange rows 3 and 4
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 0 -7/20 -7/20 7/10
## [2,] 0 1 7/5 7/5 -9/5
## [3,] 0 0 -29/5 11/5 58/5
## [4,] 0 0 -14/5 11/5 -2/5
##
## multiply row 3 by -5/29
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 0 -7/20 -7/20 7/10
## [2,] 0 1 7/5 7/5 -9/5
## [3,] 0 0 1 -11/29 -2
## [4,] 0 0 -14/5 11/5 -2/5
##
## multiply row 3 by 7/20 and add to row 1
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 0 0 -14/29 0
## [2,] 0 1 7/5 7/5 -9/5
## [3,] 0 0 1 -11/29 -2
## [4,] 0 0 -14/5 11/5 -2/5
##
## multiply row 3 by 7/5 and subtract from row 2
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 0 0 -14/29 0
## [2,] 0 1 0 56/29 1
## [3,] 0 0 1 -11/29 -2
## [4,] 0 0 -14/5 11/5 -2/5
##
## multiply row 3 by 14/5 and add to row 4
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 0 0 -14/29 0
## [2,] 0 1 0 56/29 1
## [3,] 0 0 1 -11/29 -2
## [4,] 0 0 0 33/29 -6
##
## row: 4
##
## multiply row 4 by 29/33
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 0 0 -14/29 0
## [2,] 0 1 0 56/29 1
## [3,] 0 0 1 -11/29 -2
## [4,] 0 0 0 1 -58/11
##
## multiply row 4 by 14/29 and add to row 1
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 0 0 0 -28/11
## [2,] 0 1 0 56/29 1
## [3,] 0 0 1 -11/29 -2
## [4,] 0 0 0 1 -58/11
##
## multiply row 4 by 56/29 and subtract from row 2
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 0 0 0 -28/11
## [2,] 0 1 0 0 123/11
## [3,] 0 0 1 -11/29 -2
## [4,] 0 0 0 1 -58/11
##
## multiply row 4 by 11/29 and add to row 3
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 0 0 0 -28/11
## [2,] 0 1 0 0 123/11
## [3,] 0 0 1 0 -4
## [4,] 0 0 0 1 -58/11
Solve(A, B)
## x1 = -2.54545455
## x2 = 11.18181818
## x3 = -4
## x4 = -5.27272727
A <-matrix(c(1,1,1,0,1,2,1,1,0,1,1,3,0,1,2,1),nrow=4,ncol=4)
A
## [,1] [,2] [,3] [,4]
## [1,] 1 1 0 0
## [2,] 1 2 1 1
## [3,] 1 1 1 2
## [4,] 0 1 3 1