Skip to main content

mariokart_desk-inf-mod

R
bayes
lagemaße
regression
tidyverse
vis
yacsda
Published

February 26, 2025

Untersuchen Sie den Datensatz mariokart. Beantworten Sie dabei die folgende Forschungsfrage:

Erzielen Spiele mit Photo (stock_photo) einen höheren Verkaufspreis (total_pr) im Vergleich zu Spielen ohne Photo?

  1. Prüfen Sie auf fehlende Werte und Extremwerte und führen Sie ggf. entsprechende Schritte aus, um etwaige Probleme in diesem Zusammenhang zu lösen.
  2. Berechnen Sie relevante deskriptive Statistiken.
  3. Visualisieren Sie die die Daten sinnvoll.
  4. Berechnen und interpretieren Sie ein passendes Modell. e.Berechnen und interpretieren Sie Maße der Inferenzstatistik (Bayes oder Frequentistisch).

Hinweise:

  • Beachten Sie die üblichen Hinweise des Datenwerks.













0.1 Vorbereitung

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()`.
library(ggpubr)
## 
## Attache Paket: 'ggpubr'
## 
## Die folgenden Objekte sind maskiert von 'package:datawizard':
## 
##     mean_sd, median_mad
library(visdat)
library(rstanarm)
## Lade nötiges Paket: Rcpp
## Registered S3 method overwritten by 'lme4':
##   method           from
##   na.action.merMod car 
## This is rstanarm version 2.32.2
## - See https://mc-stan.org/rstanarm/articles/priors for changes to default priors!
## - Default priors may change, so it's safest to specify priors, even if equivalent to the defaults.
## - For execution on a local, multicore CPU with excess RAM we recommend calling
##   options(mc.cores = parallel::detectCores())
## 
## Attache Paket: 'rstanarm'
## 
## Das folgende Objekt ist maskiert 'package:parameters':
## 
##     compare_models
mariokart <- read.csv("https://vincentarelbundock.github.io/Rdatasets/csv/openintro/mariokart.csv")

0.2 Vorverarbeitung

0.2.1 Extremwerte

gghistogram(mariokart, x = "total_pr")
## Warning: Using `bins = 30` by default. Pick better value with the argument
## `bins`.

plot of chunk unnamed-chunk-3

Ja, besser wir entfernen die Extremwerte:

mariokart_no_extreme <- 
  mariokart |> 
  filter(total_pr < 100)

0.2.2 Fehlende Werte

Fehlende Werte visualisieren:

vis_dat(mariokart_no_extreme)

plot of chunk unnamed-chunk-5

Fehlende Werte zählen:

colSums(is.na(mariokart_no_extreme))
##    rownames          id    duration      n_bids        cond    start_pr 
##           0           0           0           0           0           0 
##     ship_pr    total_pr     ship_sp seller_rate stock_photo      wheels 
##           0           0           0           0           0           0 
##       title 
##           0

Oder so, mit dplyr:

mariokart_no_extreme |> 
  summarise(across(everything(), ~ sum(is.na(.x))))
##   rownames id duration n_bids cond start_pr ship_pr total_pr ship_sp
## 1        0  0        0      0    0        0       0        0       0
##   seller_rate stock_photo wheels title
## 1           0           0      0     0

0.3 Deskriptive Statistik

0.3.1 Metrische Variablen

Überblick

describe_distribution(mariokart_no_extreme) |> 
  format_table(digits = 2)
##      Variable     Mean       SD      IQR      Min      Max Skewness  Kurtosis
## 1    rownames    72.42    41.48    72.00     1.00   143.00    -0.02     -1.20
## 2          id 2.25e+11 8.78e+10 1.60e+11 1.10e+11 4.00e+11     0.23     -1.24
## 3    duration     3.75     2.59     6.00     1.00    10.00     0.35     -1.31
## 4      n_bids    13.38     5.76     7.50     1.00    29.00    -0.07     -0.03
## 5    start_pr     8.85    15.16     9.01     0.01    69.95     2.35      5.40
## 6     ship_pr     2.98     2.62     4.00     0.00    11.45     0.95      1.32
## 7    total_pr    47.43     9.11    12.99    28.98    75.00     0.41 -1.75e-03
## 8 seller_rate 16122.82 52174.55  4748.50     0.00 2.70e+05     4.06     16.12
## 9      wheels     1.15     0.84     2.00     0.00     4.00     0.14     -0.45
##     n n_Missing
## 1 141         0
## 2 141         0
## 3 141         0
## 4 141         0
## 5 141         0
## 6 141         0
## 7 141         0
## 8 141         0
## 9 141         0

Visualisierung:

describe_distribution(mariokart_no_extreme) |> plot()
## Error:
## ! Failed at retrieving data :( Please provide original model or data
##   through the `data` argument

0.3.2 Nominale Variablen

Überblick:

data_tabulate(mariokart_no_extreme, 
              select = c("cond", "ship_sp", "stock_photo")) |> 
  print_md() |> 
  format_table(digits = 2)
##                                                                x
## 1                                         Table: Frequency Table
## 2                                                               
## 3  |Variable    |      Value|   N|Raw % | Valid %| Cumulative %|
## 4  |:-----------|----------:|---:|:-----|-------:|------------:|
## 5  |cond        |        new|  59|41.84 |   41.84|        41.84|
## 6  |            |       used|  82|58.16 |   58.16|       100.00|
## 7  |            |       (NA)|   0| 0.00 |    (NA)|         (NA)|
## 8  |            |           |    |      |        |             |
## 9  |ship_sp     | firstClass|  22|15.60 |   15.60|        15.60|
## 10 |            |      media|  14| 9.93 |    9.93|        25.53|
## 11 |            |      other|   3| 2.13 |    2.13|        27.66|
## 12 |            |     parcel|  14| 9.93 |    9.93|        37.59|
## 13 |            |   priority|  23|16.31 |   16.31|        53.90|
## 14 |            |   standard|  33|23.40 |   23.40|        77.30|
## 15 |            |    ups3Day|   1| 0.71 |    0.71|        78.01|
## 16 |            |  upsGround|  31|21.99 |   21.99|       100.00|
## 17 |            |       (NA)|   0| 0.00 |    (NA)|         (NA)|
## 18 |            |           |    |      |        |             |
## 19 |stock_photo |         no|  36|25.53 |   25.53|        25.53|
## 20 |            |        yes| 105|74.47 |   74.47|       100.00|
## 21 |            |       (NA)|   0| 0.00 |    (NA)|         (NA)|
## 22 |            |           |    |      |        |             |

Visualisierung:

data_tabulate(mariokart_no_extreme, 
              select = c("cond", "ship_sp", "stock_photo")) |> 
  plot()
## [[1]]

plot of chunk unnamed-chunk-11
## 
## [[2]]

plot of chunk unnamed-chunk-11
## 
## [[3]]

plot of chunk unnamed-chunk-11

0.3.3 Alternative

skimr::skim(mariokart_no_extreme)
Data summary
Name mariokart_no_extreme
Number of rows 141
Number of columns 13
_______________________
Column type frequency:
character 4
numeric 9
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
cond 0 1 3 4 0 2 0
ship_sp 0 1 5 10 0 8 0
stock_photo 0 1 2 3 0 2 0
title 0 1 0 59 1 79 0

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
rownames 0 1 7.242000e+01 4.148000e+01 1.000000e+00 3.700000e+01 7.300000e+01 1.080000e+02 1.430000e+02 ▇▇▇▇▇
id 0 1 2.249920e+11 8.784150e+10 1.104395e+11 1.403507e+11 2.303822e+11 3.003523e+11 4.000775e+11 ▇▅▅▅▃
duration 0 1 3.750000e+00 2.590000e+00 1.000000e+00 1.000000e+00 3.000000e+00 7.000000e+00 1.000000e+01 ▇▅▂▆▁
n_bids 0 1 1.338000e+01 5.760000e+00 1.000000e+00 1.000000e+01 1.400000e+01 1.700000e+01 2.900000e+01 ▂▅▇▃▁
start_pr 0 1 8.850000e+00 1.516000e+01 1.000000e-02 9.900000e-01 1.000000e+00 1.000000e+01 6.995000e+01 ▇▁▁▁▁
ship_pr 0 1 2.980000e+00 2.620000e+00 0.000000e+00 0.000000e+00 2.990000e+00 4.000000e+00 1.145000e+01 ▅▇▁▁▁
total_pr 0 1 4.743000e+01 9.110000e+00 2.898000e+01 4.100000e+01 4.603000e+01 5.399000e+01 7.500000e+01 ▃▇▆▂▁
seller_rate 0 1 1.612282e+04 5.217455e+04 0.000000e+00 1.160000e+02 8.200000e+02 4.858000e+03 2.701440e+05 ▇▁▁▁▁
wheels 0 1 1.150000e+00 8.400000e-01 0.000000e+00 0.000000e+00 1.000000e+00 2.000000e+00 4.000000e+00 ▆▇▇▁▁

0.4 Visualisierung

ggboxplot(data = mariokart_no_extreme,
          x = "stock_photo",
          y = "total_pr",
          add = "mean_se",
          add.params = list(color = okabeito_colors()[1]))

plot of chunk unnamed-chunk-13

0.5 Modellierung

0.5.1 Kausalmodell

Wir nehmen folgendes Kausalmodell an.

graph LR
  photo --> price
  u --> price

Unter der Annahme dieses Kausalmodells können wir die Modellkoeffizienten als valide betrachten.

0.5.2 Modell - Frequentistisch

Modell berechnen und Parameter prüfen:

lm1 <- lm(total_pr ~ stock_photo, data = mariokart_no_extreme)
parameters(lm1) |> 
  format_table(digits = 2)
##           Parameter Coefficient   SE         95% CI t(139)      p
## 1       (Intercept)       44.33 1.49 [41.37, 47.28]  29.68 < .001
## 2 stock photo [yes]        4.17 1.73 [ 0.75,  7.59]   2.41 0.017

Visualisierung:

parameters(lm1) |> plot()

plot of chunk unnamed-chunk-16

0.5.3 Modell - Bayesianisch

Modell berechnen und Parameter prüfen:

lm1_bayes <- stan_glm(total_pr ~ stock_photo, 
                      data = mariokart_no_extreme,
                      refresh = 0)
parameters(lm1_bayes)
## Parameter      | Median |         95% CI |     pd |  Rhat | ESS (tail) |                   Prior
## ------------------------------------------------------------------------------------------------
## (Intercept)    |  44.32 | [41.27, 47.33] |   100% | 1.000 |       2408 | Normal (47.43 +- 22.78)
## stock_photoyes |   4.18 | [ 0.82,  7.68] | 99.25% | 1.000 |       3102 |  Normal (0.00 +- 52.07)
## 
## Uncertainty intervals (equal-tailed) computed using a MCMC distribution
##   approximation.

Visualisierung:

parameters(lm1_bayes) |> plot()

plot of chunk unnamed-chunk-18

0.6 Inferenzstatistik

0.6.1 Nullhypothese

Wie man sieht, ist die Null nicht im Konfidenzintervall enthalten. Daher können wir die Nullhypothese ausschließen.

0.6.2 ROPE

Wir können eine ROPE-Nullhypothese nicht komplett ausschließen, aber fast.

rope(lm1_bayes)
## # Proportion of samples inside the ROPE [-0.91, 0.91]:
## 
## Parameter      | Inside ROPE
## ----------------------------
## (Intercept)    |      0.00 %
## stock_photoyes |      0.42 %

Visualisierung:

rope(lm1_bayes) |> plot()
## Error:
## ! Failed at retrieving data :( Please provide original model or data
##   through the `data` argument

Aufgabenname: mariokart_desk-inf-mod