# Membuat data contoh
# 1. MEMUAT PACKAGE DAN DATA
library(ggplot2)
library(lmtest)
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
library(car)
## Loading required package: carData
library(csv)
df <- read.csv("C:/Users/LENOVO/Downloads/economic_dataset.csv")
data <- df[c("Inflation_Rate","Economic_Growth")]
head(data)
## Inflation_Rate Economic_Growth
## 1 3.37 2.25
## 2 6.50 -1.61
## 3 5.42 -0.36
## 4 2.74 2.80
## 5 4.13 1.19
## 6 7.48 0.77
tail(data)
## Inflation_Rate Economic_Growth
## 145 5.83 2.17
## 146 4.68 0.89
## 147 5.68 -1.89
## 148 7.32 -1.04
## 149 4.64 2.91
## 150 5.21 -0.27
# Statistik deskriptif sederhana
summary(data)
## Inflation_Rate Economic_Growth
## Min. :0.800 Min. :-3.5800
## 1st Qu.:3.877 1st Qu.:-0.3000
## Median :5.060 Median : 0.8800
## Mean :5.086 Mean : 0.6533
## 3rd Qu.:6.310 3rd Qu.: 1.6625
## Max. :8.900 Max. : 4.1500
sd(df$Inflation_Rate)
## [1] 1.64148
sd(df$Economic_Growth)
## [1] 1.479998
hasil_korelasi <- cor.test(df$Inflation_Rate, df$Economic_Growth, method = "pearson")
# Menampilkan hasil
print(hasil_korelasi)
##
## Pearson's product-moment correlation
##
## data: df$Inflation_Rate and df$Economic_Growth
## t = -8.8887, df = 148, p-value = 1.96e-15
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.6854107 -0.4745589
## sample estimates:
## cor
## -0.5899524
berdasarkan uji korelasi person di peroleh p-value sebesar 1.96e-15 dimana < 0.05, sehingga H0 ditolak, maka terdapat hubungan yang signifikan antara Inflation_Rate dan Economic_Growth
plot(df$Inflation_Rate, df$Economic_Growth,
main = "Scatter Plot Inflation_Rate vs Economic_Growth",
xlab = "Inflation_Rate",
ylab = "Economic_Growth",
pch = 19,
col = "blue")
## Menambahkan garis regresi
abline(lm(df$Economic_Growth ~ df$Inflation_Rate), col = "red", lwd = 2)
# Hubungan Korelasi
ggplot(data, aes(x =Inflation_Rate, y = Economic_Growth)) +
geom_point(size = 3) +
geom_smooth(method = "lm", se = TRUE) +
labs(title = "Hubungan Marketing Spend dan Profit",
x = "Inflation_Rate",
y = "Economic_Growth") +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'
# Interpretasinya