Zum Hauptinhalt springen

389  mtcars-simple1

Schlüsselwörter

Aufgaben, Statistik, Prognose, Modellierung, R, Datenanalyse, Regression

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.

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 |         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.13 | [28.62, 39.31] |   100% | 1.001 | 2393 | Normal (20.09 +- 15.07)
## hp          |  -0.01 | [-0.05,  0.02] | 83.50% | 1.000 | 2177 |   Normal (0.00 +- 0.22)
## cyl         |  -1.21 | [-2.79,  0.50] | 92.75% | 1.000 | 1901 |   Normal (0.00 +- 8.44)
## disp        |  -0.02 | [-0.04,  0.00] | 96.53% | 0.999 | 2296 |   Normal (0.00 +- 0.12)

The coefficient is estimated as about -0.01

Aufgabenname: mtcars-simple1