nw = read.table(file.path(pfadu, "Nicole_grafik.txt"), header=T) # Daten von Nicole Weidinger. # Inwiefern wird representation (BPO vs IO) # vom Alter beeinflusst? nw = read.table(file.path(pfad, "Nicole_grafik.txt"), header=T) # convert to long-format. Separate BPO, IO temp = nw$representation == "BPO" nw.b = nw[temp,] nw.o = nw[!temp,] # check they are in the correct order all(with(nw.b, interaction(vpn, age)) == with(nw.o, interaction(vpn, age))) # then proceed with long-format conversion vpn.b = with(nw.b, rep(as.character(vpn), freq)) age.b = with(nw.b, rep(as.character(age), freq)) darst.b = rep("BPO", sum(nw.b$freq)) vpn.o = with(nw.o, rep(as.character(vpn), freq)) age.o = with(nw.o, rep(as.character(age), freq)) darst.o = with(nw.o, rep("IO", sum(freq))) vpn = c(vpn.b, vpn.o) age = c(age.b, age.o) darst = c(darst.b, darst.o) # So hätte der Data-Frame aussehen sollen d.df = data.frame(D = factor(darst), Age = factor(age), Vpn = factor(vpn)) # Bild malen tab = with(d.df, table(Age, D)) prop = prop.table(tab, 1) barchart(prop, auto.key=T, horizontal=F) # BPO ist häufiger als IO für 5-jährige # Statistik dazu o = lmer(D ~ Age + (1|Vpn), family = binomial, data = d.df) # Hat Alter einen Einfluss auf BPO/IO Proportionen? o2 = update(o, ~ . -Age) anova(o, o2) # Alter hat einen Einfluss auf die BPO/IO Verteilung # X^2[1] = 30.7, p < 0.001