podatki<-read.table("Pripravljalnica/Maraton/Maraton.csv",
                    header=TRUE,
                    sep=";",
                    dec=",")
head(podatki[,-1])
##   Teza Visina Tlak Utrip Hemoglobin Hematokrit Holesterol Glukoza Spol
## 1   72  179.0  105    64        160         50        4.9     4.7    1
## 2   68  178.0  105    60        158         51        4.8     4.9    0
## 3   64  174.0  109    54        155         51        4.5     7.0    0
## 4   63  174.0  112    54        153         58        8.0     7.2    0
## 5   61  173.5  100    53        152         59        4.6     6.7    0
## 6   60  173.0   99    53        158         49        3.9     6.0    0

Enota: Atlet Spremenljivke: * Teža, Višina, Tlak, Utrip, Hemoglobin, Hematokrit, Holesterol, Glukoza - Številske, razmernostne. Višina, Holesterol in glukoza zvezne, ostale diskretne * Spol: Kategorialna nominalna

summary(podatki$Visina)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   166.0   173.2   177.0   177.0   181.0   189.0
sd(podatki$Visina)
## [1] 5.85156

Aritmetična sredina je mean = 177cm, to je povprečna višina, seštejemo vse vrednosti in vsoto delimo z številom vseh vrednosti.

Standardni odklon znaša s= 5,85. Ta opiše, kako variirajo posamezne vrednosti spremenljivke okoli povprečja.Razpršenost - pove nam kako je višina razpršena okoli povprečja, če gre za normalno porazdelitev, vemo da je 1 sd od povprečja 68% vrednosti.

podatki$spolfaktor<-factor(podatki$Spol,
       levels=c(1,0),
       labels=c("M","Z"))
library(psych)
describeBy(podatki$Glukoza,group=podatki$spolfaktor)
## 
##  Descriptive statistics by group 
## group: M
##    vars  n mean  sd median trimmed  mad min max range skew kurtosis   se
## X1    1 21 4.54 0.7    4.6    4.45 0.74 3.8   6   2.2 0.97    -0.13 0.15
## ------------------------------------------------------------ 
## group: Z
##    vars  n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 14 5.96 0.93    5.8    5.97 1.33 4.6 7.2   2.6 0.12    -1.62 0.25

t-test kjer je rezultat -3,07 + ali smemo zavrniti H0 (H0: μ_gluk = 5,0)

t.test(podatki$Glukoza,
       mu = 5.0,
       alternative ="two.sided")
## 
##  One Sample t-test
## 
## data:  podatki$Glukoza
## t = 0.58365, df = 34, p-value = 0.5633
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  4.741168 5.467404
## sample estimates:
## mean of x 
##  5.104286

! ni ok, vzeli vse podatke, ne sam moških:

t.test(podatki[podatki$spolfaktor=="M",]$Glukoza,
       mu = 5.0,
       alternative ="two.sided")
## 
##  One Sample t-test
## 
## data:  podatki[podatki$spolfaktor == "M", ]$Glukoza
## t = -3.0324, df = 20, p-value = 0.006578
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  4.216336 4.855093
## sample estimates:
## mean of x 
##  4.535714

Zavrnemo H0 pri p = 0,007. Povpr. vrednost glukoze pri moških se razlikuje od vrednosti 5,0.

  1. Način:
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
podatki_m <- podatki %>%
  filter(spolfaktor == "M")

t.test(podatki_m$Glukoza,
       mu = 5.0,
       alternative ="two.sided")
## 
##  One Sample t-test
## 
## data:  podatki_m$Glukoza
## t = -3.0324, df = 20, p-value = 0.006578
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  4.216336 4.855093
## sample estimates:
## mean of x 
##  4.535714

Lahko upoštevamo tudi težo.& = IN, | = ALI

t.test(podatki[podatki$spolfaktor=="M" & podatki$Teza > 70,]$Glukoza,
       mu = 5.0,
       alternative ="two.sided")
## 
##  One Sample t-test
## 
## data:  podatki[podatki$spolfaktor == "M" & podatki$Teza > 70, ]$Glukoza
## t = -6.4369, df = 14, p-value = 1.556e-05
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  4.14675 4.57325
## sample estimates:
## mean of x 
##      4.36
library(pastecs)
## 
## Attaching package: 'pastecs'
## The following objects are masked from 'package:dplyr':
## 
##     first, last
round(stat.desc(podatki[,c(-1,-10,-11)]),2)
##                 Teza  Visina    Tlak   Utrip Hemoglobin Hematokrit Holesterol
## nbr.val        35.00   35.00   35.00   35.00      35.00      35.00      35.00
## nbr.null        0.00    0.00    0.00    0.00       0.00       0.00       0.00
## nbr.na          0.00    0.00    0.00    0.00       0.00       0.00       0.00
## min            55.00  166.00   90.00   49.00     143.00      45.00       3.40
## max            81.00  189.00  135.00   64.00     183.00      69.00       8.00
## range          26.00   23.00   45.00   15.00      40.00      24.00       4.60
## sum          2375.00 6193.50 3838.00 1967.00    5445.00    1801.00     167.60
## median         68.00  177.00  108.00   55.00     157.00      51.00       4.70
## mean           67.86  176.96  109.66   56.20     155.57      51.46       4.79
## SE.mean         1.30    0.99    1.79    0.67       1.45       0.82       0.17
## CI.mean.0.95    2.64    2.01    3.64    1.37       2.94       1.66       0.34
## var            59.01   34.24  112.47   15.81      73.13      23.49       1.00
## std.dev         7.68    5.85   10.61    3.98       8.55       4.85       1.00
## coef.var        0.11    0.03    0.10    0.07       0.05       0.09       0.21
##              Glukoza
## nbr.val        35.00
## nbr.null        0.00
## nbr.na          0.00
## min             3.80
## max             7.20
## range           3.40
## sum           178.65
## median          4.80
## mean            5.10
## SE.mean         0.18
## CI.mean.0.95    0.36
## var             1.12
## std.dev         1.06
## coef.var        0.21

Največjo variabilnost imata spremenljivki Glukoza in Holesterol (glej coef.var).

95% interval zaupanja za povpr. holesterol je 4,79 +- 0,34. (Gledaš mean in CI.mean.0.95)

ybar=mean(podatki$Holesterol);sd = sd(podatki$Holesterol); n=nrow(podatki)

se = sd/sqrt(n)

ybar_spodnja_z=ybar+qt(0.025, df=n-1)*se 
ybar_zgornja_z=ybar+qt(0.975, df=n-1)*se

cat(c("95-odstotna intervalna ocena:", round(ybar_spodnja_z,3), "< Mu <", round(ybar_zgornja_z, 3)))
## 95-odstotna intervalna ocena: 4.445 < Mu < 5.133
hist(podatki$Hematokrit,
     main = "Frekvenčna porazdelitev spremenljivke ¨Hematokrit¨",
     xlab= "Hematokrit",
     ylab = "Frekvenca",
     col = "grey",
     breaks = seq(from=40, to=70, by=2))

Asimetrično v desno.

#install.packages("ggplot2")
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.2
## 
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
## 
##     %+%, alpha
ggplot(podatki, aes(x = spolfaktor, y = Glukoza)) + #aes = aestetics
  geom_boxplot(fill="seashell")+
  theme_light()+
  xlab("Spol")