Skip to main content

mario-compare-models

lm
regression
interaction
computer
Published

June 14, 2024

Variieren Sie das folgende Modell mit einer bzw. beiden UV bzw. mit Interaktionseffekt. Welches Modell ist am besten?

lm_mario_2uv <- lm(total_pr ~ start_pr + ship_pr, data = mariokart %>% filter(total_pr < 100))

Hinweise:

  • Nutzen Sie den Datensatz mariokart.
  • Bonus: Visualisieren Sie das Streudiagramm!

Den Datensatz können Sie hier beziehen:

mariokart <- read.csv("https://vincentarelbundock.github.io/Rdatasets/csv/openintro/mariokart.csv")

library(easystats)
## # Attaching packages: easystats 0.7.6.3 (red = needs update)
## ✖ bayestestR  0.19.0   ✔ correlation 0.8.8 
## ✖ datawizard  1.4.0    ✔ effectsize  1.0.3 
## ✖ insight     1.5.4    ✖ modelbased  0.17.0
## ✖ performance 0.18.2   ✖ parameters  0.29.3
## ✔ report      0.6.4    ✖ see         0.14.2
## 
## Restart the R-Session and update packages with `easystats::easystats_update()`.
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.2.1     ✔ readr     2.2.0
## ✔ forcats   1.0.1     ✔ stringr   1.6.0
## ✔ ggplot2   4.0.3     ✔ tibble    3.3.1
## ✔ lubridate 1.9.5     ✔ tidyr     1.3.2
## ✔ purrr     1.2.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter()        masks stats::filter()
## ✖ dplyr::lag()           masks stats::lag()
## ✖ dplyr::recode_values() masks datawizard::recode_values()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors

Modelle berechnen:

library(easystats)

# Modell a
lm_mario_2uv <- lm(total_pr ~ start_pr + ship_pr, data = mariokart %>% filter(total_pr < 100))

# Modell b
lm_mario_start_pr <- lm(total_pr ~ start_pr, data = mariokart %>% filter(total_pr < 100))

# Modell c
lm_mario_ship_pr <- lm(total_pr ~  ship_pr, data = mariokart %>% filter(total_pr < 100))

# Modell d
lm_mario_2uv_interaktion <- lm(total_pr ~ start_pr + ship_pr + start_pr:ship_pr, data = mariokart %>% filter(total_pr < 100))

Modellgüten ausgeben lassen:

r2(lm_mario_2uv)
## # R2 for Linear Regression
##        R2: 0.107
##   adj. R2: 0.094
r2(lm_mario_start_pr)
## # R2 for Linear Regression
##        R2: 0.107
##   adj. R2: 0.101
r2(lm_mario_ship_pr)
## # R2 for Linear Regression
##        R2: 0.000
##   adj. R2: -0.007
r2(lm_mario_2uv_interaktion)
## # R2 for Linear Regression
##        R2: 0.108
##   adj. R2: 0.088

1 BONUS

Visualisieren Sie das Streudiagramm!

library(DataExplorer)

mariokart |> 
  select(total_pr, ship_pr) |> 
  filter(total_pr < 100) |> 
  plot_scatterplot( "total_pr")

plot of chunk unnamed-chunk-8
library(ggpubr)
## 
## Attache Paket: 'ggpubr'
## Die folgenden Objekte sind maskiert von 'package:datawizard':
## 
##     mean_sd, median_mad
ggscatter(mariokart |> filter(total_pr < 100),
          x = "ship_pr",
          y = "total_pr",
          add = "reg.line")

plot of chunk unnamed-chunk-8

Aufgabenname: mario-compare-models