choices <- choices %>% group_by(day,IdLabel) %>% mutate(cumrewards = cumsum(reward_status))
choices %>% ggplot(aes(Nchoice,cumrewards, color=IdLabel)) +
facet_grid(. ~ day) + geom_line()
choices <- choices %>% group_by(day,IdLabel) %>% mutate(cumrewards = cumsum(reward_status))
choices <- alldays %>% group_by(day,IdLabel,choice = str_detect(unitLabel, "Cond")) %>%
mutate(Nchoice = 1:n()) %>% filter(choice) %>% ungroup() %>% select(-choice)
learningchoices <- choices %>% group_by(day,IdLabel) %>%
mutate(Choicebin = cut(Nchoice, breaks=seq(0,1000, by=50))) %>%
group_by(day,IdLabel,Choicebin) %>%  summarise(perc_rewarded=mean(reward_status))
learningchoices %>% ggplot(aes(as.integer(Choicebin)*50,perc_rewarded, color=IdLabel)) +
facet_grid(IdLabel ~ day) + geom_line()
choices <- choices %>% group_by(day,IdLabel) %>% mutate(cumrewards = cumsum(reward_status))
choices %>% ggplot(aes(Nchoice,cumrewards, color=IdLabel)) +
facet_grid(. ~ day) + geom_line()
require(dplyr)
require(psych)
require(stringr)
require(ggplot2)
day1 <- read.csv2(file="discrimination-12.11.13.csv", header=TRUE, dec=",",sep=";",
fileEncoding="UTF-16LE", as.is = T, row.names=NULL)
day2 <- read.csv2(file="discrimination-12.11.14.csv", header=TRUE, dec=",",sep=";",
fileEncoding="UTF-16LE", as.is = T, row.names=NULL)
day3 <- read.csv2(file="discrimination-12.11.15.csv", header=TRUE, dec=",",sep=";",
fileEncoding="UTF-16LE", as.is = T, row.names=NULL)
day1 <- day1 %>% mutate(day = 1)
day2 <- day2 %>% mutate(day = 2)
day3 <- day3 %>% mutate(day = 3)
for (i in 1:3) {
assign(paste("day",i, sep = ""), eval(parse(text=paste("day",i, sep = ""))) %>% mutate(day = i))
}
alldays <- bind_rows(day1,day2,day3)
#alldays$DateTime <- sub(",",".",alldays$DateTime)
#alldays$DateTime <- as.POSIXlt(as.numeric(alldays$DateTime) * (60*60*24), origin="1899-12-30", tz="GMT")
alldays$DateTime <- as.POSIXct(alldays$DateTime * (60*60*24), origin="1899-12-30", tz="GMT")
alldays <- alldays %>% filter(row_number() > 168)
sextable <-data.frame(IdLabel = c("m20","m22","m24","m30","m32"),
sex = c(0,1,0,1,0))
alldays <- inner_join(alldays,sextable)
alldays %>% group_by(IdLabel,sex,day) %>%
summarise(consumed = sum(reinforce1value,na.rm=TRUE)) %>%
group_by(sex) %>% summarise(
averageconsumed = mean(consumed))
alldays <- alldays %>% rename(
LNDur = MsgValue2, reward_status = MsgValue3
) %>%
mutate(
LNDur = ifelse(eventDuration > 0,log(eventDuration),0),
reward_status = ifelse((reinforce1value==0 |
is.na(reinforce1value)),0,1))
breaks <- seq(0,max(alldays$eventDuration), by=100)
durations <- alldays %>% mutate(
durint=cut(eventDuration, breaks= seq(0,max(alldays$eventDuration), by=100))
#cut, compare with previous example
) %>% filter(str_detect(unitLabel, "[Cond]")) %>% #filter all non-CondMod events
group_by(durint) %>%  summarise(Nvis = n())
durations %>% ggplot() + geom_bar(aes(as.integer(durint)*100, Nvis), stat="identity") +
xlim(0,10000) #this zooms the axis in to better see what's going on
durations %>% ggplot() + geom_bar(aes(as.integer(durint)*100, Nvis), stat="identity")
alldays %>% ggplot() + geom_density(aes(eventDuration)) + xlim(0,10000)
require(lubridate)
hourlydata <- alldays %>% group_by(rounded_hour = floor_date(
DateTime, unit = "hour"),IdLabel,day) %>% arrange(DateTime) %>%
summarise(rewards = sum(reward_status), detections = n())
hourlydata %>% ggplot(aes(rounded_hour,rewards,color=IdLabel)) + geom_line() +
scale_colour_brewer(palette="Set2")
hourlydata %>% ggplot(aes(rounded_hour,detections,color=IdLabel)) + geom_line()
require(scales)
hourlydata %>% ggplot(aes(rounded_hour,detections,color=IdLabel)) + geom_line() +
scale_colour_brewer(palette="Set2") +
scale_x_datetime(breaks=("12 hour"), minor_breaks=("1 hour"),
labels=date_format("%D:%H"))
hourlydata %>% ggplot(aes(rounded_hour,detections,color=IdLabel)) + geom_line() +
scale_colour_brewer(palette="Set2") + facet_grid( ~ IdLabel) +
scale_x_datetime(breaks=("12 hour"), minor_breaks=("1 hour"), labels=date_format("%H"))
learning <- alldays %>% group_by(day,IdLabel) %>%
mutate(Visbin = cut(Nvis, breaks=seq(0,1000, by=50))) %>%
group_by(day,IdLabel,Visbin) %>%  summarise(perc_rewarded=mean(reward_status)) %>% filter(str_detect(IdLabel, "m"))
alldays %>% ggplot(aes(Nvis,reward_status, color = IdLabel)) +
stat_smooth()
alldays <- alldays %>% group_by(day,IdLabel) %>% mutate(Nvis = 1:n())
alldays %>% ggplot(aes(Nvis,reward_status, color = IdLabel)) +
stat_smooth()
learning <- alldays %>% group_by(day,IdLabel) %>%
mutate(Visbin = cut(Nvis, breaks=seq(0,1000, by=50))) %>%
group_by(day,IdLabel,Visbin) %>%  summarise(perc_rewarded=mean(reward_status)) %>% filter(str_detect(IdLabel, "m"))
hourlydata %>% ggplot(aes(rounded_hour,detections,color=IdLabel)) + geom_line() +
scale_colour_brewer(palette="Set2") + facet_grid( ~ IdLabel) +
scale_x_datetime(breaks=("12 hour"), minor_breaks=("1 hour"), labels=date_format("%H"))
learning %>% ggplot(aes(as.integer(Visbin)*50,perc_rewarded, color=IdLabel)) +
facet_grid(IdLabel ~ day) + geom_line()
alldays <- alldays %>% mutate(corner = str_sub(unitLabel,-1))
feeders<- data.frame(IdLabel = c("m20","m22","m24","m30","m32"),
"C1" = c(1,0,1,0,0), "C2" = c(0,1,0,0,1),
"C3" = c(0,0,1,1,1), "C4" = c(1,1,0,1,0))
require(tidyr)
feeders <- gather(feeders, corner, correct_corner, -IdLabel) %>%  mutate(corner = str_sub(corner, -1))
alldays <- inner_join(alldays,feeders)
#which mouse visits which corner
cornerdata <- alldays %>% group_by(IdLabel,day,corner) %>%
summarise(visits = n(), correct_corner = mean(correct_corner),
visitsperh = ifelse(correct_corner == 0, visits/8, visits/4))
cornerdata %>% ggplot(aes(correct_corner, visits)) + geom_point() + facet_wrap(IdLabel ~ day)
cornerdata %>% ggplot(aes(correct_corner, visitsperh)) + geom_point() + facet_wrap(IdLabel ~ day)
cornerdata %>% ggplot(aes(correct_corner, visits)) + geom_point() + facet_wrap(IdLabel ~ day) +
geom_line()
cornerdata %>% ggplot(aes(correct_corner, visits)) + geom_point() + facet_wrap(IdLabel ~ day) +
geom_smooth()
cornerdata %>% ggplot(aes(correct_corner, visits)) + geom_point() + facet_wrap(IdLabel ~ day) +
geom_smooth(method=lm)
cornerdata %>% ggplot(aes(correct_corner, visitsperh)) + geom_point() + facet_wrap(IdLabel ~ day) +
geom_smooth(method=lm)
alldays %>% group_by(IdLabel,day) %>% summarise(correct_corner = mean(correct_corner)) %>%
ggplot(aes(day,correct_corner, color=IdLabel)) + geom_point() + geom_line()
cornerdata %>% ggplot(aes(correct_corner, visitsperh)) + geom_point() + facet_wrap(IdLabel ~ day) +
geom_smooth(method=lm)
cornerdata %>% ggplot(aes(correct_corner, visitsperh, color=IdLabel)) + geom_point() +
facet_wrap(. ~ day) + geom_smooth(method=lm)
cornerdata %>% ggplot(aes(correct_corner, visitsperh, color=IdLabel)) + geom_point()
cornerdata %>% ggplot(aes(correct_corner, visitsperh, color=IdLabel)) + geom_point() +
facet_wrap(. ~ day) + geom_line()
cornerdata %>% ggplot(aes(correct_corner, visitsperh, color=IdLabel)) + geom_point() +
geom_line()
cornerdata %>% ggplot(aes(correct_corner, visitsperh, color=IdLabel)) + geom_point() +
geom_smooth(method=lm)
cornerdata %>% ggplot(aes(correct_corner, visitsperh, color=day)) + geom_point() +
geom_smooth(method=lm)
cornerdata %>% ggplot(aes(correct_corner, visitsperh, color=as.factor(day))) + geom_point() +
geom_smooth(method=lm)
alldays %>% group_by(IdLabel,day) %>% summarise(correct_corner = mean(correct_corner)) %>%
ggplot(aes(day,correct_corner, color=IdLabel)) + geom_point() + geom_line()
alldays %>% group_by(IdLabel,day) %>% summarise(perc_correct_corner = mean(correct_corner)) %>%
ggplot(aes(day,perc_correct_corner, color=IdLabel)) + geom_point() + geom_line()
hourlydata <- alldays %>% group_by(rounded_hour = floor_date(
DateTime, unit = "hour"),IdLabel,as.factor(day)) %>% arrange(DateTime) %>%
summarise(rewards = sum(reward_status), detections = n(),perccorrect = mean(correct_corner))
hourlydata <- alldays %>% group_by(rounded_hour = floor_date(
DateTime, unit = "hour"),IdLabel,as.factor(day)) %>% arrange(DateTime) %>%
summarise(rewards = sum(reward_status), detections = n(),perccorrect = mean(correct_corner))
hourlydata %>% ggplot(aes(rounded_hour,perccorrect,color=IdLabel)) + geom_line() +
scale_colour_brewer(palette="Set2") + facet_grid( ~ IdLabel) +
scale_x_datetime( breaks=("6 hour"), minor_breaks=("1 hour"), labels=date_format("%H"))
hourlydata <- alldays %>% group_by(rounded_hour = floor_date(
DateTime, unit = "hour"),IdLabel,day) %>% arrange(DateTime) %>%
summarise(rewards = sum(reward_status), detections = n(),perccorrect = mean(correct_corner))
hourlydata %>% ggplot(aes(rounded_hour,perccorrect,color=IdLabel)) + geom_line() +
scale_colour_brewer(palette="Set2") + facet_grid( ~ IdLabel) +
scale_x_datetime( breaks=("6 hour"), minor_breaks=("1 hour"), labels=date_format("%H"))
hourlydata <- alldays %>% group_by(rounded_hour = floor_date(
DateTime, unit = "hour"),IdLabel,day) %>% arrange(DateTime) %>%
summarise(rewards = sum(reward_status), detections = n(),perccorrect = mean(correct_corner))
hourlydata %>% ggplot(aes(rounded_hour,perccorrect,color=IdLabel)) + geom_line() +
scale_colour_brewer(palette="Set2") + facet_grid( ~ IdLabel) +
scale_x_datetime( breaks=("6 hour"), minor_breaks=("1 hour"), labels=date_format("%H"))
dr_sessions <- alldays %>% filter(str_detect(unitLabel, "Cond")) %>%
mutate(dr_session = ifelse(hour(DateTime) == 17,1,ifelse(hour(DateTime)==2,2,0))) %>%
group_by(day,IdLabel, dr_session)
dr_sessions2 <- alldays %>% filter(str_detect(unitLabel, "Cond")) %>% mutate(hour = hour(DateTime))
sessions <- data.frame(
hour = c(17,2),
dr_session = c(1,2)
)
dr_sessions3 <- full_join(dr_sessions2,sessions, by="hour") %>%
mutate(dr_session = ifelse(is.na(dr_session), 0,dr_session))
dr_sessions %>% group_by(day, IdLabel, dr_session) %>%
summarise(meanreward = mean(reward_status)) %>%
ggplot(aes(dr_session,meanreward, color = IdLabel)) + facet_grid(IdLabel ~ day) +
geom_line() + geom_point()
dr_sessions3 %>% group_by(day, IdLabel, dr_session) %>%
summarise(meanreward = mean(reward_status)) %>%
ggplot(aes(dr_session,meanreward, color = IdLabel)) + facet_grid(IdLabel ~ day) +
geom_line() + geom_point()
hourlydata %>% ggplot() + geom_line(aes(rounded_hour,perccorrect,color=IdLabel)) +
scale_colour_brewer(palette="Set2") + #facet_grid( ~ IdLabel) +
scale_x_datetime( breaks=("6 hour"), minor_breaks=("1 hour"), labels=date_format("%H")) +
geom_rect(data=rectangles, aes(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax),
fill='gray80', alpha=0.8)
rectleft <- c(ymd_hms("2012-11-13 17:00:00 GMT", tz="GMT")+ days(0:2),
ymd_hms("2012-11-14 02:00:00 GMT", tz="GMT")+ days(0:2))
rectangles <- data.frame(
xmin = rectleft,
xmax = rectleft + dhours(1),
ymin = 0, ymax = Inf
)
rectangles <- rectangles %>% mutate(intervals = new_interval(xmin,xmax, tzone = "GMT"),
session = ifelse(hour(xmin)== 18,1,2))
hourlydata %>% ggplot() + geom_line(aes(rounded_hour,perccorrect,color=IdLabel)) +
scale_colour_brewer(palette="Set2") + #facet_grid( ~ IdLabel) +
scale_x_datetime( breaks=("6 hour"), minor_breaks=("1 hour"), labels=date_format("%H")) +
geom_rect(data=rectangles, aes(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax),
fill='gray80', alpha=0.8)
choices <- alldays %>% group_by(day,IdLabel,choice = str_detect(unitLabel, "Cond")) %>%
mutate(Nchoice = 1:n()) %>% filter(choice) %>% ungroup() %>% select(-choice)
learningchoices <- choices %>% group_by(day,IdLabel) %>%
mutate(Choicebin = cut(Nchoice, breaks=seq(0,1000, by=50))) %>%
group_by(day,IdLabel,Choicebin) %>%  summarise(perc_rewarded=mean(reward_status))
learningchoices %>% ggplot(aes(as.integer(Choicebin)*50,perc_rewarded, color=IdLabel)) +
facet_grid(IdLabel ~ day) + geom_line()
choices <- choices %>% group_by(day,IdLabel) %>% mutate(cumrewards = cumsum(reward_status))
choices %>% ggplot(aes(Nchoice,cumrewards, color=IdLabel)) +
facet_grid(. ~ day) + geom_line()
choices %>% ggplot(aes(Nchoice,cumrewards, color=IdLabel)) +
facet_grid(. ~ day) + geom_line()
View(dr_sessions)
dr_sessions %>% group_by(day, IdLabel, dr_session) %>%
summarise(meanreward = mean(reward_status)) %>%
ggplot(aes(dr_session,meanreward, color = IdLabel)) + facet_grid(IdLabel ~ day) +
geom_line() + geom_point()
dr_sessions %>% group_by(day, IdLabel, dr_session) %>%
summarise(meanreward = mean(reward_status))
dr_sessions1 <- alldays %>% filter(str_detect(unitLabel, "Cond")) %>%
group_by(day,IdLabel, dr_session = ifelse(hour(DateTime) == 17,1,ifelse(hour(DateTime)==2,2,0)))
identical(dr_sessions,dr_sessions1)
all.equal(dr_sessions,dr_sessions1)
dr_sessions <- alldays %>% filter(str_detect(unitLabel, "Cond")) %>%
mutate(dr_session = ifelse(hour(DateTime) == 17,1,ifelse(hour(DateTime)==2,2,0))) %>%
group_by(day,IdLabel, dr_session)
View(alldays)
View(dr_sessions)
sessions <- data.frame(
hour = c(17,2),
dr_session = c(1,2)
)
View(sessions)
sessions <- data.frame(
hour = c(17,18,1,2),
dr_session = c(1,1,2,2)
)
View(sessions)
dr_sessions <- alldays %>% filter(str_detect(unitLabel, "Cond")) %>%
mutate(dr_session = ifelse(hour(DateTime) == 17 | hour(DateTime) == 18,1,
ifelse(hour(DateTime)== 2 | hour(DateTime) == 3,2,0))) %>%
group_by(day,IdLabel, dr_session)
dr_sessions1 <- alldays %>% filter(str_detect(unitLabel, "Cond")) %>%
group_by(day,IdLabel, dr_session = ifelse(hour(DateTime) == 17,1,ifelse(hour(DateTime)==2,2,0)))
identical(dr_sessions,dr_sessions1)
all.equal(dr_sessions,dr_sessions1)
dr_sessions <- alldays %>% filter(str_detect(unitLabel, "Cond")) %>%
mutate(dr_session = ifelse(hour(DateTime) == 17 | hour(DateTime) == 18,1,
ifelse(hour(DateTime)== 2 | hour(DateTime) == 3,2,0))) %>%
group_by(day,IdLabel, dr_session)
View(dr_sessions)
View(dr_sessions)
dr_sessions <- alldays %>% filter(str_detect(unitLabel, "Cond")) %>%
mutate(dr_session = ifelse(hour(DateTime) == 17 | hour(DateTime) == 18,1,
ifelse(hour(DateTime)== 2 | hour(DateTime) == 3,2,0))) %>%
group_by(day,IdLabel, dr_session)
dr_sessions1 <- alldays %>% filter(str_detect(unitLabel, "Cond")) %>%
group_by(day,IdLabel, dr_session = ifelse(hour(DateTime) == 17 | hour(DateTime) == 18,1,
ifelse(hour(DateTime)==2 | hour(DateTime) == 3,2,0)))
identical(dr_sessions,dr_sessions1)
all.equal(dr_sessions,dr_sessions1)
dr_sessions2 <- alldays %>% filter(str_detect(unitLabel, "Cond")) %>% mutate(hour = hour(DateTime))
sessions <- data.frame(
hour = c(17,18,1,2),
dr_session = c(1,1,2,2)
)
dr_sessions3 <- full_join(dr_sessions2,sessions, by="hour") %>%
mutate(dr_session = ifelse(is.na(dr_session), 0,dr_session))
dr_sessions %>% group_by(day, IdLabel, dr_session) %>%
summarise(meanreward = mean(reward_status)) %>%
ggplot(aes(dr_session,meanreward, color = IdLabel)) + facet_grid(IdLabel ~ day) +
geom_line() + geom_point()
dr_sessions3 %>% group_by(day, IdLabel, dr_session) %>%
summarise(meanreward = mean(reward_status)) %>%
ggplot(aes(dr_session,meanreward, color = IdLabel)) + facet_grid(IdLabel ~ day) +
geom_line() + geom_point()
dr_sessions3 %>% group_by(day, IdLabel, dr_session) %>%
summarise(meanreward = mean(reward_status)) %>%
ggplot(aes(dr_session,meanreward, color = IdLabel)) + facet_grid(IdLabel ~ day) +
geom_line() + geom_point()
dr_sessions3 <- full_join(dr_sessions2,sessions, by="hour") %>%
mutate(dr_session = ifelse(is.na(dr_session), 0,dr_session))
dr_sessions %>% group_by(day, IdLabel, dr_session) %>%
summarise(meanreward = mean(reward_status)) %>%
ggplot(aes(dr_session,meanreward, color = IdLabel)) + facet_grid(IdLabel ~ day) +
geom_line() + geom_point()
dr_sessions3 %>% group_by(day, IdLabel, dr_session) %>%
summarise(meanreward = mean(reward_status)) %>%
ggplot(aes(dr_session,meanreward, color = IdLabel)) + facet_grid(IdLabel ~ day) +
geom_line() + geom_point()
dr_sessions <- alldays %>% filter(str_detect(unitLabel, "Cond")) %>%
mutate(dr_session = ifelse(hour(DateTime) == 17 | hour(DateTime) == 18,1,
ifelse(hour(DateTime)== 2 | hour(DateTime) == 3,2,0))) %>%
group_by(day,IdLabel, dr_session)
dr_sessions1 <- alldays %>% filter(str_detect(unitLabel, "Cond")) %>%
group_by(day,IdLabel, dr_session = ifelse(hour(DateTime) == 17 | hour(DateTime) == 18,1,
ifelse(hour(DateTime)==2 | hour(DateTime) == 3,2,0)))
identical(dr_sessions,dr_sessions1)
all.equal(dr_sessions,dr_sessions1)
dr_sessions2 <- alldays %>% filter(str_detect(unitLabel, "Cond")) %>% mutate(hour = hour(DateTime))
sessions <- data.frame(
hour = c(17,18,1,2),
dr_session = c(1,1,2,2)
)
dr_sessions3 <- full_join(dr_sessions2,sessions, by="hour") %>%
mutate(dr_session = ifelse(is.na(dr_session), 0,dr_session))
dr_sessions %>% group_by(day, IdLabel, dr_session) %>%
summarise(meanreward = mean(reward_status)) %>%
ggplot(aes(dr_session,meanreward, color = IdLabel)) + facet_grid(IdLabel ~ day) +
geom_line() + geom_point()
dr_sessions3 %>% group_by(day, IdLabel, dr_session) %>%
summarise(meanreward = mean(reward_status)) %>%
ggplot(aes(dr_session,meanreward, color = IdLabel)) + facet_grid(IdLabel ~ day) +
geom_line() + geom_point()
sessions
all.equal(dr_sessions,dr_sessions1)
identical(dr_sessions,dr_sessions1)
all.equal(dr_sessions, dr_sessions3)
all.equal(dr_sessions, dr_sessions3)
all.equal(dr_sessions, dr_sessions3 %>% select(-hour))
dr_sessions2 <- alldays %>% filter(str_detect(unitLabel, "Cond")) %>% mutate(hour = hour(DateTime))
sessions <- data.frame(
hour = c(17,18,1,2),
dr_session = c(1,1,2,2)
)
dr_sessions3 <- full_join(dr_sessions2,sessions, by="hour") %>%
mutate(dr_session = ifelse(is.na(dr_session), 0,dr_session))
View(dr_sessions3)
View(dr_sessions3)
dr_sessions2 <- alldays %>% filter(str_detect(unitLabel, "Cond")) %>% mutate(hour = hour(DateTime))
dr_sessions <- alldays %>% filter(str_detect(unitLabel, "Cond")) %>%
mutate(dr_session = ifelse(hour(DateTime) == 17 | hour(DateTime) == 18,1,
ifelse(hour(DateTime)== 2 | hour(DateTime) == 3,2,0))) %>%
group_by(day,IdLabel, dr_session)
dr_sessions1 <- alldays %>% filter(str_detect(unitLabel, "Cond")) %>%
group_by(day,IdLabel, dr_session = ifelse(hour(DateTime) > 16 & hour(DateTime) < 19,1,
ifelse(hour(DateTime)> 1 & hour(DateTime) < 4,2,0)))
identical(dr_sessions,dr_sessions1)
all.equal(dr_sessions,dr_sessions1)
dr_sessions2 <- alldays %>% filter(str_detect(unitLabel, "Cond")) %>% mutate(hour = hour(DateTime))
sessions <- data.frame(
hour = c(17,18,1,2),
dr_session = c(1,1,2,2)
)
sessions
dr_sessions3 <- full_join(dr_sessions2,sessions, by="hour") %>%
mutate(dr_session = ifelse(is.na(dr_session), 0,dr_session))
all.equal(dr_sessions1, dr_sessions3 %>% select(-hour))
dr_sessions3 <- full_join(dr_sessions2,sessions, by="hour") %>% group_by(day, IdLabel) %>%
mutate(dr_session = ifelse(is.na(dr_session), 0,dr_session))
all.equal(dr_sessions1, dr_sessions3 %>% select(-hour))
all.equal(dr_sessions1, dr_sessions2 %>% select(-hour))
all.equal(dr_sessions1 %>% select(-dr_session), dr_sessions2 %>% select(-hour))
all.equal(dr_sessions1 %>% select(-dr_session), dr_sessions2 %>% select(-hour))
dr_sessions1 %>% select(-dr_session)
dr_sessions1 %>% select(-IdLabel)
dr_sessions1
dr_sessions1 %>% select(-IdLabel)
dr_sessions1 %>% select(-dr_session)
all.equal(dr_sessions1 %>% select(-dr_session), dr_sessions2 %>% select(-hour))
dr_sessions2 %>% select(-hour)
dr_sessions3 <- full_join(dr_sessions2,sessions, by="hour") %>%
mutate(dr_session = ifelse(is.na(dr_session), 0,dr_session))
View(dr_sessions3)
View(dr_sessions3)
sessions <- data.frame(
hour = c(17,18,2,3),
dr_session = c(1,1,2,2)
)
dr_sessions3 <- full_join(dr_sessions2,sessions, by="hour") %>%
mutate(dr_session = ifelse(is.na(dr_session), 0,dr_session))
all.equal(dr_sessions1 %>% select(-dr_session), dr_sessions2 %>% select(-hour))
all.equal(dr_sessions1, dr_sessions3 %>% select(-hour))
dr_sessions %>% group_by(day, IdLabel, dr_session) %>%
summarise(meanreward = mean(reward_status)) %>%
ggplot(aes(dr_session,meanreward, color = IdLabel)) + facet_grid(IdLabel ~ day) +
geom_line() + geom_point()
dr_sessions3 %>% group_by(day, IdLabel, dr_session) %>%
summarise(meanreward = mean(reward_status)) %>%
ggplot(aes(dr_session,meanreward, color = IdLabel)) + facet_grid(IdLabel ~ day) +
geom_line() + geom_point()
all.equal(dr_sessions1, dr_sessions3 %>% select(-hour))
dr_sessions3 %>% group_by(day, IdLabel, dr_session) %>%
summarise(meanreward = mean(correct_corner)) %>%
ggplot(aes(dr_session,meanreward, color = IdLabel)) + facet_grid(IdLabel ~ day) +
geom_line() + geom_point()
dr_sessions3 %>% group_by(day, IdLabel, dr_session) %>%
summarise(meanreward = mean(reward_status)) %>%
ggplot(aes(dr_session,meanreward, color = IdLabel)) + facet_grid(IdLabel ~ day) +
geom_line() + geom_point()
dr_sessions3 %>% group_by(day, IdLabel, dr_session) %>%
summarise(perccorrect = mean(correct_corner)) %>%
ggplot(aes(dr_session,perccorrect, color = IdLabel)) + facet_grid(IdLabel ~ day) +
geom_line() + geom_point()
dr_sessions3 %>% group_by(day, IdLabel, dr_session) %>%
summarise(perccorrect = mean(correct_corner)) %>%
ggplot(aes(dr_session,perccorrect, color = IdLabel)) + facet_grid(. ~ day) +
geom_line() + geom_point()
session_choices <- dr_sessions %>% group_by(day,IdLabel, dr_session, choice = str_detect(unitLabel, "Cond")) %>%
mutate(Nchoice = 1:n()) %>% filter(choice) %>% ungroup() %>% select(-choice)
learningchoices <- session_choices %>% group_by(day,IdLabel, dr_session) %>%
mutate(Choicebin = cut(Nchoice, breaks=seq(0,1000, by=50))) %>%
group_by(day,IdLabel,Choicebin, dr_session) %>%  summarise(perc_rewarded=mean(reward_status))
learningchoices
learningchoices %>% ggplot(aes(as.integer(Choicebin)*50,perc_rewarded, color=IdLabel)) +
facet_grid(IdLabel ~ day) + geom_line()
learningchoices %>% ggplot(aes(as.integer(Choicebin)*50,perc_rewarded, color=IdLabel)) +
facet_grid(dr_session ~ day) + geom_line()
learningchoices <- session_choices %>% group_by(day,IdLabel, dr_session) %>%
mutate(Choicebin = cut(Nchoice, breaks=seq(0,1000, by=50))) %>%
group_by(day,IdLabel,Choicebin, dr_session) %>%  summarise(perccorrect=mean(correct_corner))
learningchoices %>% ggplot(aes(as.integer(Choicebin)*50,perccorrect, color=IdLabel)) +
facet_grid(dr_session ~ day) + geom_line()
learningchoices %>% ggplot(aes(as.integer(Choicebin)*50,perccorrect, color=IdLabel)) +
facet_grid(dr_session ~ day) + geom_line()
choices <- session_choices %>% group_by(day,IdLabel, dr_session) %>%
mutate(cumrewards = cumsum(reward_status))
choices %>% ggplot(aes(Nchoice,cumrewards, color=IdLabel)) +
facet_grid(dr_session ~ day) + geom_line()
choices <- session_choices %>% group_by(day,IdLabel, dr_session) %>%
mutate(cumrewards = cumsum(reward_status), cumcorrect = cumsum(correct_corner))
choices %>% ggplot(aes(Nchoice,cumcorrect, color=IdLabel)) +
facet_grid(dr_session ~ day) + geom_line()
choices %>% ggplot(aes(Nchoice,cumrewards, color=IdLabel)) +
facet_grid(. ~ day) + geom_line()
choices %>% ggplot(aes(Nchoice,cumrewards, color=IdLabel)) +
facet_grid(. ~ day) + geom_line()
choices <- choices %>% group_by(day,IdLabel) %>% mutate(cumrewards = cumsum(reward_status))
choices %>% ggplot(aes(Nchoice,cumrewards, color=IdLabel)) +
facet_grid(. ~ day) + geom_line()
choices <- alldays %>% group_by(day,IdLabel,choice = str_detect(unitLabel, "Cond")) %>%
mutate(Nchoice = 1:n()) %>% filter(choice) %>% ungroup() %>% select(-choice)
learningchoices <- choices %>% group_by(day,IdLabel) %>%
mutate(Choicebin = cut(Nchoice, breaks=seq(0,1000, by=50))) %>%
group_by(day,IdLabel,Choicebin) %>%  summarise(perc_rewarded=mean(reward_status))
learningchoices %>% ggplot(aes(as.integer(Choicebin)*50,perc_rewarded, color=IdLabel)) +
facet_grid(IdLabel ~ day) + geom_line()
choices <- choices %>% group_by(day,IdLabel) %>% mutate(cumrewards = cumsum(reward_status))
choices %>% ggplot(aes(Nchoice,cumrewards, color=IdLabel)) +
facet_grid(. ~ day) + geom_line()
session_choices <- dr_sessions %>% group_by(day,IdLabel, dr_session, choice = str_detect(unitLabel, "Cond")) %>%
mutate(Nchoice = 1:n()) %>% filter(choice) %>% ungroup() %>% select(-choice)
learningchoices <- session_choices %>% group_by(day,IdLabel, dr_session) %>%
mutate(Choicebin = cut(Nchoice, breaks=seq(0,1000, by=50))) %>%
group_by(day,IdLabel,Choicebin, dr_session) %>% summarise(perccorrect=mean(correct_corner))
learningchoices %>% ggplot(aes(as.integer(Choicebin)*50,perccorrect, color=IdLabel)) +
facet_grid(dr_session ~ day) + geom_line()
session_choices <- dr_sessions %>% group_by(day,IdLabel, dr_session, choice = str_detect(unitLabel, "Cond")) %>%
mutate(Nchoice = 1:n()) %>% filter(choice) %>% ungroup() %>% select(-choice)
learningchoices <- session_choices %>% group_by(day,IdLabel, dr_session) %>%
mutate(Choicebin = cut(Nchoice, breaks=seq(0,1000, by=50))) %>%
group_by(day,IdLabel,Choicebin, dr_session) %>% summarise(perccorrect=mean(correct_corner))
learningchoices %>% ggplot(aes(as.integer(Choicebin)*50,perccorrect, color=IdLabel)) +
facet_grid(dr_session ~ day) + geom_line()
# choices outside of drinking session 1 and 2 are note necessarily strictly sequential
choices <- session_choices %>% group_by(day,IdLabel, dr_session) %>%
mutate(cumrewards = cumsum(reward_status), cumcorrect = cumsum(correct_corner))
choices %>% ggplot(aes(Nchoice,cumcorrect, color=IdLabel)) +
facet_grid(dr_session ~ day) + geom_line()
install.packages(c("coin", "roxygen2"))
install.packages("roxygen2")
install.packages("roxygen2")
require(dplyr)
require(ggplot2)
require(psych)
require(cpdetectorr)
setwd("C:\\Users\\nachevv\\Desktop\\Exploitation\\Exploitation\\bin\\Debug\\")
CP20vs60G0.5 <- read.csv2(file="Efficiency20vs60G0.5.csv", header=TRUE, dec=".",sep=";", na.strings="NA")
CP20vs60G0.4 <- read.csv2(file="Efficiency20vs60G0.4.csv", header=TRUE, dec=".",sep=";", na.strings="NA")
CP20vs60G0.3 <- read.csv2(file="Efficiency20vs60G0.3.csv", header=TRUE, dec=".",sep=";", na.strings="NA")
CP20vs60G0.2 <- read.csv2(file="Efficiency20vs60G0.2.csv", header=TRUE, dec=".",sep=";", na.strings="NA")
CP20vs60G0.1 <- read.csv2(file="Efficiency20vs60G0.1.csv", header=TRUE, dec=".",sep=";", na.strings="NA")
CP20vs60 <- bind_rows(CP20vs60G0.5, CP20vs60G0.4, CP20vs60G0.3, CP20vs60G0.2, CP20vs60G0.1)
sumeff <- CP20vs60 %>% group_by(Lapse, Gamma, Run) %>% summarise(Efficiency = mean(kJ),
perf = mean(Evenness))
sumeff %>% ggplot(aes(Lapse,Efficiency)) + geom_point() + stat_smooth(method="lm")
sumeff %>% ggplot(aes(Lapse,perf)) + geom_point() + stat_smooth(method="lm")
sumeff %>% ggplot(aes(Gamma,Efficiency)) + geom_point() + stat_smooth(method="lm")
sumeff %>% ggplot(aes(Gamma,perf)) + geom_point() + stat_smooth(method="lm")
output <- CP20vs60 %>% group_by(AgentID, Run, Lapse, Gamma) %>%
do(cp_wrapper(.$Evenness, "binomial", 1.3))
output <- output %>% filter(!is.na(Slopes))
summary1 <- output %>% group_by(Lapse, Gamma, Run) %>%
summarise(nCPs = sum(Run)/mean(Run), CP1 = min(Trial))
summary1 %>% group_by(Lapse, Gamma) %>% summarise(meanCP = mean(nCPs)) %>% ggplot(aes(Lapse,meanCP)) +
geom_point() + stat_smooth(method="lm")
summary1 %>% group_by(Lapse, Gamma) %>% summarise(meanlat = mean(CP1)) %>% ggplot(aes(Lapse,meanlat)) +
geom_point() + stat_smooth(method="lm")
summary1 %>% group_by(Lapse, Gamma) %>% filter(CP1 < 500) %>% summarise(meanlat = mean(CP1)) %>%
ggplot(aes(Lapse,meanlat)) +  geom_point() + stat_smooth(method="lm")
summary1 %>% group_by(Lapse, Gamma) %>% filter(CP1 < 500) %>% summarise(meanlat = mean(CP1)) %>%
ggplot(aes(Lapse, Gamma)) + geom_tile(aes(fill = meanlat), colour = "white") +
scale_fill_gradient(low = "white", high = "steelblue")
summary1 %>% group_by(Lapse, Gamma) %>% summarise(meanCP = mean(nCPs)) %>% ggplot(aes(Lapse,Gamma)) +
geom_tile(aes(fill = meanCP), colour = "white") +
scale_fill_gradient(low = "white", high = "steelblue")
output %>% group_by(Lapse, Gamma) %>% filter(Trial == 500) %>% summarise(meanslope = mean(Slopes)) %>%
ggplot(aes(Lapse, Gamma)) + geom_tile(aes(fill = meanslope), colour = "white") +
scale_fill_gradient(low = "white", high = "steelblue")
require(MCMCglmm)
prior1<-list(R=list(V=1, nu=0.002), G=list(G1=list(V=1, nu=1,
alpha.mu=0, alpha.V=100)))
finaloutput <- output %>% filter(Trial == 500)
y.mcmc<-MCMCglmm(CumSs ~ Gamma*Lapse,
random=~Run, family=c("gaussian"),
nitt=1300000,thin=1000,burnin=300000,
data=finaloutput, prior=prior1,
verbose=FALSE, pr=TRUE)
summary(y.mcmc)
y.mcmc<-MCMCglmm(cbind(CumSs,Trial) ~ Gamma*Lapse,
random=~Run, family=c("multinomial2"),
nitt=1300000,thin=1000,burnin=300000,
data=finaloutput, prior=prior1,
verbose=FALSE, pr=TRUE)
summary(y.mcmc)
y.mcmc<-MCMCglmm(cbind(CumSs,Trial-CumSs) ~ Gamma*Lapse,
random=~Run, family=c("multinomial2"),
nitt=1300000,thin=1000,burnin=300000,
data=finaloutput, prior=prior1,
verbose=FALSE, pr=TRUE)
summary(y.mcmc)
View(finaloutput)
