New names:
Rows: 200 Columns: 6
── Column specification
──────────────────────────────────────────────────────── Delimiter: "," dbl
(6): ...1, X1, TV, radio, newspaper, sales
ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
Specify the column types or set `show_col_types = FALSE` to quiet this message.
• `` -> `...1`
plot(sales ~ TV, data = ad_sales)
Now let’s fit a linear model with TV advertising as a predictor.
fit <-lm(sales ~ TV, data = ad_sales)summary(fit)
Call:
lm(formula = sales ~ TV, data = ad_sales)
Residuals:
Min 1Q Median 3Q Max
-8.3860 -1.9545 -0.1913 2.0671 7.2124
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 7.032594 0.457843 15.36 <2e-16 ***
TV 0.047537 0.002691 17.67 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 3.259 on 198 degrees of freedom
Multiple R-squared: 0.6119, Adjusted R-squared: 0.6099
F-statistic: 312.1 on 1 and 198 DF, p-value: < 2.2e-16
Question 2:Is there a relationship between TV advertising and Sales? If so, what does the relationship look like? Explain the coefficient and R square.
Your answer here
Question 3:Can you plot the relationship between radio advertising and Sales? If so, please save it as fit1. What does the relationship look like? Explain the coefficients and R square.
Your answer here
Question 4:Can you plot the relationship between radio advertising (X1), TV advertising (X2), and Sales (Y)? If so, please save it as fit2. What does the relationship look like? Explain the coefficients and R square.
Your answer here
Question 4: Two things you learned from this session