Commit 1e2e9098 authored by Simon Ciranka's avatar Simon Ciranka
Browse files

added latest probabilistic sims and new figures

parent 57c72c28
---
title: "Make_figs"
author: "Simon"
date: "28/01/2021"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r fig.width=12,fig.height=6}
library("viridis")
envirionmentMeanKids=seq(-50,50,length.out=5)#define the range of kid envirionemt
envirionmentVarianceKids=seq(1,10,length.out=5)
EnvirionemntKids=expand.grid(Mean=envirionmentMeanKids,Variance=envirionmentVarianceKids)# we sample from this later
#define the range of adolescent environment
envirionmentMeanAdol=seq(-100,100,length.out=12)
envirionmentVarianceAdol=seq(1,80,length.out=12)
EnvirionemntAdol=expand.grid(Mean=envirionmentMeanAdol,Variance=envirionmentVarianceAdol)
EnvirionemntAdol%>%ungroup()
EnvirionemntAdol%>%dplyr::rowwise()%>%mutate(value=rnorm(1,mean = Mean,sd=Variance))%>%
ggplot(aes(x=Mean,y=Variance,fill=value))+geom_tile()+
scale_fill_viridis(name="Outcome",option="plasma",direction = -1)+
geom_hline(aes(yintercept=40),size=2)+
geom_vline(aes(xintercept=0),size=2)+
annotate("text",x=50,y=38,label=c("Low Risk / Reward"))+
annotate("text",x=-50,y=38,label=c("Low Risk / Loss"))+
annotate("text",x=50,y=42,label=c("High Risk / Reward"))+
annotate("text",x=-50,y=42,label=c("High Risk / Loss"))+
ggtitle("Adolescent Environment")+theme_minimal()+theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())->Adolescent
EnvirionemntAdol%>%dplyr::rowwise()%>%mutate(value=rnorm(1,mean = Mean,sd=Variance))%>%
ggplot(aes(x=Mean,y=Variance,fill=value,alpha=Mean>-46&Variance<40&Mean<46))+geom_tile()+
scale_fill_viridis(name="Outcome",option="plasma",direction = -1)+
scale_alpha_discrete(range = c(1, 0.6))+
geom_hline(aes(yintercept=40),size=2)+
geom_vline(aes(xintercept=0),size=2)+
guides(alpha=F)+theme_minimal()+theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())->Kid
legend=cowplot::get_legend(Kid)
cowplot::plot_grid(Kid+theme(legend.position="none"),
Adolescent+theme(legend.position="none",
axis.title.y = element_text(colour="white")),
legend,ncol =3,rel_widths = c(1,1,0.2))
ggsave(plot=Kid,filename = "/X_Figures/Environment_new2.png")
ggsave(filename = "../X_Figures/Environments.png")
```
```{r, fig.width=5,fig.height=5}
x=-300:300
tibble(y=dnorm(x,mean=100,sd=80),
x=x)%>%
ggplot(aes(y=y,x=x,color=x>0))+geom_line(size=3)+
scale_y_continuous(name="probability")+
scale_x_continuous(name="Outcome value")+
scale_color_discrete(name="Outcome",breaks=c("TRUE","FALSE"),labels=c("Loss","Win"))+
theme_cowplot()+theme(axis.text.y = element_blank(),
panel.border = element_rect(colour = "black", fill=NA, size=2),
legend.position = c(0.75,0.8))
ggsave("../X_Figures/HighRiskHighRew.png",dpi=300,height = 5,width = 5)
tibble(y=dnorm(x,mean=100,sd=10),
x=x)%>%
ggplot(aes(y=y,x=x,color=x>0))+geom_line(size=3)+
scale_y_continuous(name="probability")+
scale_x_continuous(name="Outcome value")+
scale_color_discrete(name="Outcome",breaks=c("TRUE","FALSE"),labels=c("Loss","Win"))+
theme_cowplot()+theme(axis.text.y = element_blank(),
panel.border = element_rect(colour = "black", fill=NA, size=2),
legend.position = c(0.75,0.8))
ggsave("../X_Figures/LowRiskHighRew.png",dpi=300,height = 5,width = 5)
tibble(y=dnorm(x,mean=-100,sd=80),
x=x)%>%
ggplot(aes(y=y,x=x,color=x>0))+geom_line(size=3)+
scale_y_continuous(name="probability")+
scale_x_continuous(name="Outcome value")+
scale_color_discrete(name="Outcome",breaks=c("TRUE","FALSE"),labels=c("Loss","Win"))+
theme_cowplot()+theme(axis.text.y = element_blank(),
panel.border = element_rect(colour = "black", fill=NA, size=2),
legend.position = c(0.75,0.8))
ggsave("../X_Figures/HighRiskLowRew.png",dpi=300,height = 5,width = 5)
tibble(y=dnorm(x,mean=-100,sd=10),
x=x)%>%
ggplot(aes(y=y,x=x,color=x>0))+geom_line(size=3)+
scale_y_continuous(name="probability")+
scale_x_continuous(name="Outcome value")+
scale_color_discrete(name="Outcome",breaks=c("TRUE","FALSE"),labels=c("Loss","Win"))+
theme_cowplot()+theme(axis.text.y = element_blank(),
panel.border = element_rect(colour = "black", fill=NA, size=2),
legend.position = c(0.75,0.8))
ggsave("../X_Figures/LowRiskLowRew.png",dpi=300,height = 5,width = 5)
```
# Bayes update
```{r}
library(viridis)
x=-20:50
NormalSamples=tibble(values=rnorm(20,mean=25,sd=6))
rbind(
tibble(y=dnorm(x,mean=20,sd=10),x=x)%>%mutate(type="1"),
tibble(y=dnorm(x,mean=25,sd=6),x=x)%>%mutate(type="2")
)%>%
ggplot()+
geom_line(aes(y=y,x=x,color=type),size=3)+
scale_color_viridis_d(name="",option="plasma")+
#scale_alpha_discrete(range=c(0.4,1))+
geom_dotplot(data = NormalSamples,aes(x=values,color="3"),fill="#F1F592",binwidth = 1,dotsize = 1.5)+
#scale_fill_viridis()+
coord_cartesian(ylim=c(0,0.15))+
theme_cowplot(20)+
theme(axis.line.y=element_blank(),
axis.title.y =element_blank(),
axis.text.y =element_blank(),
axis.ticks.y=element_blank()
)->Posterior
rbind(
tibble(y=dnorm(x,mean=20,sd=10),x=x)%>%mutate(type="1")
#tibble(y=dnorm(x,mean=25,sd=3),x=x)%>%mutate(type="Posterior")
)%>%
ggplot()+
geom_line(aes(y=y,x=x,color=type),size=3)+
scale_color_viridis_d(name="",option="plasma")+
#geom_dotplot(data = NormalSamples,aes(x=values,color="Observations (Likelihood)"),fill="grey",binwidth = 1,dotsize = 1.5)+
#scale_fill_viridis()+
theme_cowplot(20)+
coord_cartesian(ylim=c(0,0.15))+
theme(axis.line.y=element_blank(),
axis.title.y =element_blank(),
axis.text.y =element_blank(),
axis.ticks.y=element_blank()
)->Prior
rbind(
tibble(y=dnorm(x,mean=20,sd=10),x=x)%>%mutate(type="1")
#tibble(y=dnorm(x,mean=25,sd=3),x=x)%>%mutate(type="Posterior")
)%>%
ggplot()+
geom_line(aes(y=y,x=x,color=type),size=3)+
scale_color_viridis_d(name="",option="plasma")+
geom_dotplot(data = NormalSamples,aes(x=values,color="2"),fill="#F1F592",binwidth = 1,dotsize = 1.5)+
#scale_fill_viridis()+
coord_cartesian(ylim=c(0,0.15))+theme_cowplot(20)+
theme(axis.line.y=element_blank(),
axis.title.y =element_blank(),
axis.text.y =element_blank(),
axis.ticks.y=element_blank()
)->Outcomes
ggsave(plot=Posterior,filename="../X_Figures/Posterior.png",dpi=330)
ggsave(plot=Outcomes,filename="../X_Figures/Outcomes.png",dpi=330)
ggsave(plot=Prior,filename="../X_Figures/Prior.png",dpi=330)
```
X_Figures/OutcomesSocial2.png

430 KB | W: | H:

X_Figures/OutcomesSocial2.png

504 KB | W: | H:

X_Figures/OutcomesSocial2.png
X_Figures/OutcomesSocial2.png
X_Figures/OutcomesSocial2.png
X_Figures/OutcomesSocial2.png
  • 2-up
  • Swipe
  • Onion skin
X_Figures/OutcomesSolo.png

383 KB | W: | H:

X_Figures/OutcomesSolo.png

481 KB | W: | H:

X_Figures/OutcomesSolo.png
X_Figures/OutcomesSolo.png
X_Figures/OutcomesSolo.png
X_Figures/OutcomesSolo.png
  • 2-up
  • Swipe
  • Onion skin
X_Figures/Sampling_Timecourse.gif

537 KB | W: | H:

X_Figures/Sampling_Timecourse.gif

436 KB | W: | H:

X_Figures/Sampling_Timecourse.gif
X_Figures/Sampling_Timecourse.gif
X_Figures/Sampling_Timecourse.gif
X_Figures/Sampling_Timecourse.gif
  • 2-up
  • Swipe
  • Onion skin
X_Figures/Solo_Social_Outcomes.png

565 KB | W: | H:

X_Figures/Solo_Social_Outcomes.png

522 KB | W: | H:

X_Figures/Solo_Social_Outcomes.png
X_Figures/Solo_Social_Outcomes.png
X_Figures/Solo_Social_Outcomes.png
X_Figures/Solo_Social_Outcomes.png
  • 2-up
  • Swipe
  • Onion skin
X_Figures/SwitchWhereOthersAre.png

154 KB | W: | H:

X_Figures/SwitchWhereOthersAre.png

392 KB | W: | H:

X_Figures/SwitchWhereOthersAre.png
X_Figures/SwitchWhereOthersAre.png
X_Figures/SwitchWhereOthersAre.png
X_Figures/SwitchWhereOthersAre.png
  • 2-up
  • Swipe
  • Onion skin
X_Figures/TimecourseExplore.png

161 KB | W: | H:

X_Figures/TimecourseExplore.png

85.9 KB | W: | H:

X_Figures/TimecourseExplore.png
X_Figures/TimecourseExplore.png
X_Figures/TimecourseExplore.png
X_Figures/TimecourseExplore.png
  • 2-up
  • Swipe
  • Onion skin
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