library(rstanarm)
library(easystats)
library(tidyverse)
mtcars-simple3
regression
en
bayes
frequentist
qm1
stats-nutshell
qm2
Exercise
We will use the dataset mtcars
in this exercise.
Assume your causal model of your research dictates that fuel economy is a linear function of horse power, cylinder count and displacement of the engine.
Which of the predictors in the above model has the weakest causal impact on the output variable?
Notes:
- Use can either use frequentist or bayesian modeling.
- Use R for all computations.
- There are multiple ways to find a solution.
Answerlist
cyl
hp
disp
- All are equally strong
- none of the above
Solution
In order to gauge the relative importance of the predictors, we need to make sure they are on the same scale:
<-
mtcars2 standardise(mtcars)
Compute Model:
<- lm(mpg ~ hp + cyl + disp, data = mtcars2)
lm1_freq <- stan_glm(mpg ~ hp + cyl + disp, data = mtcars2, refresh = 0) lm1_bayes
Get parameters:
parameters(lm1_bayes)
Parameter | Median | 95% CI | pd | Rhat | ESS | Prior
----------------------------------------------------------------------------------------------
(Intercept) | -2.49e-03 | [-0.19, 0.18] | 50.92% | 1.000 | 3348.00 | Normal (7.11e-17 +- 2.50)
hp | -0.17 | [-0.50, 0.18] | 83.17% | 1.000 | 2399.00 | Normal (0.00 +- 2.50)
cyl | -0.37 | [-0.84, 0.11] | 93.83% | 1.000 | 2134.00 | Normal (0.00 +- 2.50)
disp | -0.39 | [-0.82, 0.04] | 96.50% | 1.000 | 2301.00 | Normal (0.00 +- 2.50)
Note that the absolute value of the coefficient’s estimate is what we are after.
The predictors with the strongest impact is disp
, and cyl
. The weakest influence has hp
.
Answerlist
- wrong
- correct
- wrong
- wrong
- wrong
Categories:
- regression
- en
- bayes
- frequentist
- qm1
- stats-nutshell