Commit 1b118eb9 authored by Amit Goldenberg's avatar Amit Goldenberg

a few visual additions

parent a91e927f
......@@ -5,14 +5,10 @@ date: "October 21, 2016"
output: html_document
---
```{r packages, include=FALSE}
library (ggplot2) ; library ('lme4'); library ('lmerTest'); library ('plyr'); library ('dplyr'); library ('psych'); library ('car'); library("tidyr");
library('lmerTest'); library('Rmisc'); library('ez') ; library ("visreg")
library('coefplot');
if (!require("pacman")) install.packages("pacman")
pacman::p_load("ggplot2","lme4",'lmerTest','plyr','dplyr','psych','car',"tidyr",'Rmisc','ez',"visreg",'GGally','coefplot')
pl1way <- function(dat,y,x) {
pld <- summarySEwithin(dat,y,withinvars = x, idvar = "subject")
......@@ -27,20 +23,15 @@ pl1way <- function(dat,y,x) {
```
```{r get file, include=FALSE}
setwd("C:/Users/Amit/Dropbox/Research/emotional conformity-non conformity/motivated_contation_EEG_2017/Results")
```{r get and convert the file, include=FALSE}
# setwd("C:/Users/Amit/Dropbox/Research/emotional conformity-non conformity/motivated_contation_EEG_2017/Results")
setwd("C:/Users/ro/OneDrive - Tartu likool/Teadus/REGULATION/16 motivated contagion")
d <- read.csv("eeg_data_motivated_contagion.csv")
head(d)
#d = subset (d, condition != "none")
#ds = subset (d, phase == "social")
```
### Andero's stuff ####
```{r convert the file ,include=FALSE}
# separate phases
a <- d[d$phase=="indiv",]
......@@ -49,59 +40,147 @@ b <- d[d$phase=="social",]
# make a wide format with each picture in a separate row and the phases in separate columns
D3 <- merge(a[,c("subject", "photo", "order", "rt", "P3", "LPP", "SLW")],b,by=c("subject", "photo"))
head(D3)
colnames(D3) <- gsub(".x", ".indiv", colnames(D3), fixed =T)
colnames(D3) <- gsub(".y", ".social", colnames(D3), fixed =T)
# remove "none"" and fix comparison levels
D3 <- D3[D3$condition!="none",]
D3$condition <- factor(as.character(D3$condition), levels = c("same", "low", "high"))
D3$photoType <- relevel(D3$photoType,"ntr")
# add phase differences
D3$P3.dif = D3$P3.social-D3$P3.indiv
D3$LPP.dif = D3$LPP.social-D3$LPP.indiv
D3$SLW.dif = D3$SLW.social-D3$SLW.indiv
# add difference between group and individual ratings
D3$rateDif <- D3$grate - D3$rate
head(D3)
# DESCRIPTIVES
table(D3$subject, D3$condition)
ggplot(d, aes(P3)) + geom_density()
ggplot(d, aes(LPP)) + geom_density()
ggplot(d, aes(SLW)) + geom_density()
```
### A couple of descriptive pictures
```{r descriptives, warning=F}
# frequency table of trials
table(D3$subject, D3$condition, D3$photoType)
# independent variables
ggpairs(D3[,c("rate","grate", "rateDif")])
# dependent variables
ggpairs(d[,c("P3","LPP", "SLW")])
# differences
ggpairs(D3[,c("P3.indiv","P3.social", "P3.dif")])
ggpairs(D3[,c("LPP.indiv","LPP.social", "LPP.dif")])
ggpairs(D3[,c("SLW.indiv","SLW.social", "SLW.dif")])
# Do we need to control for order? No
cor(d[,c("P3","LPP", "SLW", "rate", "grate")],d$order, use="pairwise.complete.obs")
```
```{r analysis p3}
I've been thinking about some of the researcher degrees of freedom we have in constructing the models. Here's a summary:
pl1way(D3,"P3.indiv","photoType")
pl1way(D3,"LPP.indiv","photoType")
pl1way(D3,"LPP.indiv","photoType")
### 1) We have a choice between taking a "brain-centric" and "task-centric" approach
Brain-centric would look somethink like this: P3.social ~ P3.indiv + condition + (1|subject)
Task-centric something like this: P3.social ~ photoType + condition + (1|subject) + (1|photo)
# continuous model
summary(fit <- lmer(SLW.social ~ SLW.indiv + rate*grate + (1|subject) + (1|photo), data = D3))
Both approaches aim to isolate brain responses to the social manipulation.
coefplot(fit)
visreg(fit, xvar = "grate", by = "rate")
The brain-centric model assumes that the first presentation response (P3.indiv term) captures all brain responses to both the affective and nonaffective aspects of the stimuli. In this model, we shouldn't include other stuff like individual ratings, photoType, or photo random factor, because processes triggered by all these things are already contained in the P3.indiv variance.
# categorical model
summary(fit <- lmer(SLW.social ~ SLW.indiv + photoType*condition + (1|subject) + (1|photo), data = D3))
The alternative is of course to use what we manipulated to regress out brain variance not related to the social manipulation. If we do that, we shouldn't any more include the first phase EEG, because we then run the risk of regressing the same thing out twice.
### 2) For brain-centric approach, should we use a difference score or residualization?
In principle using the difference between P3.social and P3.indiv as a depent variable is also a way to do the brain-centric approach. There is some reason to think residualization works better, because variance from the first phase will "leak" into difference scores but not into residualized scores:
```{r, warning=F}
rsd <- lmer(P3.social ~ P3.indiv + (1|subject), data = D3)
ggpairs(cbind(D3[,c("P3.indiv", "P3.social","P3.dif")],P3.residuals=resid(rsd)))
```
### 3) Should we use condition as a factor or as a continuous difference between group and individual ratings?
One reaosn to prefer the factor is that this allows us to detect nonlinear effects (e.g. low differing from both same and high, which is what happens for P3 amplitudes)
Based on various reasons, including some saturday-night-p-hacking, I stuck to the brain-centric models using group ratings as factor:
### P3
```{r, warning=F}
# simplest model
summary(fit <- lmer(P3.social ~ P3.indiv + condition + (1|subject), data = D3))
# get p-values for the random effects
rand(fit)
# get a significance test for all terms
anova(fit)
coefplot(fit)
#visreg(fit, xvar = "condition")
# model without neutral pictures
summary(fit <- lmer(P3.social ~ P3.indiv + condition + (1|subject) + (1|photo), data = D3[D3$photoType=="emo",]))
# plot means using raw data
# pl1way(D3,"P3.dif", "condition")
# plot condition effect using residuals from the model above
rsd <- lmer(P3.social ~ P3.indiv + (1|subject), data = D3)
pl1way(cbind(D3,dep=resid(rsd)),"dep", "condition")
```
### LPP
```{r, warning=F}
# simplest model
summary(fit <- lmer(LPP.social ~ LPP.indiv + condition + (1|subject), data = D3))
# get p-values for the random effects
rand(fit)
# get a significance test for all terms
anova(fit)
coefplot(fit)
#visreg(fit, xvar = "condition")
# plot means using raw data
# pl1way(D3,"P3.dif", "condition")
# plot condition effect using residuals from the model above
rsd <- lmer(LPP.social ~ LPP.indiv + (1|subject), data = D3)
pl1way(cbind(D3,dep=resid(rsd)),"dep", "condition")
```
hea
mean (D3$P3.dif)
### SLW
```{r, warning=F}
# simplest model
summary(fit <- lmer(SLW.social ~ SLW.indiv + condition + (1|subject), data = D3))
# get p-values for the random effects
rand(fit)
# get a significance test for all terms
anova(fit)
coefplot(fit)
#visreg(fit, xvar = "condition")
# plot means using raw data
# pl1way(D3,"P3.dif", "condition")
# plot condition effect using residuals from the model above
rsd <- lmer(SLW.social ~ SLW.indiv + (1|subject), data = D3)
pl1way(cbind(D3,dep=resid(rsd)),"dep", "condition")
```
```{r dif}
Based on these analyses, we have a small but significant effect on P3 and no effects in later stages. I'm pretty sure we can build a story out of this alone. But I also am getting increasing eager to take a more explorative approach to ask where in the brain the social cues actually have an impact. Given our design, LIMO is probably still the best way to do that, we can of course discuss this further.
```{r dif, include=FALSE}
head(D3)
D3$P3.dif = D3$P3.social-D3$P3.indiv
......@@ -109,19 +188,15 @@ D3$LPP.dif = D3$LPP.social-D3$LPP.indiv
D3$SLW.dif = D3$SLW.social-D3$SLW.indiv
summary(fit <- lmer(P3.dif ~ condition + (1|subject) + (1|photo), data = D3[D3$photoType=="emo",]))
summary(fit <- lmer(LPP.dif ~ condition + (1|subject) + (1|photo), data = D3[D3$photoType=="emo",]))
summary(fit <- lmer(SLW.dif ~ condition + (1|subject) + (1|photo), data = D3[D3$photoType=="emo",]))
```
```{r analysis slw }
```{r analysis slw, include=FALSE}
head(pl1way)
# AFFECTIVE MAIN EFFECT
......@@ -149,7 +224,7 @@ coefplot(fit)
```
```{r LPP}
```{r LPP ,include=FALSE}
# continuous model
summary(fit <- lmer(LPP.social ~ LPP.indiv + rate*grate + (1|subject) + (1|photo), data = D3))
......@@ -169,11 +244,11 @@ coefplot(fit)
```
```{r, include=FALSE}
### my plan is to create two wide formats
####1. will allow me to create a difference score from the first phase to the second
####2. Will allow me to create a difference scroe from the emotional and the neutral pictures
```{r }
id = which( colnames(d)=="id" )
condition = which( colnames(d)=="condition" )
......@@ -207,9 +282,8 @@ length (d2$LPPs)
```
## as you can see the length of the two datasets is not the same
```{r Look just at the second, include=FALSE}
## as you can see the length of the two datasets is not the same
d %>%
......@@ -229,5 +303,4 @@ d %>%
```
```
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment