Analyse der Daten unseres Experiments

Start der Analyse

Pakete laden und installieren

Hilfefunktion für Cousineau Morey

cm.ci <- function(data.frame, conf.level = 0.95, difference = TRUE) {
  #cousineau-morey within-subject CIs
  k = ncol(data.frame)
  if (difference == TRUE) 
    diff.factor = 2^0.5/2
  else diff.factor = 1
  n <- nrow(data.frame)
  df.stack <- stack(data.frame)
  index <- rep(1:n, k)
  p.means <- tapply(df.stack$values, index, mean)
  norm.df <- data.frame - p.means + (sum(data.frame)/(n * k))
  t.mat <- matrix(, k, 1)
  mean.mat <- matrix(, k, 1)
  for (i in 1:k) t.mat[i, ] <- t.test(norm.df[i])$statistic[1]
  for (i in 1:k) mean.mat[i, ] <- mean(as.matrix(norm.df[i]))
  c.factor <- (k/(k - 1))^0.5
  moe.mat <- mean.mat/t.mat * qt(1 - (1 - conf.level)/2, n - 1) * c.factor * 
    diff.factor
  ci.mat <- matrix(, k, 2)
  dimnames(ci.mat) <- list(names(data.frame), c("lower", "upper"))
  for (i in 1:k) {
    ci.mat[i, 1] <- mean.mat[i] - moe.mat[i]
    ci.mat[i, 2] <- mean.mat[i] + moe.mat[i]
  }
  ci.mat
}

Daten einlesen

d1 <- read.table("vilo3e598877c1b5cb023a2033d61f461c92a6fadeb0.dat")
d1$vp <- 1
idxrm <- 1:10
d1 <- d1[-idxrm,]

d2 <- read.table("vilo8675e27761faabd63ce91b8098b9385af431d3b5.dat")
d2$vp <- 2
idxrm <- 1:10
d2 <- d2[-idxrm,]

d3 <- read.table("viloc5f3f9ae81f24b85c59ec854301979c2dc92ffc4.dat")
d3$vp <- 3
idxrm <- 1:10
d3 <- d3[-idxrm,]

d4 <- read.table("vilo78bda3a0186f9ce19144fb0178d7570a4c77757c.dat")
d4$vp <- 4
idxrm <- 1:10
d4 <- d4[-idxrm,]

d5 <- read.table("vilo9ee5d682a96850b9e1340acfce2fee3fe85d29f3.dat")
d5$vp <- 5
idxrm <- 1:10
d5 <- d5[-idxrm,]

d6 <- read.table("vilo49abacc85de256c6b13dfc962df0011d97c7a3f5.dat")
d6$vp <- 6
idxrm <- 1:10
d6 <- d6[-idxrm,]

d7 <- read.table("vilo494bf4424c551c08fe8b3416071ca0534d357505.dat")
d7$vp <- 7
idxrm <- 1:10
d7 <- d7[-idxrm,]

d8 <- read.table("vilodfcd6ff7f499b4666e3d281fd2f834710c98dd37.dat")
d8$vp <- 8
idxrm <- 1:10
d8 <- d8[-idxrm,]

d9 <- read.table("vilocd83c4882d0c954bb3fb766a69c15a4434081470.dat")
d9$vp <- 9
idxrm <- 1:10
d9 <- d9[-idxrm,]

d10 <- read.table("vilob139c3d8c0783d70a777a3187330f782932e5423.dat")
d10$vp <- 10
idxrm <- 1:10
d10 <- d10[-idxrm,]

Daten kombinieren und kontrollieren

dall <- rbind(d1,d2,d3,d4,d5,d6,d7,d8,d9,d10) 
View(dall)
colnames(dall) <- c("block","trial","posx","posy",
                    "target_location","mask_wo","type_emotion",
                    "orientation","tStart",
                    "tMemOn","tMemOff","tProbe",
                    "tResp","Response",
                    "RT","vp")

Die Antworten herausziehen

dall$answer <- dall$orientation*dall$Response
dall$answer <- ifelse(dall$answer<0,0,1)

data <- dall[,c("vp","block","mask_wo","type_emotion","RT","answer")]

data$vp <- as.factor(data$vp)
data$mask_wo <-  as.factor(data$mask_wo)
levels(data$mask_wo) <- c("Ohne Distraktor","Mit Distraktor")
data$type_emotion <-  as.factor(data$type_emotion)
levels(data$type_emotion) <- c("Neutrale Emotion","Positive Emotion")
head(data)
##    vp block         mask_wo     type_emotion   RT answer
## 11  1     1  Mit Distraktor Neutrale Emotion 1399      1
## 12  1     1 Ohne Distraktor Positive Emotion 2120      1
## 13  1     1  Mit Distraktor Neutrale Emotion 2149      1
## 14  1     1  Mit Distraktor Positive Emotion 1505      1
## 15  1     1  Mit Distraktor Neutrale Emotion 1127      0
## 16  1     1 Ohne Distraktor Neutrale Emotion 2556      1
table(data$vp)
## 
##   1   2   3   4   5   6   7   8   9  10 
## 250 250 250 250 250 250 250 250 250 250

Erster Plot

Versuchspersonen Mittelwerte finden

m1 <- melt(data,id=c("type_emotion","mask_wo","vp"),measure=c("answer"))
c1 <- cast(m1,type_emotion+ mask_wo +vp ~ variable,mean)

Bedingungsmittelwerte finden

m2 <- melt(c1,id=c("type_emotion","mask_wo"),measure=c("answer"))
c2 <- cast(m2,type_emotion+mask_wo ~ variable,mean)

Ersten Plot generieren

# start plotting psychometric curves
fig1 <- ggplot(c2,aes(x=type_emotion,y=answer,color=mask_wo))+geom_point()+theme_bw()#+geom_smooth(method="loess",se=FALSE)+
fig1 <- fig1 + scale_colour_manual(values=c("red","blue"))
fig1 <- fig1 + geom_line()
fig1 <- fig1 + scale_fill_manual(values=c("red","blue"))
fig1 <- fig1 + scale_y_continuous(limits=c(0.5,1),breaks=c(0.5,0.75,1),expand = expansion(mult=0))
fig1 <- fig1 + ylab("Proportion launches") + xlab("Type Emotion")
#fig1 <- fig1 + theme(legend.position="bottom", legend.box = "horizontal",legend.title = element_blank())

pdf("Figure1.pdf", width = (17.7*(1/2))/2.54, height = (17.7*(1/2))/2.54,useDingbats=FALSE)
print(fig1)
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?

ANOVA durchführen

Mittelwerte pro Versuchsperson finden

m3 <- melt(data,id=c("type_emotion","mask_wo","vp"),measure=c("answer"))
c3 <- cast(m3,type_emotion + mask_wo +vp ~ variable,mean)

ANOVA für Personenmittelwerte durchführen

c3$vp <- as.factor(c3$vp)
aov.m              <- aov(answer ~ type_emotion*mask_wo + Error(vp/(type_emotion*mask_wo)),data=c3)
summary(aov.m)
## 
## Error: vp
##           Df Sum Sq Mean Sq F value Pr(>F)
## Residuals  9  0.467 0.05188               
## 
## Error: vp:type_emotion
##              Df  Sum Sq Mean Sq F value Pr(>F)
## type_emotion  1 0.00911 0.00911   2.552  0.145
## Residuals     9 0.03213 0.00357               
## 
## Error: vp:mask_wo
##           Df  Sum Sq Mean Sq F value  Pr(>F)   
## mask_wo    1 0.03717 0.03717   12.83 0.00591 **
## Residuals  9 0.02606 0.00290                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Error: vp:type_emotion:mask_wo
##                      Df  Sum Sq  Mean Sq F value Pr(>F)
## type_emotion:mask_wo  1 0.00006 0.000057   0.014  0.907
## Residuals             9 0.03567 0.003963

Zweiter Plot

Versuchspersonen Mittelwerte finden

m4 <- melt(c3,id=c("type_emotion","mask_wo"),measure=c("answer"))
c4 <- cast(m4,type_emotion+mask_wo ~ variable,mean)

Konfidenzintervalle hinzufügen

c3$cond <-  as.factor(paste(as.integer(c3$type_emotion),as.integer(c3$mask_wo)))
c3_reduced <- c3[,c("answer","cond")]
c3_reduced <- unstack(c3_reduced)

ci_cm <- cm.ci(data.frame=c3_reduced,conf.level=2*(pnorm(1.96,0,1)-0.5),difference=TRUE) # 1sem or 1.96 sem

c4$upper <- ci_cm[,2]
c4$lower <- ci_cm[,1]

labels <- c("Neutrale Emotion", "Positive Emotion")

fig2 <- ggplot(c4,aes(x=type_emotion,y=answer,color=mask_wo,ymin=lower,ymax=upper))+theme_bw() +
  geom_point()+geom_linerange(show.legend = FALSE) +
  scale_colour_manual(values=c("red","blue")) +
  scale_fill_manual(values=c("red","blue")) +
  scale_y_continuous(limits=c(0.5,1.0),breaks=c(0.5,0.6,0.7,0.8,0.9,1.0),expand = expand_scale(mult=0)) +
  ylab("Anteil der richtigen Antworten") + xlab ("") +
  labs(color = "Präsentation eines Distraktors") +
  geom_line(aes(group = mask_wo), show.legend = FALSE) +
  theme(legend.text = element_text(colour = "black")) +
  theme(legend.position = c(0.8, 0.12),  legend.background = element_rect(fill = "white", color = "black")) +
  scale_x_discrete(label = labels) +
  theme(axis.text.x = element_text(angle = 0, hjust = 0.5, size = 12),  # Increased axis label size
        axis.text.y = element_text(size = 12))
## Warning: `expand_scale()` was deprecated in ggplot2 3.3.0.
## ℹ Please use `expansion()` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
fig2

pdf("Interaktionsplot_Distraktoren.pdf", width = (17.7)/2.54, height = (17.7)/2.54,useDingbats=FALSE)
print(fig2)

Reaktionszeitenplot generieren

Erstellen eines neuen Datensatzes mit den Daten

data <- data.frame(
  vp = c(5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24),
  block = rep(1, 20),
  mask_wo = c("Mit Distraktor", "Ohne Distraktor", "Ohne Distraktor", "Ohne Distraktor", "Mit Distraktor",
              "Mit Distraktor", "Mit Distraktor", "Ohne Distraktor", "Mit Distraktor", "Mit Distraktor",
              "Ohne Distraktor", "Ohne Distraktor", "Mit Distraktor", "Mit Distraktor", "Ohne Distraktor",
              "Mit Distraktor", "Ohne Distraktor", "Ohne Distraktor", "Mit Distraktor", "Mit Distraktor"),
  type_emotion = c("Neutrale Emotion", "Neutrale Emotion", "Positive Emotion", "Neutrale Emotion", "Neutrale Emotion",
                   "Positive Emotion", "Neutrale Emotion", "Positive Emotion", "Neutrale Emotion", "Positive Emotion",
                   "Neutrale Emotion", "Positive Emotion", "Neutrale Emotion", "Positive Emotion", "Positive Emotion",
                   "Neutrale Emotion", "Neutrale Emotion", "Positive Emotion", "Positive Emotion", "Neutrale Emotion"),
  RT = c(3711, 1834, 1154, 758, 1976, 2482, 1399, 2120, 2149, 1505, 1127, 2556, 2288, 2478, 1755, 2006, 3928, 4174, 3401, 1803),
  answer = c(0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0)
)

Convert factors

data$vp <- as.factor(data$vp)
data$mask_wo <- as.factor(data$mask_wo)
levels(data$mask_wo) <- c("Mit Distraktor", "Ohne Distraktor")
data$type_emotion <- as.factor(data$type_emotion)

Reaktionsplot

reaction_time_plot <- ggplot(data, aes(x = type_emotion, y = RT, color = mask_wo)) +
  geom_boxplot(position = position_dodge(width = 0.6), outlier.shape = NA, width = 0.5) +  # Adjusted width for boxplots
  scale_y_continuous(limits = c(0, max(data$RT) + 500), breaks = seq(0, max(data$RT) + 500, by = 500)) +  # Adjusted y-axis limits
  labs(x = " ",
       y = "Reaktionszeit",
       color = "Präsentation eines Distraktors") +
  scale_colour_manual(values=c("red","blue")) +
  theme_bw() +
  theme(axis.text.x = element_text(angle = 0, hjust = 0.5, size = 12),  # Increased axis label size
        axis.text.y = element_text(size = 12),  # Increased y-axis label size
        legend.position = c(0.8, 0.88),  # Legende oben rechts
        legend.box.background = element_rect(color = "black"),
        # Set legend box properties
        legend.key.size = unit(1, "cm"),
        legend.background = element_rect(fill = "white", color = "black"))  # Set legend key size

Den Plot anzeigen oder speichern

print(reaction_time_plot)

pdf("Reaktionszeiten.pdf", width = (17.7)/2.54, height = (17.7)/2.54,useDingbats=FALSE)
print(reaction_time_plot)