-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiffusion_App_presentation.Rmd
144 lines (108 loc) · 4.54 KB
/
Diffusion_App_presentation.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
---
title: "Diffusion Application Presentation"
author: "Use page up/down to navigate"
output: ioslides_presentation
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## The Psychology of Decision Making
People make decisions all the time, but have you ever wondered how these decisions occur in our mind?
The app I created offers the user an opportunity to delve into the decision making process
and develop an intuitive understanding.
This decision process is captured by the diffusion model which is a well known model
of decision making in psychology with parameters that are psychologically interpretable.
The user can adjust these parameters to see how they influence the time course of
the decision making process.
## What is the Diffusion Model?
The diffusion model is a stochastic theoretical model of decision making.
In the context of simple 2 choice decisions, the model assumes that information is accumulated
until a decision criterion (representing one of two response options) is reached at which
point a response is made.
The model produces predicted response time distributions and response proportions
for decision processes that terminate at the top and bottom decision boundaries.
## Diffusion Model Parameters {.smaller}
As was mentioned earlier, the diffusion model has parameters that are psychologically
interpretable. Here is a brief explanation of the most important parameters.
-**Drift rate (v)** is rate of information accumulation and dictates how quickly an individual
accumulates information towards one response boundary or another.
-**Boundary separation (a)** is a threshold parameter that represents how much information
is required before a response is initiated. This is set by an individual and is
interpreted as how cautious someone is in their responding.
-**Starting point (z)** represents where the information accumulation process begins. This
captures biases in preference for one response over another. Positive values make
it more likely and quicker for a response to terminate at the upper boundary and
vice versa for negative values.
## Diffusion Model Simulation {.smaller}
```{r Code to generate diffusion simulation}
library(tidyverse)
library(gganimate)
library(gifski)
library(grDevices)
library(RColorBrewer)
brownian<-function(T,N,delta,z){
# T is time interval of diffusion process
# N is the number of steps
# delta determines speed of brownian motion
# z is starting point of the diffusion process
dt<-T/N
# create vector of random variables
r<-rnorm(N,0,1*delta*sqrt(dt))
# incorporate starting point random variables
r<-c(z,r)
# Brownian Motion is calculated by a cumulative sum of the random samples
brown<-cumsum(r)
return(brown)
}
brownian_drift<-function(T,N,delta,z,v,sigma){
# T is time interval of diffusion process
# N is the number of steps
# delta determines speed of brownian motion
# z is starting point of the diffusion process
# v is the drift rate (coefficient)
# sigma is the variability in drift
brown<-brownian(T,N,delta,z)
dt=T/N
time_steps<-seq(from=0,to=N*dt,length.out = N+1)
V<-v*time_steps+sigma*brown
return(V)
}
#Parameters
sigma<-1 # diffusion coefficient
v<-.1 #drift rate
z<-0 # Starting point
a<-15 # Boundary
N=1000
T=2*(a/v*sigma)
nsim=5
delta=1
brown_drift<-matrix(0,nrow=N+1,ncol=nsim)
t<-seq(from=0,to=N*(T/N),length.out = N+1)
for(sim in 1:nsim){
brown_drift[,sim]<-brownian_drift(T,N,delta,z,v,sigma)
}
driftdata<-data.frame(t,brown_drift)
colnames(driftdata)<-c("Timestep",paste0("Sim",seq(1:nsim)))
df <- driftdata %>%
select(Timestep, paste0("Sim",seq(1:nsim))) %>%
gather(key = "Simulation", value = "Evidence", -Timestep)
newdf<-data.frame()
for(i in 1:nsim){
first<-which(df$Simulation==paste0("Sim",i))[1]
ind<-which(df$Simulation==paste0("Sim",i)&(df$Evidence>=a|df$Evidence<=-a))[1]
if(is.na(ind)){ind<-first+N}
newdf<-rbind(newdf,df[first:ind,])
}
cols<-brewer.pal(3,"BuGn")
pal<-colorRampPalette(cols)
simplot<-ggplot(newdf,aes(x=Timestep,y=Evidence))+geom_path(aes(color=Simulation))+
geom_hline(yintercept=c(a,-a),color='red',size=1.5)+
scale_color_brewer(palette = "Dark2")+
ggtitle("Simulation of 5 Individual Decisions",
subtitle = paste('v = ',v,'z = ',z,'a = ',a))+
theme(plot.title = element_text(hjust=.5),plot.subtitle = element_text(hjust=.5))
```
```{r plot of Decision Time course, echo=TRUE,size='tiny'}
simplot<-simplot+transition_reveal(Timestep)
animate(simplot,nframes=75,renderer=gifski_renderer())
```