library(rstanarm)
library(easystats)
library(tidyverse)mtcars-simple3
regression
en
bayes
frequentist
qm1
stats-nutshell
qm2
mtcars
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
cylhpdisp- 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:
lm1_freq <- lm(mpg ~ hp + cyl + disp, data = mtcars2)
lm1_bayes <- stan_glm(mpg ~ hp + cyl + disp, data = mtcars2, refresh = 0)Get parameters:
parameters(lm1_bayes)| Parameter | Median | CI | CI_low | CI_high | pd | Rhat | ESS_tail | Prior_Distribution | Prior_Location | Prior_Scale |
|---|---|---|---|---|---|---|---|---|---|---|
| (Intercept) | 0.0032447 | 0.95 | -0.1763947 | 0.1817065 | 0.51475 | 1.000001 | 2227 | normal | 0 | 2.5 |
| hp | -0.1724119 | 0.95 | -0.5093495 | 0.1732813 | 0.84250 | 1.001527 | 2157 | normal | 0 | 2.5 |
| cyl | -0.3496643 | 0.95 | -0.8058727 | 0.1336430 | 0.92575 | 1.000285 | 2065 | normal | 0 | 2.5 |
| disp | -0.3998787 | 0.95 | -0.8494027 | 0.0372232 | 0.96225 | 0.999581 | 2011 | normal | 0 | 2.5 |
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