lm1_freq <- lm(mpg ~ hp + cyl + disp, data = mtcars)
library(rstanarm)
lm1_bayes <- stan_glm(mpg ~ hp + cyl + disp, data = mtcars, refresh = 0)mtcars-simple2
regression
    en
    bayes
    frequentist
    qm1
    stats-nutshell
    mtcars
  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:
Get R2:
library(easystats)r2(lm1_freq)# R2 for Linear Regression
       R2: 0.768
  adj. R2: 0.743r2(lm1_bayes)# Bayesian R2 with Compatibility Interval
  Conditional R2: 0.746 (95% CI [0.610, 0.856])The coefficient is estimated as about 0.77.
Categories:
- regression
- en
- bayes
- frequentist
- qm1
- stats-nutshell