Analiziral bom podatke o plačah podatkovnih analitikov v letu 2023;
Vir podatkov: https://www.kaggle.com/datasets/arnabchaki/data-science-salaries-2023
Osnovna hipoteza:
H0: vse aritmetične sredine analiziranih spremenljivk so enake
H1: vsaj ena aritmetična sredina se razlikuje
podatki <- read.table("/cloud/project/ds_salaries_csv.csv", header = TRUE , sep=";", dec = ",")
head(podatki)
## ID salary remote_type
## 1 1 30.0000 2
## 2 2 5.6536 3
## 3 3 5.9888 3
## 4 4 16.8000 3
## 5 5 8.5000 1
## 6 6 18.0000 3
Opis spremenljivk:
Faktoriram spremenljivko remote_type:
podatki$remote_typeF <- factor(podatki$remote_type,
levels = c(1, 2, 3),
labels = c("pisarna", "hibrid", "doma"))
library(psych)
psych::describe(podatki$salary)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 115 7.79 5.36 6.16 7.32 4.45 0.63 30 29.37 1.02 1.22 0.5
psych::describeBy(podatki$salary, podatki$remote_typeF)
##
## Descriptive statistics by group
## group: pisarna
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 35 10.38 4.74 10.8 10.62 4.96 0.63 18.98 18.34 -0.26 -0.98 0.8
## ------------------------------------------------------------
## group: hibrid
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 23 6.99 6.63 5 5.67 3.36 1 30 29 2.07 4.09 1.38
## ------------------------------------------------------------
## group: doma
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 57 6.53 4.65 5.11 6.01 3.36 0.63 18 17.37 1.01 0.27 0.62
Levenov test:
H0: variance spremenljivke “salary” so pri vseh skupinah enake
H1: vsaj ena varianca spremenljivke “salary” se razlikuje
library(car)
## Loading required package: carData
##
## Attaching package: 'car'
## The following object is masked from 'package:psych':
##
## logit
leveneTest(podatki$salary, podatki$remote_typeF)
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 2 0.4488 0.6395
## 112
Test ne zavrne ničelne domneve, tako da obstaja velika možnost, da so variance enake.
Shapiro-Wilkov preizkus:
H0: variance se normalno porazdeljujejo
H1: variance niso normalno porazdeljene
library(dplyr)
##
## Attaching package: 'dplyr'
## The following object is masked from 'package:car':
##
## recode
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(rstatix)
##
## Attaching package: 'rstatix'
## The following object is masked from 'package:stats':
##
## filter
podatki %>%
group_by(remote_typeF) %>%
shapiro_test(salary)
## # A tibble: 3 × 4
## remote_typeF variable statistic p
## <fct> <chr> <dbl> <dbl>
## 1 pisarna salary 0.949 0.106
## 2 hibrid salary 0.729 0.0000337
## 3 doma salary 0.892 0.0000987
Test ne zavrne ničelne domneve samo pri spremenljivki remoteFpisarna, kar pomeni, da se varianci dveh spremenljivk ne porazdeljujeta normalno; vseeno izvedem spodaj postopek za ANOVA test:
ANOVA test:
rezultati <- aov(salary ~ remote_typeF,
data = podatki)
summary(rezultati)
## Df Sum Sq Mean Sq F value Pr(>F)
## remote_typeF 2 339.6 169.81 6.468 0.0022 **
## Residuals 112 2940.6 26.26
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Če Shapiro-Wilkov preizkus normalnosti porazdelitve varianc ne bi zavrnil vseh treh ničelnih domnev, bi lahko trdili, da smo dobili statistično značilno povezavo med velikostjo plače in načinom dela med podatkovnimi analitiki (F=6,468, p<0,001).
Velikost učinka: majhna
library(effectsize)
##
## Attaching package: 'effectsize'
## The following objects are masked from 'package:rstatix':
##
## cohens_d, eta_squared
## The following object is masked from 'package:psych':
##
## phi
eta_squared(rezultati)
## For one-way between subjects designs, partial eta squared is equivalent
## to eta squared. Returning eta squared.
## # Effect Size for ANOVA
##
## Parameter | Eta2 | 95% CI
## ----------------------------------
## remote_typeF | 0.10 | [0.02, 1.00]
##
## - One-sided CIs: upper bound fixed at [1.00].
Interpretacija velikosti učinka:
interpret_eta_squared(0.10, rules = "cohen1992")
## [1] "small"
## (Rules: cohen1992)
Welchev F-preizkus (če bi bila kršena predpostavka homogenosti varianc; v našem primeru je ta podatek neuporaben):
library(onewaytests)
##
## Attaching package: 'onewaytests'
## The following object is masked from 'package:psych':
##
## describe
welch.test(salary ~ remote_typeF,
data = podatki)
##
## Welch's Heteroscedastic F Test (alpha = 0.05)
## -------------------------------------------------------------
## data : salary and remote_typeF
##
## statistic : 7.369117
## num df : 2
## denom df : 50.68641
## p.value : 0.00155135
##
## Result : Difference is statistically significant.
## -------------------------------------------------------------
Post-hoc testi za ANOVA test:
pairwise.t.test(podatki$salary, g = podatki$remote_typeF,
paired = FALSE,
p.adj = "none")
##
## Pairwise comparisons using t tests with pooled SD
##
## data: podatki$salary and podatki$remote_typeF
##
## pisarna hibrid
## hibrid 0.01532 -
## doma 0.00068 0.71611
##
## P value adjustment method: none
pairwise.t.test(podatki$salary, g = podatki$remote_typeF,
paired = FALSE,
p.adj = "bonf")
##
## Pairwise comparisons using t tests with pooled SD
##
## data: podatki$salary and podatki$remote_typeF
##
## pisarna hibrid
## hibrid 0.046 -
## doma 0.002 1.000
##
## P value adjustment method: bonferroni
Grafični prikaz ANOVA testa:
pwc <- podatki %>%
pairwise_t_test(salary ~ remote_typeF,
paired = FALSE,
p.adjust.method = "bonferroni")
ANOVA_rezultati <- anova_test(salary ~ remote_typeF,
data = podatki)
library(rstatix)
pwc <- pwc %>%
add_y_position(fun = "median", step.increase = 0.35)
library(ggpubr)
## Loading required package: ggplot2
##
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
##
## %+%, alpha
ggboxplot(
podatki,
x = "remote_typeF",
y = "salary",
add = "point",
ylim = c(0, 30)
) +
stat_pvalue_manual(pwc, hide.ns = FALSE) +
stat_summary(
fun = mean,
geom = "point",
shape = 16,
size = 4,
aes(group = remote_typeF),
color = "darkred",
position = position_dodge(width = 0.8)
) +
stat_summary(
fun = mean,
colour = "darkred",
position = position_dodge(width = 0.8),
geom = "text",
vjust = -0.5,
hjust = -1,
aes(label = round(after_stat(y), digits = 2), group = remote_typeF)
) +
labs(subtitle = get_test_label(ANOVA_rezultati, detailed = TRUE),
caption = get_pwc_label(pwc))
Sedaj pa izvedem “pravilen” preizkus:
Kruskal-Wallisov preizkus vsot rangov (neparametrični preizkus):
H0: lokacije porazdelitev so enake
H1: vsaj ena lokacija porazdelitev se razlikuje
kruskal.test(salary ~ remote_typeF,
data = podatki)
##
## Kruskal-Wallis rank sum test
##
## data: salary by remote_typeF
## Kruskal-Wallis chi-squared = 16.583, df = 2, p-value = 0.0002507
kruskal_effsize(salary ~ remote_typeF,
data = podatki)
## # A tibble: 1 × 5
## .y. n effsize method magnitude
## * <chr> <int> <dbl> <chr> <ord>
## 1 salary 115 0.130 eta2[H] moderate
H0 zavrnemo pri p<0,001: lokacije porazdelitev so različne, našli smo statistično značilne povezave med višino plače in načinom dela med podatkovnimi analitiki.
Post-hoc preizkus:
library(rstatix)
skupine_nepar <- wilcox_test(salary ~ remote_typeF,
paired = FALSE,
p.adjust.method = "bonferroni",
data = podatki)
skupine_nepar
## # A tibble: 3 × 9
## .y. group1 group2 n1 n2 statistic p p.adj p.adj.signif
## * <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <chr>
## 1 salary pisarna hibrid 35 23 598. 0.002 0.006 **
## 2 salary pisarna doma 35 57 1471 0.000141 0.000423 ***
## 3 salary hibrid doma 23 57 626. 0.754 1 ns
Wilcoxonov test je ob uporabi Bonferronijevega popravka odkril, da sta statistično značilni razliki v plači med “pisarna” in “hibrid” ter “pisarna” in “doma”.
Grafični prikaz neparametričnega preizkusa:
pwc <- podatki %>%
wilcox_test(salary ~ remote_typeF,
paired = FALSE,
p.adjust.method = "bonferroni")
Kruskal_rezultati <- kruskal_test(salary ~ remote_typeF,
data = podatki)
library(rstatix)
pwc <- pwc %>%
add_y_position(fun = "median", step.increase = 0.35)
library(ggpubr)
ggboxplot(podatki, x = "remote_typeF", y = "salary", add = "point", ylim=c(0, 30)) +
stat_pvalue_manual(pwc, hide.ns = FALSE) +
stat_summary(fun = median, geom = "point", shape = 16, size = 4,
aes(group = remote_typeF), color = "darkred",
position = position_dodge(width = 0.8)) +
stat_summary(fun = median, colour = "darkred",
position = position_dodge(width = 0.8),
geom = "text", vjust = -0.5, hjust = -1,
aes(label = round(after_stat(y), digits = 2), group = remote_typeF)) +
labs(subtitle = get_test_label(Kruskal_rezultati, detailed = TRUE),
caption = get_pwc_label(pwc))