Name : Farhan Dzaffa Arfianto

NIM : 220605110099

Class : C

Institue : Maulana Malik Ibrahim Islamic State University of Malang

Lecture : Prof. Dr. Suhartono, M.Kom

library(ggplot2)
set.seed(123) # Mengatur seed agar hasil acak dapat direproduksi
n <- 100 # Jumlah sampel
x <- runif(n, min = 0, max = 10) # Variabel prediktor dengan distribusi uniform
epsilon <- rnorm(n, mean = 0, sd = 1) # Noise dengan distribusi Gaussian
y <- 2*x + 3 + epsilon # Variabel respons
data <- data.frame(x, y)
ggplot(data, aes(x, y)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE, color = "red") +
  labs(x = "Variabel X", y = "Variabel Y", title = "Model Regresi Linear")
## `geom_smooth()` using formula = 'y ~ x'

model <- lm(y ~ x, data = data)
summary(model)
## 
## Call:
## lm(formula = y ~ x, data = data)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.23797 -0.61323 -0.01973  0.59633  2.21723 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  2.99104    0.19605   15.26   <2e-16 ***
## x            1.99102    0.03418   58.25   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.9693 on 98 degrees of freedom
## Multiple R-squared:  0.9719, Adjusted R-squared:  0.9716 
## F-statistic:  3393 on 1 and 98 DF,  p-value: < 2.2e-16