rm(list=ls(all=TRUE)) # clear all variables graphics.off() # clear all graphics # Visual Search # Greg Francis # PSY 626 # 02 October 202 # load full data file ZCdata<-read.csv(file="ZennerCards.csv",header=TRUE,stringsAsFactors=FALSE) # load the rethinking library library(rethinking) # Dummy variables to indicate actual card type and guessed card type ZCdata$CardIndex <- coerce_index(ZCdata$ActualCard) # numbers 1-5 assigned to Card names alphabetically ZCdata$SelectedCardIndex <- coerce_index(ZCdata$GuessedCard) # numbers 1-5 assigned to Card names alphabetically # All cards and subjects treated the same ZCmodel1 <- map( alist( Score ~ dbinom(1, p), logit(p) <- a, a ~ dnorm(0, 10) ), data= ZCdata ) print(precis(ZCmodel1)) cat("Finished with ZCmodel1\n") a=coef(ZCmodel1)["a"] cat("Probability of correct response: ", logistic(a)) # Different probabilities for different actual cards ZCmodel2 <- map( alist( Score ~ dbinom(1, p), logit(p) <- a[CardIndex], a[CardIndex] ~ dnorm(0, 10) ), data= ZCdata ) cat("Finished with ZCmodel2\n") print(precis(ZCmodel2, depth=2)) cat("Probability of correct response: ", logistic(coef(ZCmodel2))) # Different probabilities for different selected cards ZCmodel3 <- map( alist( Score ~ dbinom(1, p), logit(p) <- a[SelectedCardIndex], a[SelectedCardIndex] ~ dnorm(0, 10) ), data= ZCdata ) cat("Finished with ZCmodel3\n") cat("Probability of correct response: ", logistic(coef(ZCmodel3))) # Null model (p=0.2) ZCmodel0 <- map( alist( Score ~ dbinom(1, p), logit(p) <- a, a ~ dnorm(logit(0.2), 0.001) ), data= ZCdata ) print(precis(ZCmodel0)) cat("Finished with ZCmodel0\n") a=coef(ZCmodel0)["a"] cat("Probability of correct response: ", logistic(a)) # Different probabilities for different participants ZCmodel4 <- map( alist( Score ~ dbinom(1, p), logit(p) <- a[Participant], a[Participant] ~ dnorm(0, 10) ), data= ZCdata ) cat("Finished with ZCmodel4\n") print(precis(ZCmodel4, depth=2)) cat("Probability of correct response: ", logistic(coef(ZCmodel4))) # Different probabilities for different cards and different participants ZCmodel5 <- map( alist( Score ~ dbinom(1, p), logit(p) <- a[CardIndex] + b[Participant], a[CardIndex] ~ dnorm(0, 10), b[Participant] ~ dnorm(0, 10) ), data= ZCdata ) cat("Finished with ZCmodel5\n") print(precis(ZCmodel5, depth=2)) aValues5<-c() for(p in unique(ZCdata$Participant)){ for(p2 in sort(unique(ZCdata$CardIndex))){ code<-sprintf("b[%d]", p) code2<-sprintf("a[%d]", p2) aValues5<- c(aValues5, coef(ZCmodel5)[code] + coef(ZCmodel5)[code2]) } } cat("Probability of correct response: ", logistic(aValues5)) # Stupid model # Different probabilities for different selected cards and different participants ZCdata$InteractionIndex <- 1+ 5*(ZCdata$SelectedCardIndex-1) + (ZCdata$CardIndex-1) ZCmodel6 <- map( alist( Score ~ dbinom(1, p), logit(p) <- a[InteractionIndex], a[InteractionIndex] ~ dnorm(0, 10) ), data= ZCdata ) cat("Finished with ZCmodel6\n") print(precis(ZCmodel6, depth=2))