data <- read.csv("advertising.csv")

head(data)
##      TV Radio Newspaper Sales
## 1 230.1  37.8      69.2  22.1
## 2  44.5  39.3      45.1  10.4
## 3  17.2  45.9      69.3  12.0
## 4 151.5  41.3      58.5  16.5
## 5 180.8  10.8      58.4  17.9
## 6   8.7  48.9      75.0   7.2
summary(data)
##        TV             Radio          Newspaper          Sales      
##  Min.   :  0.70   Min.   : 0.000   Min.   :  0.30   Min.   : 1.60  
##  1st Qu.: 74.38   1st Qu.: 9.975   1st Qu.: 12.75   1st Qu.:11.00  
##  Median :149.75   Median :22.900   Median : 25.75   Median :16.00  
##  Mean   :147.04   Mean   :23.264   Mean   : 30.55   Mean   :15.13  
##  3rd Qu.:218.82   3rd Qu.:36.525   3rd Qu.: 45.10   3rd Qu.:19.05  
##  Max.   :296.40   Max.   :49.600   Max.   :114.00   Max.   :27.00

Deskripsi Data

Rata-rata Iklan TV adalah 147.0425

Rata-rata Iklan Radio adalah 23.264

Rata-rata Penjualan adalah 15.1305

Model Regresi

Bentuk umum persamaan regresi linier: \[ y = \beta_0 + \beta_1 TV + \beta_2 Radio + \beta_3 Newspaper + \epsilon \]

Estimasi Parameter

model <- lm(Sales ~ TV + Radio + Newspaper, data=data)
summary(model)
## 
## Call:
## lm(formula = Sales ~ TV + Radio + Newspaper, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -7.3034 -0.8244 -0.0008  0.8976  3.7473 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 4.6251241  0.3075012  15.041   <2e-16 ***
## TV          0.0544458  0.0013752  39.592   <2e-16 ***
## Radio       0.1070012  0.0084896  12.604   <2e-16 ***
## Newspaper   0.0003357  0.0057881   0.058    0.954    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.662 on 196 degrees of freedom
## Multiple R-squared:  0.9026, Adjusted R-squared:  0.9011 
## F-statistic: 605.4 on 3 and 196 DF,  p-value: < 2.2e-16

Model Akhir

Model regresi yang diperoleh adalah:

Sales = 4.6251 + 0.0544 TV + 0.107 Radio + 3^{-4} Newspaper

Pengujian Hipotesis

Uji Normalitas Residual

error = model$residuals
ks.test(error,"pnorm",mean(error),sqrt(var(error)))
## 
##  Asymptotic one-sample Kolmogorov-Smirnov test
## 
## data:  error
## D = 0.082313, p-value = 0.133
## alternative hypothesis: two-sided

Uji Autokorelasi

library(lmtest)
## Warning: package 'lmtest' was built under R version 4.4.1
## Warning: package 'zoo' was built under R version 4.4.1
dwtest(model)
## 
##  Durbin-Watson test
## 
## data:  model
## DW = 2.2506, p-value = 0.9625
## alternative hypothesis: true autocorrelation is greater than 0

Plot Model Regresi

Scatter plot dari TV vs Sales dan garis regresinya
Scatterplot TV vs Sales

Scatterplot TV vs Sales

Plot 2 Radio vs Sales

Scatter plot dari Radio vs sSales dan garis regresinya
Scatterplot Radio vs Sales

Scatterplot Radio vs Sales

Plot 3 Newspaper vs Sales

Scatter plot dari Newspaper vs Sales dan garis regresinya
Scatterplot Newspaper vs Sales

Scatterplot Newspaper vs Sales