12 – Lösungen

Statistische Datenanalyse mit R

Autor

Clemens Brunner

Veröffentlicht

19. Juni 2023

Übung 1

Größe

library(dplyr)

t.test(height ~ gender, data=starwars, alternative="less")

    Welch Two Sample t-test

data:  height by gender
t = -1.5596, df = 37.315, p-value = 0.06365
alternative hypothesis: true difference in means between group feminine and group masculine is less than 0
95 percent confidence interval:
      -Inf 0.9641724
sample estimates:
 mean in group feminine mean in group masculine 
               164.6875                176.5161 

Weibliche Charaktere sind nicht signifikant kleiner als männliche (\(t=-1.56\), \(p = .064\)).

Gewicht

t.test(mass ~ gender, data=starwars, alternative="less")

    Welch Two Sample t-test

data:  mass by gender
t = -1.936, df = 49.094, p-value = 0.02932
alternative hypothesis: true difference in means between group feminine and group masculine is less than 0
95 percent confidence interval:
      -Inf -6.897942
sample estimates:
 mean in group feminine mean in group masculine 
               54.68889               106.14694 

Weibliche Charaktere sind signifikant leichter als männliche (\(t=-1.94\), \(p = .029\)).

Übung 2

library(palmerpenguins)

with(
    subset(penguins, species == "Adelie" | species == "Chinstrap"),
    t.test(bill_length_mm ~ species)
)

    Welch Two Sample t-test

data:  bill_length_mm by species
t = -21.865, df = 106.97, p-value < 2.2e-16
alternative hypothesis: true difference in means between group Adelie and group Chinstrap is not equal to 0
95 percent confidence interval:
 -10.952948  -9.131917
sample estimates:
   mean in group Adelie mean in group Chinstrap 
               38.79139                48.83382 
with(
    subset(penguins, species == "Adelie" | species == "Gentoo"),
    t.test(bill_length_mm ~ species)
)

    Welch Two Sample t-test

data:  bill_length_mm by species
t = -24.725, df = 242.58, p-value < 2.2e-16
alternative hypothesis: true difference in means between group Adelie and group Gentoo is not equal to 0
95 percent confidence interval:
 -9.407672 -8.019303
sample estimates:
mean in group Adelie mean in group Gentoo 
            38.79139             47.50488 
with(
    subset(penguins, species == "Gentoo" | species == "Chinstrap"),
    t.test(bill_length_mm ~ species)
)

    Welch Two Sample t-test

data:  bill_length_mm by species
t = 2.706, df = 129.22, p-value = 0.00773
alternative hypothesis: true difference in means between group Chinstrap and group Gentoo is not equal to 0
95 percent confidence interval:
 0.3572698 2.3006212
sample estimates:
mean in group Chinstrap    mean in group Gentoo 
               48.83382                47.50488 
with(
    subset(penguins, species == "Adelie" | species == "Chinstrap"),
    t.test(bill_depth_mm ~ species)
)

    Welch Two Sample t-test

data:  bill_depth_mm by species
t = -0.43771, df = 137.75, p-value = 0.6623
alternative hypothesis: true difference in means between group Adelie and group Chinstrap is not equal to 0
95 percent confidence interval:
 -0.4095657  0.2611044
sample estimates:
   mean in group Adelie mean in group Chinstrap 
               18.34636                18.42059 
with(
    subset(penguins, species == "Adelie" | species == "Gentoo"),
    t.test(bill_depth_mm ~ species)
)

    Welch Two Sample t-test

data:  bill_depth_mm by species
t = 25.337, df = 271.98, p-value < 2.2e-16
alternative hypothesis: true difference in means between group Adelie and group Gentoo is not equal to 0
95 percent confidence interval:
 3.102837 3.625651
sample estimates:
mean in group Adelie mean in group Gentoo 
            18.34636             14.98211 
with(
    subset(penguins, species == "Gentoo" | species == "Chinstrap"),
    t.test(bill_depth_mm ~ species)
)

    Welch Two Sample t-test

data:  bill_depth_mm by species
t = 21.01, df = 122.3, p-value < 2.2e-16
alternative hypothesis: true difference in means between group Chinstrap and group Gentoo is not equal to 0
95 percent confidence interval:
 3.114497 3.762452
sample estimates:
mean in group Chinstrap    mean in group Gentoo 
               18.42059                14.98211 
pairwise.t.test(penguins$bill_length_mm, penguins$species)

    Pairwise comparisons using t tests with pooled SD 

data:  penguins$bill_length_mm and penguins$species 

          Adelie Chinstrap
Chinstrap <2e-16 -        
Gentoo    <2e-16 0.0032   

P value adjustment method: holm 
pairwise.t.test(penguins$bill_depth_mm, penguins$species)

    Pairwise comparisons using t tests with pooled SD 

data:  penguins$bill_depth_mm and penguins$species 

          Adelie Chinstrap
Chinstrap 0.65   -        
Gentoo    <2e-16 <2e-16   

P value adjustment method: holm 

Übung 3

t.test(extra ~ group, data=sleep, paired=TRUE)

    Paired t-test

data:  extra by group
t = -4.0621, df = 9, p-value = 0.002833
alternative hypothesis: true mean difference is not equal to 0
95 percent confidence interval:
 -2.4598858 -0.7001142
sample estimates:
mean difference 
          -1.58 

Die mittlere Differenz beträgt −1.58, das 95%-Konfidenzintervall erstreckt sich von −2.46 bis −0.7.