<- lm(mpg ~ hp + cyl + disp, data = mtcars)
lm1_freq
library(rstanarm)
<- stan_glm(mpg ~ hp + cyl + disp, data = mtcars, refresh = 0) lm1_bayes
mtcars-simple1
regression
en
bayes
frequentist
qm1
stats-nutshell
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 | 95% CI | t(28) | p
------------------------------------------------------------------
(Intercept) | 34.18 | 2.59 | [28.88, 39.49] | 13.19 | < .001
hp | -0.01 | 0.01 | [-0.04, 0.02] | -1.00 | 0.325
cyl | -1.23 | 0.80 | [-2.86, 0.41] | -1.54 | 0.135
disp | -0.02 | 0.01 | [-0.04, 0.00] | -1.81 | 0.081
parameters(lm1_bayes)
Parameter | Median | 95% CI | pd | Rhat | ESS | Prior
------------------------------------------------------------------------------------------
(Intercept) | 34.12 | [28.88, 39.57] | 100% | 1.000 | 2289.00 | Normal (20.09 +- 15.07)
hp | -0.01 | [-0.05, 0.02] | 83.30% | 1.000 | 2691.00 | Normal (0.00 +- 0.22)
cyl | -1.21 | [-2.85, 0.37] | 93.35% | 1.001 | 1836.00 | Normal (0.00 +- 8.44)
disp | -0.02 | [-0.04, 0.00] | 95.67% | 1.000 | 2045.00 | Normal (0.00 +- 0.12)
The coefficient is estimated as about -0.01
Categories:
- regression
- en
- bayes
- frequentist
- qm1
- stats-nutshell