Skip to content
Snippets Groups Projects
Commit 4a14fd81 authored by Xianzong Meng's avatar Xianzong Meng
Browse files

clean spare codes

parent 8b94ffd0
No related branches found
No related tags found
No related merge requests found
......@@ -322,13 +322,9 @@ labs(x = "positions", y = "approaching score")+
theme_classic() + facet_wrap(~ restriction, ncol = 2)
Fig_LE_approaching
ggsave('C:/Users/xiamen/Desktop/modified robogator/result figs/Fig_LE_approaching.svg', plot = Fig_LE_approaching, device = 'svg',dpi = 300)
<<<<<<< HEAD
=======
```
## Fig4
```{r}
>>>>>>> b86c3dabbc987a1a3471a93de7959760021346f0
Fig4 <- ggarrange(Fig_LE_leaving, Fig_LE_approaching, ncols=2,labels=c('A','B'), common.legend=TRUE,legend="none")
Fig4
ggsave('C:/Users/xiamen/Desktop/modified robogator/result figs/Fig4.svg', plot = Fig4, device = 'svg',dpi = 300, width = 176, height = 140, units = "mm")
......@@ -407,24 +403,25 @@ approaching_emm_trials_sex
## approaching figure_restriction_sex
```{r}
LE_Rday1_approaching_M <- ggplot(df.LE_Rday1_approaching_M, aes(x=trials, y=approaching.score, group=rat_ID))
LE_Rday1_approaching_M +
fig4c <- ggplot(df.LE_Rday1_approaching_M, aes(x=trials, y=approaching.score, group=rat_ID)) +
geom_line(color="gray", alpha=0.2)+
stat_summary(fun = "mean", size = 1, aes(group = restriction, color= restriction), geom = "line", fun.min = 'sd', fun.max = 'sd')+
stat_summary(fun.data = mean_se, aes(group = restriction, color= restriction), geom = "errorbar", alpha=1, width=0.05)+
scale_color_manual(values = c("#7fc97f", "#fdc086"))+
stat_summary(fun.data = mean_se, aes(group = restriction, color= restriction), geom = "errorbar", alpha=1, width=0.05) +
scale_color_manual(values = c("#8DA0CB", "#E78AC3"))+
scale_y_continuous(breaks = seq(0, 7, by = 1))+
theme_minimal() + facet_wrap(~ restriction, ncol = 2)
labs(x = "positions", y = "approaching score") + theme_classic() + facet_wrap(~restriction, ncol = 2)
fig4c
LE_Rday1_approaching_F <- ggplot(df.LE_Rday1_approaching_F, aes(x=trials, y=approaching.score, group=rat_ID))
LE_Rday1_approaching_F +
fig4d <- ggplot(df.LE_Rday1_approaching_F, aes(x=trials, y=approaching.score, group=rat_ID)) +
geom_line(color="gray", alpha=0.2)+
stat_summary(fun = "mean", size = 1, aes(group = restriction, color= restriction), geom = "line", fun.min = 'sd', fun.max = 'sd')+
stat_summary(fun.data = mean_se, aes(group = restriction, color= restriction), geom = "errorbar", alpha=1, width=0.05)+
scale_color_manual(values = c("#7fc97f", "#fdc086"))+
stat_summary(fun.data = mean_se, aes(group = restriction, color= restriction), geom = "errorbar", alpha=1, width=0.05) +
scale_color_manual(values = c("#8DA0CB", "#E78AC3"))+
scale_y_continuous(breaks = seq(0, 7, by = 1))+
theme_minimal() + facet_wrap(~ restriction, ncol = 2)
labs(x = "positions", y = "approaching score") + theme_classic() + facet_wrap(~restriction, ncol = 2)
fig4d
Fig4c_d <- ggarrange(Fig_LE_leaving,Fig_LE_approaching,fig4c,fig4d,ncol=2,nrow=2,labels=c('A','B','C','D'),common.legend=TRUE,legend="none")
Fig4c_d
ggsave('C:/Users/xiamen/Desktop/modified robogator/result figs/Fig4c_d.svg', plot = Fig4c_d, device = 'svg',dpi = 300, width = 176, height = 140, units = "mm")
```
## packages loading
```{r}
#General utility packages
library(tidyverse)
library(glue)
library(knitr)
library(data.table)
#Stats packages
library(lme4)
library(multcomp)
library(parameters)
library(effectsize)
library(performance)
library(emmeans)
#Plot packages
library(ggpubr)
```
## loading table
```{r}
df <- read_csv('C:/Users/xiamen/Desktop/data_for_R/modified_robogator_paper/robotmod_distance.csv') %>%
mutate(trials = as.factor(trials)) %>%
mutate(group = as.factor(group)) %>%
mutate(sex = as.factor(sex)) %>%
mutate(rat_ID = as.factor(rat_ID)) %>%
mutate(restriction = as.factor(restriction))%>%
mutate(age = as.factor(age))%>%
mutate(food.distance.cm = as.factor(food.distance.cm))%>%
mutate(robot = as.factor(robot))%>%
# Create score based on time. Following log attribution of score as a function of time.
mutate(leaving.score = case_when(is.na(leaving.sec) ~ 7,
leaving.sec >= 200 ~ 6,
leaving.sec >= 100 ~ 5,
leaving.sec >= 50 ~ 4,
leaving.sec >= 25 ~ 3,
leaving.sec >= 12.5 ~ 2,
leaving.sec >= 6.25 ~ 1,
leaving.sec <6.25 ~ 0)) %>%
mutate(approaching.score = case_when(is.na(approaching.sec) ~ 7,
approaching.sec >= 200 ~ 6,
approaching.sec >= 100 ~ 5,
approaching.sec >= 50 ~ 4,
approaching.sec >= 25 ~ 3,
approaching.sec >= 12.5 ~ 2,
approaching.sec >= 6.25 ~ 1,
approaching.sec <6.25 ~ 0)) %>%
mutate(backing.score = case_when(is.na(backing.sec) ~ 7,
backing.sec >= 200 ~ 6,
backing.sec >= 100 ~ 5,
backing.sec >= 50 ~ 4,
backing.sec >= 25 ~ 3,
backing.sec >= 12.5 ~ 2,
backing.sec >= 6.25 ~ 1,
backing.sec <6.25 ~ 0)) %>%
mutate(foraging.score = case_when(is.na(foraging.sec) ~ 7,
foraging.sec >= 200 ~ 6,
foraging.sec >= 100 ~ 5,
foraging.sec >= 50 ~ 4,
foraging.sec >= 25 ~ 3,
foraging.sec >= 12.5 ~ 2,
foraging.sec >= 6.25 ~ 1,
foraging.sec <6.25 ~ 0))
#head(df) %>% kable("pipe")
```
## distance effect
```{r}
df.Bline <- df %>% filter(df$baseline.day == 6)
df.Rday <- df %>% filter(df$robot.day == 1)
```
## liner mixed effect model
```{r}
robot <- lmer(foraging.score~ sex + trials + robot + sex:trials + sex:robot + trials:robot + (1|rat_ID), df)
robot_sex_trials <- update(robot, . ~ . - sex:trials)
robot_sex_robot <- update(robot, . ~ . - sex:robot)
robot_trials_robot <- update(robot, . ~ . - trials:robot)
robot_robot <- lmer(foraging.score~ sex + trials + sex:trials + (1|rat_ID), df)
anova(robot, robot_robot)
eta_squared(robot)
```
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment