Zum Hauptinhalt springen

352  lm-mario2

Schlüsselwörter

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

Sagen Sie den Verkaufspreis vorher für ein Spiel mit 3 Euro Versandkosten (ship_pr)!

352.0.1 Setup

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

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()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(easystats)
## # Attaching packages: easystats 0.7.5 (red = needs update)
## ✖ bayestestR  0.17.0   ✔ correlation 0.8.8 
## ✖ datawizard  1.3.1    ✖ effectsize  1.0.2 
## ✖ insight     1.5.1    ✖ modelbased  0.15.0
## ✖ performance 0.16.0   ✖ parameters  0.29.0
## ✔ report      0.6.4    ✖ see         0.13.0
## 
## Restart the R-Session and update packages with `easystats::easystats_update()`.

352.0.2 Regressionsgerade berechnen

lm_mariokart <- lm(total_pr ~ ship_pr, data = mariokart) # "lm" wie *l*lineares *M*odell, also eine Gerade.
lm_mariokart
## 
## Call:
## lm(formula = total_pr ~ ship_pr, data = mariokart)
## 
## Coefficients:
## (Intercept)      ship_pr  
##      36.246        4.337

352.0.3 Vorhersagen

Vorhersagen funktionieren mit dem Befehl predict:

neues_spiel <- tibble(ship_pr = 3)  # oder "data.frame" statt "tibble"
neues_spiel
## # A tibble: 1 × 1
##   ship_pr
##     <dbl>
## 1       3
predict(lm_mariokart, neues_spiel)  # predicte mir den Verkaufspreis
##       1 
## 49.2572

Aufgabenname: lm-mario2


Categories:

  • R
  • lm
  • predict
  • num