lm1_freq <- lm(mpg ~ hp + cyl + disp, data = mtcars)
library(rstanarm)
lm1_bayes <- stan_glm(mpg ~ hp + cyl + disp, data = mtcars, refresh = 0)mtcars-simple1
regression
en
bayes
frequentist
qm1
stats-nutshell
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.
Compute the causal effect of horse power given the above model! Report the point estimate.
Notes:
- Use can either use frequentist or bayesian modeling.
- Use R for all computations.
- There are multiple ways to find a solution.
Solution
Compute Model:
Get parameters:
library(easystats)parameters(lm1_freq)| Parameter | Coefficient | SE | CI | CI_low | CI_high | t | df_error | p |
|---|---|---|---|---|---|---|---|---|
| (Intercept) | 34.1849192 | 2.5907776 | 0.95 | 28.8779519 | 39.4918865 | 13.194849 | 28 | 0.0000000 |
| hp | -0.0146793 | 0.0146509 | 0.95 | -0.0446903 | 0.0153316 | -1.001943 | 28 | 0.3249519 |
| cyl | -1.2274199 | 0.7972763 | 0.95 | -2.8605664 | 0.4057265 | -1.539516 | 28 | 0.1349044 |
| disp | -0.0188381 | 0.0104037 | 0.95 | -0.0401491 | 0.0024729 | -1.810711 | 28 | 0.0809290 |
parameters(lm1_bayes)| Parameter | Median | CI | CI_low | CI_high | pd | Rhat | ESS_tail | Prior_Distribution | Prior_Location | Prior_Scale |
|---|---|---|---|---|---|---|---|---|---|---|
| (Intercept) | 34.1840483 | 0.95 | 28.9536686 | 39.5287727 | 1.00000 | 1.0010351 | 2450 | normal | 20.09062 | 15.0673701 |
| hp | -0.0145818 | 0.95 | -0.0453224 | 0.0168647 | 0.84100 | 0.9997311 | 1830 | normal | 0.00000 | 0.2197599 |
| cyl | -1.2316992 | 0.95 | -2.8495240 | 0.3749313 | 0.93375 | 1.0003467 | 1665 | normal | 0.00000 | 8.4367476 |
| disp | -0.0188276 | 0.95 | -0.0395779 | 0.0021338 | 0.96000 | 1.0006829 | 2498 | normal | 0.00000 | 0.1215712 |
The coefficient is estimated as about -0.01
Aufgabenname: mtcars-simple1
Categories:
- regression
- en
- bayes
- frequentist
- qm1
- stats-nutshell