In the lecture12, we used the advertising
dataset and retained the following linear model:
\[\widehat{Sales} = \hat{\beta_0} + \hat{\beta_1} TV + \hat{\beta_2} Radio + \hat{\beta_3} (TV:Radio)\]
adv_lm
.Now, using formula in the red box above, we would like to explicitely formulate this linear model using the estimated coefficients. For example, let’s consider the following hypothetical linear model \(y = a \times x + b\) with the estimates \(a = 2\) and \(b = 1\). We would write it as \(y = 2 \times x + 1\).
glue::glue()
to generate the equation in R
# Lets create some example objects
a <- 2
b <- 1
# The following line will not modify our character sequence:
glue::glue("y = a * x + b")
## y = a * x + b
# character sequences surrounded by curly braces are detected
# as R objects and replaced by their values
glue::glue("y = {a} * x + {b}")
## y = 2 * x + 1
Using the factorised equation quickly determine whether it is better:
Calculate the ratio of the sales when investing in both media to TV alone.
predict()
. And supply as argument a data.frame/tibble where colnames are predictor names and values the desired investment to test
Do you think that the efficiency of investing 2000$ will be similar in both models?
Calculate the ratio of the sales when investing in both media to TV alone.
We are going to manipulate data where the relationship between the variables is simulated. This example comes from Gareth et al. 2013.
Use the following code to generate the data:
set.seed(1)
simul1 <- tibble(x1 = runif(100),
x2 = 0.5 * x1 + rnorm(100) / 10,
y = 2 + 2 * x1 + 0.3 * x2 + (rnorm(100)))
+ write the equation (as text in your markdown document)
+ write the regression coefficients (as text in your markdown document)
ggpairs
ggpairs
comes from the package GGally
Name this effect.
Do you accept \(H_0: \hat{\beta_1} = 0\) and \(H_0: \hat{\beta_2} = 0\)?
Do you accept \(H_0: \hat{\beta_1} = 0\)?
What happened?
Do you accept \(H_0: \hat{\beta_1} = 0\)?
What happened?
x1 = 0.1, x2 = 0.8, y = 6
.Add it to the existing simul1
and store the result as simul2
.
add_row()
defined in the package tibble
simul2
.simul2