# Load the dataset
advertising <- read.csv("advertising.csv")
# View the dataset
head(advertising)
## 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
# Original sample size
nrow(advertising)
## [1] 200
# Randomly select 50% of the observations
set.seed(123)
advertising_half <- advertising[
sample(nrow(advertising), nrow(advertising) / 2),
]
# Check new sample size
nrow(advertising_half)
## [1] 100
# EDA 1: Summary statistics for Sales
summary(advertising_half$Sales)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 5.30 10.88 15.95 14.97 18.52 26.20
# Histogram of Sales
hist(advertising_half$Sales,
main = "Distribution of Sales",
xlab = "Sales",
ylab = "Frequency")

# EDA 2: TV Advertising vs. Sales
plot(advertising_half$TV,
advertising_half$Sales,
main = "TV Advertising vs. Sales",
xlab = "TV Advertising",
ylab = "Sales",
pch = 19)

# Correlation between TV advertising and Sales
cor(advertising_half$TV, advertising_half$Sales)
## [1] 0.9021462