library(readr)
podatki <- read_csv("ThrowbackDataThursday 2019 Week 1 - NFL Injuries 2012 to 2017.csv", show_col_types = FALSE)
1.1. Podatki Vir: https://www.kaggle.com/datasets/thedevastator/nfl-injury-data-2012-2017
Opis spremenljivk:
1.2. Analiza
library(psych)
describeBy(podatki$Injuries, g = podatki$Scenario)
##
## Descriptive statistics by group
## group: Game
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 54 84.3 68.91 45.5 76.7 46.7 10 241 231 0.78 -0.74 9.38
## ------------------------------------------------------------
## group: Practice
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 54 18.59 13.95 16 17.11 12.6 0 56 56 0.92 -0.11 1.9
library(ggplot2)
##
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
##
## %+%, alpha
ggplot(podatki, aes(x = Injuries)) +
geom_histogram(binwidth = 30, color = "orange") +
facet_wrap(~Scenario, ncol = 1) +
ylab("Frekvenca")
library(rstatix)
##
## Attaching package: 'rstatix'
## The following object is masked from 'package:stats':
##
## filter
podatki %>%
group_by(Scenario) %>%
shapiro_test(Injuries)
## # A tibble: 2 × 4
## Scenario variable statistic p
## <chr> <chr> <dbl> <dbl>
## 1 Game Injuries 0.863 0.0000186
## 2 Practice Injuries 0.898 0.000243
wilcox.test(podatki$Injuries ~ podatki$Scenario,
paired = FALSE,
correct = FALSE,
exact = FALSE,
alternative = "two.sided")
##
## Wilcoxon rank sum test
##
## data: podatki$Injuries by podatki$Scenario
## W = 2520, p-value = 6.698e-11
## alternative hypothesis: true location shift is not equal to 0
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
effectsize(wilcox.test(podatki$Injuries ~ podatki$Scenario,
paired = FALSE,
correct = FALSE,
exact = FALSE,
alternative = "two.sided"))
## r (rank biserial) | 95% CI
## --------------------------------
## 0.73 | [0.61, 0.82]
interpret_rank_biserial(0.73)
## [1] "very large"
## (Rules: funder2019)
1.3 Ugotovitve Na podlagi vzorčnih podatkov ugotavljamo, da je razlika v številu poškodb glede na čas nastanka (med treningom in tekmo) p < 0,001. Razlika v številu poškodb je zelo velika (r = 0,73)
Zanima nas kako število dnevno prehojenih korakov posameznika vpliva na dolžino spanca (v urah).
2.1 Podatki Vir: https://www.kaggle.com/datasets/uom190346a/sleep-health-and-lifestyle-dataset
Opis spremenljivk:
2.2 Analiza
library(readr)
podatkispanje <- read_delim("Sleep_health_and_lifestyle_dataset.csv",
delim = ";", escape_double = FALSE, trim_ws = TRUE, show_col_types = FALSE)
library(ggplot2)
library(ellipsis)
plot(SleepDuration ~ DailySteps,
ylab = "Čas spanja v urah",
xlab = "Število prehojenih korakov",
data = podatkispanje)
fit1 <- lm(SleepDuration ~ DailySteps,
data = podatkispanje)
summary(fit1)
##
## Call:
## lm(formula = SleepDuration ~ DailySteps, data = podatkispanje)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.36352 -0.74797 0.07148 0.69092 1.33259
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 7.265e+00 1.785e-01 40.701 <2e-16 ***
## DailySteps -1.944e-05 2.548e-05 -0.763 0.446
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.7961 on 372 degrees of freedom
## Multiple R-squared: 0.001563, Adjusted R-squared: -0.001121
## F-statistic: 0.5823 on 1 and 372 DF, p-value: 0.4459
fit2 <- lm(SleepDuration ~ DailySteps + Gender,
data = podatkispanje)
summary(fit2)
##
## Call:
## lm(formula = SleepDuration ~ DailySteps + Gender, data = podatkispanje)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.46305 -0.74680 -0.02649 0.77351 1.23288
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 7.369e+00 1.827e-01 40.325 <2e-16 ***
## DailySteps -2.031e-05 2.532e-05 -0.802 0.4230
## GenderMale -1.942e-01 8.184e-02 -2.373 0.0182 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.7912 on 371 degrees of freedom
## Multiple R-squared: 0.01649, Adjusted R-squared: 0.01119
## F-statistic: 3.11 on 2 and 371 DF, p-value: 0.04578
fit3 <- lm(SleepDuration ~ DailySteps + Gender + DailySteps:Gender,
data = podatkispanje)
summary(fit3)
##
## Call:
## lm(formula = SleepDuration ~ DailySteps + Gender + DailySteps:Gender,
## data = podatkispanje)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.84856 -0.42311 0.01098 0.41779 1.95004
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 8.976e+00 1.985e-01 45.228 <2e-16 ***
## DailySteps -2.553e-04 2.813e-05 -9.076 <2e-16 ***
## GenderMale -3.886e+00 2.990e-01 -12.999 <2e-16 ***
## DailySteps:GenderMale 5.419e-04 4.271e-05 12.686 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6614 on 370 degrees of freedom
## Multiple R-squared: 0.3146, Adjusted R-squared: 0.309
## F-statistic: 56.61 on 3 and 370 DF, p-value: < 2.2e-16
podatki_m <- podatkispanje[podatkispanje$Gender=="Male" , ]
podatki_ž <- podatkispanje[podatkispanje$Gender=="Female" , ]
fit_m <- lm(SleepDuration ~ DailySteps,
data = podatki_m)
summary(fit_m)
##
## Call:
## lm(formula = SleepDuration ~ DailySteps, data = podatki_m)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.75535 -0.40907 0.01779 0.31779 1.95004
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 5.0896603 0.1843170 27.61 <2e-16 ***
## DailySteps 0.0002866 0.0000265 10.82 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.5451 on 187 degrees of freedom
## Multiple R-squared: 0.3848, Adjusted R-squared: 0.3815
## F-statistic: 117 on 1 and 187 DF, p-value: < 2.2e-16
fit_ž <- lm(SleepDuration ~ DailySteps,
data = podatki_ž)
summary(fit_ž)
##
## Call:
## lm(formula = SleepDuration ~ DailySteps, data = podatki_ž)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.84856 -0.64432 0.01098 0.80038 1.77689
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 8.976e+00 2.287e-01 39.253 < 2e-16 ***
## DailySteps -2.553e-04 3.241e-05 -7.877 2.88e-13 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.7621 on 183 degrees of freedom
## Multiple R-squared: 0.2532, Adjusted R-squared: 0.2491
## F-statistic: 62.05 on 1 and 183 DF, p-value: 2.878e-13
2.3 Ugotovitve
Če se število dnevno prehojenih korakov poveča za 1 korak se čas spanja v povprečju zmanjša za 0,00002031 ure, kar velja tako za moške kot za ženske (to bi veljalo če bi bili premici vzporedni)