This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.

Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.

plot(cars)

Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Ctrl+Alt+I.

When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Ctrl+Shift+K to preview the HTML file).

The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.

library(readr)
Titanic_Dataset <- read_csv('Titanic-Dataset.csv')
## Rows: 891 Columns: 12
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (5): Name, Sex, Ticket, Cabin, Embarked
## dbl (7): PassengerId, Survived, Pclass, Age, SibSp, Parch, Fare
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Titanic_Dataset
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
df <- Titanic_Dataset %>% select(Age, SibSp, Parch, Fare)
df_clean <- na.omit(df)

77 kosong data berhasil dihapus

corr <- cor(df_clean)
corr
##               Age      SibSp      Parch       Fare
## Age    1.00000000 -0.3082468 -0.1891193 0.09606669
## SibSp -0.30824676  1.0000000  0.3838199 0.13832879
## Parch -0.18911926  0.3838199  1.0000000 0.20511888
## Fare   0.09606669  0.1383288  0.2051189 1.00000000
install.packages("corrplot", repos = "https://cran.rstudio.com/")
## Installing package into 'C:/Users/mocha/OneDrive/Documents/Dokumen/Rpubs Introduce/renv/library/windows/R-4.5/x86_64-w64-mingw32'
## (as 'lib' is unspecified)
## package 'corrplot' successfully unpacked and MD5 sums checked
## 
## The downloaded binary packages are in
##  C:\Users\mocha\AppData\Local\Temp\Rtmpg5Wjhe\downloaded_packages
library(corrplot)
## corrplot 0.95 loaded
corrplot(corr, method = "color", addCoef.col = "black")

Adanya hubungan antara variabel SibSP (penumpang yang bawa saudara ) dan var Parch ( penumpah yang membawa orang tua) artinya penumpang yang bawa saudara juga membawa orang tua/anak

Nilai negatif antara Age dan SibSp (-0.30) kelompok usia muda cenderung membawa pasangan ketimbang usia yang lebih tua

covarian <- cov(df_clean)
covarian
##              Age      SibSp      Parch        Fare
## Age   211.019125 -4.1633339 -2.3441911   73.849030
## SibSp  -4.163334  0.8644973  0.3045128    6.806212
## Parch  -2.344191  0.3045128  0.7281027    9.262176
## Fare   73.849030  6.8062117  9.2621760 2800.413100
eig <- eigen(corr)
eig$values
## [1] 1.6367503 1.1071770 0.6694052 0.5866676
eig$vectors
##            [,1]       [,2]        [,3]        [,4]
## [1,]  0.4388714 -0.5962415  0.56095237  0.37043268
## [2,] -0.6250770  0.0732461  0.05500006  0.77517016
## [3,] -0.5908590 -0.1774532  0.60558695 -0.50265342
## [4,] -0.2599159 -0.7795136 -0.56175785 -0.09607493