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.
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.747 (95% CI [0.591, 0.853])
The coefficient is estimated as about 0.77.
Aufgabenname: mtcars-simple2