
fr = read.table(file.path(pfadu, "franken.txt"))
# Tabelle
tab = with(fr, table(Alter, Correct))
# Proportionen berechnen
p = prop.table(tab, 1)
# Barchart
barchart(p, auto.key=T, horizontal = F)
# Test
g = glm(Correct ~ Alter, binomial, data = fr)
summary(g)
# Correct (ob richtig/falsch) wurde signifikant vom
# Alter beeinflusst (z = 3.1, p < 0.01)

###################################################################

a.df = read.table(file.path(pfadu, "adaten.df.txt"))
 head(a.df)
 levels(a.df$V)
# [1] "a"  "a:"
# Erfolg
P = a.df$V == "a:"
# Misserfolg
 Q = !P
# Summierung davon
 a.lm = aggregate(cbind(P, Q) ~ F1, sum, data = a.df)
# Proportionen
 p = with(a.lm, P/(P+Q))
 a.lm = cbind(a.lm, p)
# Proportion /a:/ Antworten vs. F1
ylim = c(0, 1); xlim = c(100, 2000)
plot(p ~ F1, data = a.lm,ylab = "Proportion /a:/ Antworten", xlim = xlim, ylim = ylim)
# Statistik
 a.glm = glm(V ~ F1, binomial, data = a.df)
 summary(a.glm)
# Vokal (ob /a:/ oder /a/) wird vom F1 signifikant beeinflusst
# (z = 3.6, p < 0.001)

# Koeffiziente der Sigmoid
 cf = coef(a.glm)
# Intercept
 k = cf[1]
# Steigung
 m = cf[2]
# Sigmoid überlagern
 sig(k, m, lwd=2, col = "gold")

# Vektor der Urteile
fric = c("f", "x", "f", "f", "x", "f", "f", "f", "f", "f", "f", "x", "f", "x", "x", "f", "x", "f", "x", "f")
# Vektor der Muttersprache der Versuchspersonen
sprache = c(rep("NL", 10), rep("D", 10))
# Data-Frame davon
f.df = data.frame(fric, sprache)
# Abbildung der Proportionen
tab = with(f.df, table(sprache, fric))
p = prop.table(tab, 1)
barchart(p, auto.key=T, horizontal=F)
# Statistischer Test
f.glm = glm(fric ~ sprache, binomial, data = f.df)
summary(f.glm)
# Die Wahl ob /f/ oder /x/ wurde nicht von der Sprache
# beeinflusst (wahrscheinlich aufgrund von zu wenig Stichproben).


sagt = read.table(file.path(pfadu, "sagtp.df.txt"))
head(sagt)
levels(sagt$Urteil)
P = sagt$Urteil == "a:"
Q = !P
sagt.m = aggregate(cbind(P, Q) ~ Stimulus, sum, data = sagt)
p = with(sagt.m, P/(P+Q))
sagt.m = cbind(sagt.m, p)
plot(p ~ Stimulus, data = sagt.m)
sagt.glm = glm(Urteil ~ Stimulus, binomial, data = sagt)
summary(sagt.glm)
cf = coef(sagt.glm)
k = cf[1]
m = cf[2]
sig(k, m, col="blue")
abline(v = -k/m)


lateral = read.table(file.path(pfadu, "lateral.txt"))
# Der Data-Frame zeigt wie oft Sprecher aus drei Dialektregionen einen
# silbenfinalen /l/ vokalisiert (J) haben oder nicht (N).
# Wird die Vokalisierung vom Dialekt beeinflusst?

lateral = read.table(file.path(pfadu, "lateral.txt"))
tab = with(lateral, table(Dialekt, Lateral))
p = prop.table(tab, 1)
barchart(p, auto.key=T, horizontal=F)
lat.glm = glm(Lateral ~ Dialekt, binomial, data = lateral)
summary(lat.glm)
# Prüfen ob der Faktor Dialekt einen signifikanten Einfluss hat
lat.ohne = glm(Lateral ~ 1, binomial, data = lateral)
anova(lat.glm, lat.ohne, test="LRT")


# Für den Data-Frame preasp
preasp = read.table(file.path(pfadu, "preasp.txt"))
# inwiefern wird
# die Verteilung von ±preasp (ob Pre-aspiration vorkam oder nicht)
# von dem davor kommenden Vokal (vtype) beeinflusst?
tab = with(preasp, table(vtype, Pre))
p = prop.table(tab, 1)
barchart(p, auto.key=T, horizontal=F)
preasp.glm = glm(Pre ~ vtype, binomial, data = preasp)
summary(preasp.glm)
preasp.ohne = glm(Pre ~ 1, binomial, data = preasp)
anova(preasp.glm, preasp.ohne, test="Chisq")






