Daten & Packages laden

Laden Sie die folgenden Packages und Data-Frames:

library(tidyverse)
library(broom)
library(gridExtra)
library(lmerTest)
library(emmeans)
library(MuMIn)
library(afex)
sigmoid = function(x, k = 0, m = 1) {
  exp(m * x + k) / (1 + exp(m * x + k))
}

urla = "https://www.phonetik.uni-muenchen.de/studium_lehre/"
urlb = "lehrmaterialien/R_speech_processing/Rdf"
url = paste0(urla, urlb)
gr.df = read.table(file.path(url, "gr.df.txt"), 
                   stringsAsFactors = T)
gr.df = gr.df %>% 
  mutate(Alc = factor(Alc, levels=c("nein", "ja")))
gram.df = read.table(file.path(url, "gram.txt"), 
                   stringsAsFactors = T)
hruch.df = read.table(file.path(url, "hruchder.df.txt"), 
                   stringsAsFactors = T)
p.df = read.table(file.path(url, "preasp.txt"), 
                   stringsAsFactors = T)
l.df = read.table(file.path(url, "langdat.df.txt"), 
                   stringsAsFactors = T)
v.df = read.table(file.path(url, "vdatader.df.txt"), 
                   stringsAsFactors = T)
links = c(527, 542, 513, 502, 542, 535, 543, 508, 539, 546, 544, 533, 524, 523, 550, 526, 531, 512,549, 524)
rechts = c(524, 550, 545, 541, 524, 529, 549, 555, 554, 539, 552, 550, 555, 536, 554, 545, 523, 545, 525, 542)

Prüfen Sie mit einer Abbildung und statistischen Test, ob die Reaktionszeiten von dem Ohr beeinflusst werden.

# der Box ist fast komplett unter Null. Eventuell sig.
boxplot(links - rechts)

# oder
data.frame(rtdiff = links - rechts) %>%
  ggplot +
  aes(y = rtdiff) +
  geom_boxplot()

t.test(links-rechts)
## 
##  One Sample t-test
## 
## data:  links - rechts
## t = -2.6281, df = 19, p-value = 0.01656
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -20.119587  -2.280413
## sample estimates:
## mean of x 
##     -11.2

Die Reaktionszeit wurde signifikant (t[19] = 2.6281, p < 0.05) vom Ohr beeinflusst.

# Koeffiziente
km = 
gr.df %>%
glm(Alc ~ sps, family=binomial, .) %>%
  coef()

# Bild: die Proportionen sind eindeutig sigmoidal
gr.df %>%
  group_by(sps, Alc) %>%
  summarise(n = n()) %>%
  mutate(p = n/sum(n)) %>%
  filter(Alc == levels(Alc)[2]) %>%
  ggplot() +
  aes(y = p, x = sps) +
  ylab("Proportion 'ja' Antworten") +
  geom_point() +
  stat_function(fun = sigmoid, args=list(k = km[1], m = km[2]))
## `summarise()` has grouped output by 'sps'. You can override using the `.groups`
## argument.

# Der Umkirpppunkt
-km[1]/km[2]
## (Intercept) 
##    2.978555
# Proportion ja-Antworten bei einem sps-Wert von 1.8:
sigmoid(1.8, km[1], km[2])
##       sps 
## 0.2488193
# Test
gr.df %>%
glm(Alc ~ sps, family=binomial, .) %>%
anova(test='Chisq')
## Analysis of Deviance Table
## 
## Model: binomial, link: logit
## 
## Response: Alc
## 
## Terms added sequentially (first to last)
## 
## 
##      Df Deviance Resid. Df Resid. Dev  Pr(>Chi)    
## NULL                   808    1049.84              
## sps   1    238.9       807     810.94 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Die Entscheidungen wurden signifikant von der Alkoholstufe beeinflusst (\(X^2\)[1] = 238.9, p < 0.001).

# Class within und wie zu erwarten, Learner within
gram.df %>%
  mutate(Fac = interaction(Class, Learner)) %>%
  select(Vpn, Fac) %>%
  table()
##        Fac
## Vpn     N.early P.early V.early N.late P.late V.late
##   Vpn01       1       1       1      0      0      0
##   Vpn02       1       1       1      0      0      0
##   Vpn03       1       1       1      0      0      0
##   Vpn04       1       1       1      0      0      0
##   Vpn05       1       1       1      0      0      0
##   Vpn06       0       0       0      1      1      1
##   Vpn07       0       0       0      1      1      1
##   Vpn08       0       0       0      1      1      1
##   Vpn09       0       0       0      1      1      1
##   Vpn10       0       0       0      1      1      1
# schnellste Reaktionszeiten zu V; early eventuell
# nur langsamer in N. Eindeutig eine Interaktion.
gram.df %>%
  ggplot +
  aes(y = rt, x = Class, col = Learner) +
  geom_boxplot()

# 30 Beobachtungen und alle bedingten für einen ANOVA erfüllt:
gram.df %>%
aov_4(rt ~ Class * Learner + (Class|Vpn), . )
## Contrasts set to contr.sum for the following variables: Learner
## Anova Table (Type 3 tests)
## 
## Response: rt
##          Effect          df     MSE         F  ges p.value
## 1       Learner        1, 8 1319.39      2.16 .143    .180
## 2         Class 1.87, 14.95  434.30 89.73 *** .810   <.001
## 3 Learner:Class 1.87, 14.95  434.30 33.36 *** .614   <.001
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '+' 0.1 ' ' 1
## 
## Sphericity correction method: GG
# Post-hoc Test
gram.df %>%
aov_4(rt ~ Class * Learner + (Class|Vpn), . ) %>%
  emmeans(., ~ Class * Learner) %>%
  pairs(., simple="each", combine=T)
## Contrasts set to contr.sum for the following variables: Learner
##  Learner Class contrast     estimate   SE df t.ratio p.value
##  early   .     N - P          58.154 11.0  8   5.308  0.0065
##  early   .     N - V         179.410 13.3  8  13.487  <.0001
##  early   .     P - V         121.256 13.8  8   8.796  0.0002
##  late    .     N - P         -43.720 11.0  8  -3.991  0.0360
##  late    .     N - V          36.480 13.3  8   2.742  0.2282
##  late    .     P - V          80.200 13.8  8   5.818  0.0036
##  .       N     early - late  101.090 17.0  8   5.947  0.0031
##  .       P     early - late   -0.784 13.3  8  -0.059  1.0000
##  .       V     early - late  -41.840 19.6  8  -2.131  0.5914
## 
## P value adjustment: bonferroni method for 9 tests

Learner (F[1.87, 14.95] = 89.73, p < 0.001) und Class (F[1.87, 14.95] = 89.73, p < 0.001) hatten einen signifikanten Einfluss auf die Reaktionszeit, und es gab eine signifikante Interaktion zwischen diesen beiden Faktoren (F[1.87, 14.95] = 33.36, p < 0.001). Für frühe Lerner zeigten Post-hoc Tests signifikante Unterschiede zwischen allen syntaktischen Kategorien (N - P: p < 0.01; N - V, p < 0.001; P - V: p < 0.001). Für späte Lerner waren die Reaktionszeiten auf N schneller als auf P (p < 0.05); und die Reaktionszeiten schneller auf P als auf V (p < 0.01). Die Reaktionszeiten der frühen und späten Lerner unterschieden sich signifikant nur in Nomen (p < 0.01).

# VOT für jung > alt; Sevilla > Granada; eventuell eine Interaktion
hruch.df %>%
  ggplot +
  aes(y = VOT, x = Alter, col = Stadt) +
  geom_boxplot()

# beide Faktoren müssen wohl between sein im Bezug zu 
# Versuchsperson: (1|Vpn)
hruch.df %>%
  mutate(Fac = interaction(Stadt, Alter)) %>%
  select(Vpn, Fac) %>%
  table()
##          Fac
## Vpn       Granada.alt Sevilla.alt Granada.jung Sevilla.jung
##   ACM0011           0           8            0            0
##   ADG0021           0           0            0           18
##   AGR0009           0           0            0           14
##   ALR0012           0          16            0            0
##   AMU0049          17           0            0            0
##   ATO0020           0          15            0            0
##   AUN0059           0           0            0           11
##   BGG0008           0           0            0           15
##   BMM0047           0           0            4            0
##   CAR0005           0           0            0           15
##   CBD0026           0          14            0            0
##   CDT0024           0          15            0            0
##   CFL0032          17           0            0            0
##   CNJ0052          15           0            0            0
##   CSL0030          10           0            0            0
##   DBM0004           0           0            0           14
##   ELR0045           0           0           18            0
##   EPC0058           0           0            0           18
##   ERH0050           0           0           18            0
##   FGC0019           0           9            0            0
##   FGC0062           0          13            0            0
##   FMD0043           0           0           15            0
##   FPS0060           0          16            0            0
##   FRR0035           0           0           16            0
##   IPL0006           0          18            0            0
##   IRT0042           0           0           11            0
##   JGM0007           0           0            0           18
##   JGM0054           0           0           15            0
##   JHT0036           0           0           18            0
##   JMG0040          15           0            0            0
##   JML0039          13           0            0            0
##   JMP0002           0           0            0           11
##   JRF0002          17           0            0            0
##   JRS0033          18           0            0            0
##   LHS0003           0           0            0           18
##   LUR0016          16           0            0            0
##   MBC0034          10           0            0            0
##   MGB0055           0           0           16            0
##   MGR0016           0          16            0            0
##   MQG0003           9           0            0            0
##   NMT0014           0           0           15            0
##   NPG0010           0           0            0           18
##   NRB0044           0           0           18            0
##   PAM0022           0          18            0            0
##   PMY0005           0           0            0           14
##   POR0017           0          13            0            0
##   RHB0004           9           0            0            0
##   RXX0053           0           0           17            0
# beide Faktoren sind within im Bez. zu Wort:
# (Stadt + Alter|Wort)
hruch.df %>%
  mutate(Fac = interaction(Stadt, Alter)) %>%
  select(Wort, Fac) %>%
  table()
##          Fac
## Wort      Granada.alt Sevilla.alt Granada.jung Sevilla.jung
##   estaba           26          29           28           30
##   estado           26          26           25           32
##   estanco          25          28           27           27
##   etapa            32          32           36           33
##   pestana          28          26           32           30
##   retara           29          30           33           32
# Das Modell
hruch.df %>%
  lmer(VOT ~ Stadt * Alter + (1|Vpn) + (Stadt + Alter|Wort), .) %>%
  step()
## boundary (singular) fit: see help('isSingular')
## boundary (singular) fit: see help('isSingular')
## boundary (singular) fit: see help('isSingular')
## Backward reduced random-effect table:
## 
##                                 Eliminated npar  logLik    AIC     LRT Df
## <none>                                       12 -2587.7 5199.4           
## (1 | Vpn)                                0   11 -2696.4 5414.8 217.432  1
## Stadt in (Stadt + Alter | Wort)          0    9 -2634.6 5287.1  93.754  3
## Alter in (Stadt + Alter | Wort)          0    9 -2673.9 5365.8 172.412  3
##                                 Pr(>Chisq)    
## <none>                                        
## (1 | Vpn)                        < 2.2e-16 ***
## Stadt in (Stadt + Alter | Wort)  < 2.2e-16 ***
## Alter in (Stadt + Alter | Wort)  < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Backward reduced fixed-effect table:
## Degrees of freedom method: Satterthwaite 
## 
##             Eliminated Sum Sq Mean Sq NumDF  DenDF F value    Pr(>F)    
## Stadt:Alter          0 1768.2  1768.2     1 44.799  22.574 2.113e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Model found:
## VOT ~ Stadt * Alter + (1 | Vpn) + (Stadt + Alter | Wort)
# Eine Vereinfachung: Stadt und Wort interagieren nicht
hruch.df %>%
  lmer(VOT ~ Stadt * Alter + (1 | Vpn) + (Alter | Wort), .) %>%
  anova()
## Type III Analysis of Variance Table with Satterthwaite's method
##             Sum Sq Mean Sq NumDF  DenDF F value    Pr(>F)    
## Stadt       5861.9  5861.9     1 44.756  64.513 3.217e-10 ***
## Alter       1887.9  1887.9     1  7.374  20.777  0.002286 ** 
## Stadt:Alter 2040.2  2040.2     1 44.752  22.454 2.207e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Post-hoc Tests
hruch.df %>%
  lmer(VOT ~ Stadt * Alter + (1 | Vpn) + (Alter | Wort), .) %>%
  emmeans(., ~ Stadt * Alter) %>%
  pairs(., simple = "each", combine=T)
##  Alter Stadt   contrast          estimate   SE   df t.ratio p.value
##  alt   .       Granada - Sevilla    -6.89 2.96 44.2  -2.325  0.0989
##  jung  .       Granada - Sevilla   -26.70 2.95 43.5  -9.043  <.0001
##  .     Granada alt - jung          -11.26 5.10 10.5  -2.208  0.2023
##  .     Sevilla alt - jung          -31.07 5.09 10.4  -6.107  0.0004
## 
## Degrees-of-freedom method: kenward-roger 
## P value adjustment: bonferroni method for 4 tests

Stadt (F[1, 44.756] = 64.513, p < 0.001) und Alter (F[1, 7.374] = 20.777 p < 0.01) beeinflussten signifikant VOT, und es gab eine signifikante Interaktion zwischen diesen beiden Faktoren (F[1, 44.752] = 22.454, p < 0.001). Post-hoc Tests zeigten signifikante Unterschiede für jung zwischen den Städten (p < 0.001); für alt war VOT länger in Sevilla als in Granada aber nicht signifikant (p = 0.0989). Es gab signifikante Unterschiede zwischen den Altersgruppen in Sevilla (p < 0.001) aber nicht in Granada.

p.df %>%
  filter(city %in% c("bergamo", "parma") & cplace == "kk") %>%
  ggplot +
  aes(y = predur+clodur, x = vdur) +
  geom_point() + 
  geom_smooth(method = "lm", color = "blue")
## `geom_smooth()` using formula = 'y ~ x'

p.df %>%
  filter(city %in% c("bergamo", "parma") & cplace == "kk") %>%
  lm(predur+clodur ~ vdur, .) %>%
  summary()
## 
## Call:
## lm(formula = predur + clodur ~ vdur, data = .)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.081003 -0.026457  0.002204  0.026428  0.068444 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   0.1257     0.0132   9.519 1.13e-13 ***
## vdur          0.4275     0.1235   3.462 0.000986 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.03566 on 61 degrees of freedom
## Multiple R-squared:  0.1642, Adjusted R-squared:  0.1505 
## F-statistic: 11.98 on 1 and 61 DF,  p-value: 0.0009859

Es gibt eine signifikante lineare Beziehung (\(R^2\) = 0.1642, F[1, 61] = 11.98, p < 0.001) zwischen den beiden Variablen.

# Es gibt kaum einen Unterschied zwischen L1 und L2
# eventuell mehr richtig in 'quiet' als in 'noise'
# sicherlich eine Interaktion: L1 > L2 in 'quiet' aber nicht
# in 'noise'.
l.df %>%
  ggplot+
  aes(x = Lang, fill = Answer) +
  geom_bar(position="fill") +
  facet_wrap(~Condition)

# Condition sig und eine Interaktion
l.df %>%
  glm(Answer ~ Lang * Condition, family = binomial, .) %>%
  anova(test = "Chisq")
## Analysis of Deviance Table
## 
## Model: binomial, link: logit
## 
## Response: Answer
## 
## Terms added sequentially (first to last)
## 
## 
##                Df Deviance Resid. Df Resid. Dev Pr(>Chi)   
## NULL                             599     798.81            
## Lang            1   2.9353       598     795.87 0.086662 . 
## Condition       1   8.5841       597     787.29 0.003391 **
## Lang:Condition  1   5.3074       596     781.98 0.021235 * 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Post-hoc Tests
l.df %>%
  glm(Answer ~ Lang * Condition, family = binomial, .) %>%
  emmeans(., ~ Lang * Condition) %>%
  pairs(., simple = "each", combine=T)
##  Condition Lang contrast      estimate    SE  df z.ratio p.value
##  noise     .    L1 - L2          0.289 0.319 Inf   0.904  1.0000
##  quiet     .    L1 - L2         -0.621 0.234 Inf  -2.651  0.0321
##  .         L1   noise - quiet    0.788 0.213 Inf   3.708  0.0008
##  .         L2   noise - quiet   -0.122 0.334 Inf  -0.364  1.0000
## 
## Results are given on the log odds ratio (not the response) scale. 
## P value adjustment: bonferroni method for 4 tests

Die Richtigkeit der Antworten wurde von Condition signifikant (\(X^2\)[1] = 8.5841, p < 0.01) beinflusst, und es gab eine signifikante (\(X^2\)[1] = 5.3074, p < 0.05) Interaktion zwischen Umgebung und Sprache. Post-hoc Tests zeigten signifikante Unterschiede zwischen L1 und L2 im Labor (p < 0.05) aber nicht im Lärm. Es gab ausschließlich signifikante Unterschiede zwischen Labor und Lärm unter den L1-Versuchspersonen (p < 0.001).

  1. Y von der Gespanntheit beeinflusst wird.
  2. es eine Beziehung zwischen Y und X gibt.
  3. X und Gespanntheit miteinander interagieren.

Sie können hier Befehle eingeben, und danach 1-3 kurz (jeweils eine Zeile) begründen.

# 1.
v.df %>%
  ggplot+
  aes(y = Y, x = X) +
  geom_point() +
  facet_wrap(~Tense)

# 2.
v.df %>%
  ggplot+
  aes(y = Y, x = X) +
  geom_point() 

Kurze Begründung hier:

  1. Einfluss von der Gespanntheit: die Y-Werte für gespannt sind höher als für ungespannt.

  2. Wie aus dem zweiten Bild zu sehen: kein eindeutiger Einfluss von X auf Y.

  3. Wie aus dem ersten Bild zu sehen, eine Interaktion: in ungespannt ist die Y~X Steigung positiv, und in gespannt ist sie Steigung negativ.