Skip to main content

lm-mario2

R
lm
predict
num
computer
Published

May 17, 2023

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











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.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()`.

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

Vorhersagen

Vorhersagen funktionieren mit dem Befehl predict:

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

Aufgabenname: lm-mario2


Categories:

  • R
  • lm
  • predict
  • num