Data
df <- read.csv("C:/Users/User/OneDrive/Dokumen/SEMESTER 6/Analisis Regresi/Data Projek/CrabAgePrediction.csv")
data <- df[c("Shell.Weight", "Age")]
head(data)
## Shell.Weight Age
## 1 6.747181 9
## 2 1.559222 6
## 3 2.764076 6
## 4 5.244657 10
## 5 1.700970 6
## 6 7.229122 8
## Shell.Weight Age
## 3888 9.0718400 11
## 3889 6.3786375 8
## 3890 9.7805775 10
## 3891 0.6378637 5
## 3892 2.9766975 6
## 3893 1.4174750 8
Statistik Deskriptif
cat("\n==== STATISTIK DESKRIPTIF ====\n")
##
## ==== STATISTIK DESKRIPTIF ====
## Shell.Weight Age
## Min. : 0.04252 Min. : 1.000
## 1st Qu.: 3.71378 1st Qu.: 8.000
## Median : 6.66213 Median :10.000
## Mean : 6.79584 Mean : 9.955
## 3rd Qu.: 9.35534 3rd Qu.:11.000
## Max. :28.49125 Max. :29.000
Standar Deviasi
cat("\nStandar Deviasi Shell.Weight\n")
##
## Standar Deviasi Shell.Weight
sd(data$Shell.Weight, na.rm = TRUE)
## [1] 3.943392
cat("\nStandar Deviasi Age\n")
##
## Standar Deviasi Age
sd(data$Age, na.rm = TRUE)
## [1] 3.220967
Uji Korelasi
hasil_korelasi <- cor.test(data$Shell.Weight, data$Age, method = "pearson")
print(hasil_korelasi)
##
## Pearson's product-moment correlation
##
## data: data$Shell.Weight and data$Age
## t = 49.968, df = 3891, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.6056761 0.6439620
## sample estimates:
## cor
## 0.625195
# Ambil p-value dan koefisien korelasi
p_value <- hasil_korelasi$p.value
r_value <- hasil_korelasi$estimate
cat("\nKoefisien Korelasi (r) =", round(r_value, 4), "\n")
##
## Koefisien Korelasi (r) = 0.6252
cat("p-value =", round(p_value, 5), "\n")
## p-value = 0
# Keputusan uji (α = 0.05)
alpha <- 0.05
if (p_value < alpha) {
cat("Keputusan: Tolak H0\n")
cat("Kesimpulan: Terdapat korelasi yang signifikan antara Shell.Weight dan Age\n")
} else {
cat("Keputusan: Gagal menolak H0\n")
cat("Kesimpulan: Tidak terdapat korelasi yang signifikan antara Shell.Weight dan Age\n")
}
## Keputusan: Tolak H0
## Kesimpulan: Terdapat korelasi yang signifikan antara Shell.Weight dan Age
Scatterplot
# Membuat scatter plot
plot(data$Shell.Weight, data$Age,
main = "Scatter Plot Shell Weight vs Age",
xlab = "Shell Weight",
ylab = "Age",
pch = 19, col = "blue")
# Menambahkan garis regresi
abline(lm(data$Shell.Weight ~ data$Age), col = "red", lwd = 2)
