# Frage 2
plot(rating ~ complaints, data = attitude)
o = lm(rating ~ complaints, data = attitude)
shapiro.test(resid(o))
# geht nicht
# W = 0.919, p-value = 0.02519

# Frage 3
werte = read.table(file.path(pfadu, "frage2reg.txt"))
names(werte) = c("Jahr", "Formant")
plot(Formant ~ Jahr, data = werte)

o = lm(Formant ~ Jahr, data = werte)
shapiro.test(resid(o))
plot(resid(o))
acf(resid(o))
plot(Formant ~ Jahr, data = werte)
abline(o)
summary(o)
# Es gibt eine signifikante lineare Beziehung zwischen F2-F1 und Jahr
# (R^2 = 0.93, F[1,8] = 107.2, p < 0.001).

# Frage 4 (t-test)
a = read.table(file.path(pfadu, "frage4reg.txt"), header=T)
a.jung = a[,1]
a.alt = a[,2]
w = c(a.jung, a.alt)
Alter = c(rep("j", length(a.jung)), rep("a", length(a.alt)))
Vpn = paste("S", 1:length(w), sep="")
d = data.frame(w, Alter = factor(Alter), Vpn = factor(Vpn))
boxplot(w ~ Alter, data = d)
t.test(w ~ Alter, data = d)
# Alter hat einen signifikanten Einlfuss auf die Reaktionszeit (t[18.0] = 4.3, p < 0.001)

# Frage 5 (t-test)
werte = c(137.0,   131.2,   127.1,   123.4,   119.2,   114.6,   109.6,   104.5,   99.4,    95.3)
jahr = 1987:1996
plot(jahr, werte)
o = lm(werte ~ jahr)
shapiro.test(resid(o))
plot(resid(o))
acf(resid(o))
plot(jahr, werte)
abline(o)
summary(o)
# Es gibt eine lineare Beziehung zwischen f0 und Jahr (F[1,8] = 4276, p < 0.001)
predict(o, data.frame(jahr = 2000))
# 77.13818 

# Frage 6 (gepaarter t-test)
x = read.table(file.path(pfadu, "frage6reg.txt"), header=T)
d = x$davor - x$danach
boxplot(d)
abline(h=0, lty=2)
t.test(d)
# Die Wahrnehmung hat einen signifikanten Einfluss auf F2 (t[19] = 3.2, p < 0.01)

# Frage 7
dbwerte = read.table(file.path(pfadu, "dba.txt"))
head(dbwerte)
plot(dB ~ Dauer, data = dbwerte)
db.lm = lm(dB ~ Dauer, data = dbwerte)
shapiro.test(resid(db.lm))
plot(resid(db.lm))
acf(resid(db.lm))
plot(dB ~ Dauer, data = dbwerte)
abline(db.lm)
summary(db.lm)
# Es gibt eine signifikante linear Beziehung zwischen der Intensität
# und der Dauer (R^2 = 0.41, F[1,13] = 9.0, p < 0.05)

# Frage 8 (t-test)
w = c(26, 15, 8, 44, 26, 13, 38, 24, 17, 29)
m = c(20, 4, 9, 36, 20, 3, 25, 10, 6, 14)
int = c(w, m)
lab = c(rep("w", length(w)), rep("m", length(m)))
Vpn = paste("S", 1:length(int), sep="")
i.df = data.frame(int, G = factor(lab), Vpn = factor(Vpn))
boxplot(int ~ G, data = i.df)
t.test(int ~ G, data = i.df)
# Geschlecht hat keinen signifikanten Einfluss auf die Intensität






