mtcars-simple1

regression
en
bayes
frequentist
qm1
stats-nutshell
mtcars
Published

September 4, 2022

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:

lm1_freq <- lm(mpg ~ hp + cyl + disp, data = mtcars)

library(rstanarm)
lm1_bayes <- stan_glm(mpg ~ hp + cyl + disp, data = mtcars, refresh = 0)

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 Prior_Distribution Prior_Location Prior_Scale
(Intercept) 34.3384905 0.95 28.7492605 39.5220309 1.00000 0.9995556 2550.268 normal 20.09062 15.0673701
hp -0.0144322 0.95 -0.0440017 0.0159889 0.83275 1.0001907 2378.497 normal 0.00000 0.2197599
cyl -1.2866915 0.95 -2.8870372 0.3857465 0.94225 0.9994626 1984.656 normal 0.00000 8.4367476
disp -0.0181281 0.95 -0.0399442 0.0027910 0.95050 0.9995334 2101.649 normal 0.00000 0.1215712

The coefficient is estimated as about -0.01


Categories:

  • regression
  • en
  • bayes
  • frequentist
  • qm1
  • stats-nutshell