Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Identify unique pairs within a given study (to keep things manageable) and create list of possible surrogate pairs (e.g. individual 1 from pair 1 and individual 2 from pair 2)
- Groups <- as.numeric(as.character(unique(s4$group[s4$StudyNum==4]))) # Lists all pairs
- SurrogateList <- expand.grid(a = Groups, b = Groups) # Identify all possible combinations of 2 pairs
- SurrogateList = subset(SurrogateList, a != b) # Exclude combinations with identical pairs
- surrodf <- tibble()
- for (i in 1:nrow(SurrogateList)){ # loop through all combinations
- x <- subset(s4, group==SurrogateList$a[i]) # subset data from the first pair
- y <- subset(s4, group==SurrogateList$a[i]) # subset data from the second pair
- group <- c(800 + ((1:4)*i)) # create new pair id
- for (co in c("Synchronous","TurnTaking", "Conversation", "MovementCoop", "MovementGuided")){ # loop through conditions
- if (co %in% unique(x$condition) & co %in% unique(y$condition)){ # check that both pairs have the data for that condition
- z1 <- subset(x, condition==co) # subset only that condtion from first pair
- z2 <- subset(y, condition==co) # subset only that condtion from second pair
- if (nrow(z1) > nrow(z2)) { # make sure data have same length in both pairs
- z1<-z1[1:length(z2)]
- }
- if (nrow(z2) > nrow(z1)) {
- z2<-z2[1:length(z1)]
- }
- w1 <- z1 %>% mutate( # assemble new pair combining the 2 pairs
- HR2 = z2$HR_other,
- Resp2 = z2$Resp_other,
- HR2_lead = z2$HR_self,
- Resp2_lead = z2$Resp_self,
- HR2_change = z2$changeHR_other,
- Resp2_change = z2$changeResp_other)
- } ### DO SOMETHING TO SAVE THIS # make sure that you do this!
- surrodf <- rbind(surrodf, w1)
- }}
- # Starting from the wide format, create "surrogate" dataset with the data from surrogate pairs
- # Make it into long format
- # Create models as in chunks above, but adding an interaction with the Real vs. Surrogate variable (exclude shuffled ones for simplicity)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement