1. Raziskovalno vprašanje: Ali izobrazba staršev vpliva na rezultat študenta pri matematičnem testu?

1.1 Podatki

VIR: https://www.kaggle.com/datasets/spscientist/students-performance-in-exams?resource=download

library(readr)
Podatki <- read_delim("C:/Users/badov/Desktop/archive/StudentsPerformance.csv", 
    delim = ";", escape_double = FALSE, trim_ws = TRUE)
## Rows: 1000 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ";"
## chr (5): gender, race, ParentsEducation, Lunch, TestPreparationCourse
## dbl (3): MathScore, ReadingScore, WritingScore
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

1.2 Analiza

library(dplyr)
## 
## Attaching package: 'dplyr'
## 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(ParentsEducation) %>%
  shapiro_test(MathScore)
## # A tibble: 6 × 4
##   ParentsEducation   variable  statistic       p
##   <chr>              <chr>         <dbl>   <dbl>
## 1 associate's degree MathScore     0.987 0.0446 
## 2 bachelor's degree  MathScore     0.991 0.604  
## 3 high school        MathScore     0.987 0.0652 
## 4 master's degree    MathScore     0.956 0.0317 
## 5 some college       MathScore     0.989 0.0959 
## 6 some high school   MathScore     0.977 0.00516
library(car)
## Loading required package: carData
## 
## Attaching package: 'car'
## The following object is masked from 'package:dplyr':
## 
##     recode
leveneTest(Podatki$MathScore, Podatki$ParentsEducation)
## Warning in leveneTest.default(Podatki$MathScore, Podatki$ParentsEducation):
## Podatki$ParentsEducation coerced to factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   5  0.9333 0.4584
##       994
library(Rmisc)
## Loading required package: lattice
## Loading required package: plyr
## ------------------------------------------------------------------------------
## You have loaded plyr after dplyr - this is likely to cause problems.
## If you need functions from both plyr and dplyr, please load plyr first, then dplyr:
## library(plyr); library(dplyr)
## ------------------------------------------------------------------------------
## 
## Attaching package: 'plyr'
## The following objects are masked from 'package:rstatix':
## 
##     desc, mutate
## The following objects are masked from 'package:dplyr':
## 
##     arrange, count, desc, failwith, id, mutate, rename, summarise,
##     summarize
Rezultati_skupine <- summarySE(Podatki,
                               measurevar = "MathScore",
                               groupvars = "ParentsEducation",
                               conf.interval = 0.95)
Rezultati_skupine
##     ParentsEducation   N MathScore       sd        se       ci
## 1 associate's degree 222  67.88288 15.11209 1.0142573 1.998854
## 2  bachelor's degree 118  69.38983 14.94379 1.3756873 2.724477
## 3        high school 196  62.13776 14.53965 1.0385465 2.048226
## 4    master's degree  59  69.74576 15.15392 1.9728717 3.949132
## 5       some college 226  67.12832 14.31290 0.9520797 1.876133
## 6   some high school 179  63.49721 15.92799 1.1905138 2.349337
Rezultati_anova <- aov(MathScore ~ ParentsEducation,
                       data = Podatki)

summary(Rezultati_anova)
##                   Df Sum Sq Mean Sq F value   Pr(>F)    
## ParentsEducation   5   7296  1459.1   6.522 5.59e-06 ***
## Residuals        994 222394   223.7                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
library(effectsize)
## 
## Attaching package: 'effectsize'
## The following objects are masked from 'package:rstatix':
## 
##     cohens_d, eta_squared
effectsize::eta_squared(Rezultati_anova)
## 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
## --------------------------------------
## ParentsEducation | 0.03 | [0.01, 1.00]
## 
## - One-sided CIs: upper bound fixed at [1.00].
interpret_eta_squared(0.64, rules = "cohen1992")
## [1] "large"
## (Rules: cohen1992)
pairwise.t.test(Podatki$MathScore, Podatki$ParentsEducation,
                paired = FALSE,
                p.adjust = "bonf")
## 
##  Pairwise comparisons using t tests with pooled SD 
## 
## data:  Podatki$MathScore and Podatki$ParentsEducation 
## 
##                   associate's degree bachelor's degree high school
## bachelor's degree 1.00000            -                 -          
## high school       0.00143            0.00052           -          
## master's degree   1.00000            1.00000           0.00959    
## some college      1.00000            1.00000           0.00984    
## some high school  0.05390            0.01388           1.00000    
##                   master's degree some college
## bachelor's degree -               -           
## high school       -               -           
## master's degree   -               -           
## some college      1.00000         -           
## some high school  0.08238         0.23153     
## 
## P value adjustment method: bonferroni

1.3 Ugotovitve

Srednja šola je statistično značilna od vseh ostalih izobraževanj, ker so p vrednosti zelo male.


  1. Raziskovalno vprašanje:Ali lahko z višino igralca in z odstotekh uspešnih košev med igro, glede na 100 poiskusov pojasnjujemo razlike v številu povprečnih točk na igro.

2.1 Podatki

Vir: https://college.cengage.com/mathematics/brase/understandable_statistics/7e/students/datasets/mlr/frames/frame.html

library(readxl)
podatki2 <- read_excel("C:/Users/badov/Desktop/Basketball.xlsx")

Opis spremenljivk: - height: Višina igralca v ameriških “feet” - weight: Teža igralca v “pounds” - successful.goals: Odstotek uspešnih košev med igro, glede na 100 poiskusov - average.points: Povprečno število točk na igro

2.2 Analiza

summary(podatki2[c("height", "weight", "successful.goals", "average.points")])
##      height          weight      successful.goals average.points 
##  Min.   :5.700   Min.   :105.0   Min.   :0.2910   Min.   : 2.80  
##  1st Qu.:6.225   1st Qu.:185.0   1st Qu.:0.4153   1st Qu.: 8.15  
##  Median :6.650   Median :212.5   Median :0.4435   Median :10.75  
##  Mean   :6.587   Mean   :209.9   Mean   :0.4491   Mean   :11.79  
##  3rd Qu.:6.900   3rd Qu.:235.0   3rd Qu.:0.4835   3rd Qu.:13.60  
##  Max.   :7.600   Max.   :263.0   Max.   :0.5990   Max.   :27.40
library(car)
scatterplot(average.points ~ height,
            ylab = "Povprečno število točk na igro",
            xlab = "Višina igralca v ameriških 'feet'",
            smooth = FALSE,
            data = podatki2)

Šibka linearna povezava, negativna.

fit1 <- lm(average.points ~ height + weight + successful.goals,
          data = podatki2)

podatki2$StdOstanki <- round(rstandard(fit1), 3)
podatki2$CooksD <- round(cooks.distance(fit1), 3)

hist(podatki2$StdOstanki,
     xlab = "Standardizirani ostanki",
     ylab = "Frekvenca",
     main = "Histogram standardiziranih ostankov")

Preverjamo ali je izpolnjena predpostavka o normalni porazdelitvi.

shapiro.test(podatki2$StdOstanki)
## 
##  Shapiro-Wilk normality test
## 
## data:  podatki2$StdOstanki
## W = 0.9283, p-value = 0.003124

Zavrnemo H0, napake niso normalno porazdeljene

hist(podatki2$CooksD,
     xlab = "Cookove razdalje",
     ylab = "Frekvenca",
     main = "Histogram Cookovih razdalj")

Izločimo dva osamelca pri 0.10 in 0.15.

library(olsrr)
## 
## Attaching package: 'olsrr'
## The following object is masked from 'package:datasets':
## 
##     rivers
ols_test_breusch_pagan(fit1)
## 
##  Breusch Pagan Test for Heteroskedasticity
##  -----------------------------------------
##  Ho: the variance is constant            
##  Ha: the variance is not constant        
## 
##                    Data                    
##  ------------------------------------------
##  Response : average.points 
##  Variables: fitted values of average.points 
## 
##        Test Summary         
##  ---------------------------
##  DF            =    1 
##  Chi2          =    1.697425 
##  Prob > Chi2   =    0.192625

Heteroskedastičnost

summary(fit1)
## 
## Call:
## lm(formula = average.points ~ height + weight + successful.goals, 
##     data = podatki2)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -8.512 -3.588 -1.005  2.259 15.842 
## 
## Coefficients:
##                   Estimate Std. Error t value Pr(>|t|)   
## (Intercept)      14.887932  13.001833   1.145  0.25763   
## height           -3.930241   2.998253  -1.311  0.19590   
## weight           -0.002064   0.046099  -0.045  0.96447   
## successful.goals 51.712489  15.658425   3.303  0.00177 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 5.469 on 50 degrees of freedom
## Multiple R-squared:  0.1891, Adjusted R-squared:  0.1404 
## F-statistic: 3.887 on 3 and 50 DF,  p-value: 0.01421

y = 14,8879 -3,93x1 - 0,002064x2 + 51,712489x3

kor_koeficient <- sqrt(summary(fit1)$r.squared)
kor_koeficient
## [1] 0.4348596
anova(fit1)
## Analysis of Variance Table
## 
## Response: average.points
##                  Df  Sum Sq Mean Sq F value   Pr(>F)   
## height            1    8.76    8.76  0.2928 0.590858   
## weight            1   13.78   13.78  0.4606 0.500472   
## successful.goals  1  326.26  326.26 10.9067 0.001774 **
## Residuals        50 1495.67   29.91                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

2.3 Ugotovitve

Zavrnemo H0 pri p<0,001 in sprejmemo sklep, da je regresijski koeficient različen od 0.