mtcars-simple2

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 explained variance (point estimate) for the above model!

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 R2:

library(easystats)
r2(lm1_freq)
# R2 for Linear Regression
       R2: 0.768
  adj. R2: 0.743
r2(lm1_bayes)
# Bayesian R2 with Compatibility Interval

  Conditional R2: 0.748 (95% CI [0.605, 0.854])

The coefficient is estimated as about 0.77.


Categories:

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