Objectives

The following analyses are used to compare human trajectories with simulated trajectories generated by path planning algorithms from robotics (simulation codes can be seen here).

The results will be published in Topics in Cognitive Science ( TopiCS).

The article link will be updated here after this publication is available online.

Minimum Frechet Distance

First, we used different strategy-based path algorithms to simulate different navigation strategy-based trajectories given 20 trials. These 20 trials have different start and end locations within the same virtual maze. (See here)). There are 14 strategies can be used for each trial.

Next, we used the Frechet distance to calculate how close the strategy resembled the path taken by each subject. Then, we found the minimum frechet distance for each human trajectory to show on this trial which strategy the human subject used.

load minimum Frechet Distance data

df <- read.csv('minFrechet2.csv')

All: The minimum Frechet Distance among all 14 strategies for each human trajectory. Pure: The minimum Frechet Distance among 4 pure strategies for each human trajectory. Six: The minimum Frechet Distance among 6 major strategies for each human trajectory. Mix: The minimum Frechet Distance among 10 mixed strategies (not pure) for each human trajectory.

summary(df)
##       Pure             All              Mix              Six        
##  Min.   : 0.000   Min.   : 0.000   Min.   : 0.000   Min.   : 0.000  
##  1st Qu.: 1.000   1st Qu.: 1.000   1st Qu.: 1.000   1st Qu.: 1.000  
##  Median : 2.828   Median : 2.236   Median : 2.828   Median : 2.236  
##  Mean   : 2.582   Mean   : 2.448   Mean   : 2.551   Mean   : 2.486  
##  3rd Qu.: 4.000   3rd Qu.: 3.606   3rd Qu.: 3.606   3rd Qu.: 3.606  
##  Max.   :12.806   Max.   :12.806   Max.   :12.806   Max.   :12.806

The following wilcox.test show the mean rank of the Frechet Distance distribution based on all 14 strategies is significantly lower than the mean rank pf the Frechet Distance distribution based on 4 pure strategies

wilcox.test(df$Pure,df$All, paired = T, alternative = "two.sided")
## 
##  Wilcoxon signed rank test with continuity correction
## 
## data:  df$Pure and df$All
## V = 442270, p-value < 2.2e-16
## alternative hypothesis: true location shift is not equal to 0

Strategy Use in the Goto Goal versus Shortcut Condition (Human Subjects)

Goto Goal condition

load strategy used in the Goto Goal condition

df <- read.csv('strategyGoto.csv')
  • 206 human subjects. Each row represents one subject
  • 20 trials for each subject. Each column represents one trial
  • The cell value indicates which strategy (1-14) the subject used on this trial

data transformation

df_long <- gather(df, Trial, Strategy, T2:T24, factor_key=TRUE)
df_long$Instr <- 'Goto Goal'
head(df_long)
##   Trial Strategy     Instr
## 1    T2        3 Goto Goal
## 2    T2        1 Goto Goal
## 3    T2        1 Goto Goal
## 4    T2        4 Goto Goal
## 5    T2        1 Goto Goal
## 6    T2        1 Goto Goal

Shortcut condition

load strategy used in the Shortcut condition

df2 <- read.csv('strategyShortcut.csv')
df2_long <- gather(df2, Trial, Strategy, T2:T24, factor_key=TRUE)
df2_long$Instr <- 'Shortcut'
head(df2_long)
##   Trial Strategy    Instr
## 1    T2        1 Shortcut
## 2    T2        1 Shortcut
## 3    T2        1 Shortcut
## 4    T2        5 Shortcut
## 5    T2        1 Shortcut
## 6    T2        1 Shortcut

Merge data of two conditions

dfstrategy <- rbind.data.frame(df_long,df2_long)
dfstrategy$Strategy <- as.factor(dfstrategy$Strategy)

Show Distribution of Strategy Use in the Goto Goal condition (Figure 6a)

ggplot(dfstrategy[dfstrategy$Instr=="Goto Goal",],aes(x=Strategy))+
  geom_bar(aes(y = (..count..)/sum(..count..)))+
  scale_x_discrete(labels=c("Survey","Topological","Route","Reverse","Sur-Rte","Top-Rte","Sur-Rev",
                            "Top-Rev","Rte-Sur","Rte-Top","Rev-Sur","Rev-Top","Sur-Top","Top-Sur"))+
  ylab("Proportion")+
  xlab("Strategy")+
  ggtitle("A.Goto Goal Instruction")+
  theme_bw(base_size = 20)+
  theme(axis.text.x = element_text(angle = 45, hjust=1),plot.title = element_text(hjust = 0.5))

#ggsave("gotoGoal.png",width=12,height = 5)

Show Distribution of Strategy Use in the Shortcut condition (Figure 6b)

ggplot(dfstrategy[dfstrategy$Instr=="Shortcut",],aes(x=Strategy))+
  geom_bar(aes(y = (..count..)/sum(..count..)))+
  scale_x_discrete(labels=c("Survey","Topological","Route","Reverse","Sur-Rte","Top-Rte","Sur-Rev",
                            "Top-Rev","Rte-Sur","Rte-Top","Rev-Sur","Rev-Top","Sur-Top","Top-Sur"))+
  ylab("Proportion")+
  xlab("Strategy")+
  ggtitle("B.Shortcut Instruction")+
  theme_bw(base_size = 20)+
  theme(axis.text.x = element_text(angle = 45, hjust=1),plot.title = element_text(hjust = 0.5))

#ggsave("shortCut.png",width=12,height = 5)

Get Frequency table for strategy use in different conditions

dfs_sum <- dfstrategy%>%group_by(Instr,Strategy)%>%
  summarise(
    n=n()
  )
dfs_sum [nrow(dfs_sum ) + 1,] <-  c('Shortcut','13',0)
dfs_sum$n <- as.numeric(dfs_sum$n)
dfs_sum
## # A tibble: 28 x 3
## # Groups:   Instr [2]
##    Instr     Strategy     n
##  * <chr>     <fct>    <dbl>
##  1 Goto Goal 1         1510
##  2 Goto Goal 2          540
##  3 Goto Goal 3         1121
##  4 Goto Goal 4          444
##  5 Goto Goal 5           20
##  6 Goto Goal 6           28
##  7 Goto Goal 7           26
##  8 Goto Goal 8           35
##  9 Goto Goal 9          185
## 10 Goto Goal 10          31
## # … with 18 more rows

data transformation

dfs_sum_w <- reshape2::dcast(dfs_sum, Strategy~Instr, value.var="n")
dt <- as.table(t(as.matrix(dfs_sum_w[,-1])))
colnames(dt) <-  c("Survey","Topological","Route","Reverse","Sur-Rte","Top-Rte","Sur-Rev",
                            "Top-Rev","Rte-Sur","Rte-Top","Rev-Sur","Rev-Top","Sur-Top","Top-Sur")
dt
##           Survey Topological Route Reverse Sur-Rte Top-Rte Sur-Rev Top-Rev
## Goto Goal   1510         540  1121     444      20      28      26      35
## Shortcut    1482         445   542     336      20      24      21      13
##           Rte-Sur Rte-Top Rev-Sur Rev-Top Sur-Top Top-Sur
## Goto Goal     185      31     144      16       3      17
## Shortcut      142      25     155      10       0      25

Chi-square test

Show the correlation between strategy use and condition

chi.tst <- chisq.test(dt)
## Warning in chisq.test(dt): Chi-squared approximation may be incorrect
chi.tst
## 
##  Pearson's Chi-squared test
## 
## data:  dt
## X-squared = 146.37, df = 13, p-value < 2.2e-16
chi.tst$statistic
## X-squared 
##  146.3749
chi.tst$residuals
##                Survey Topological       Route     Reverse     Sur-Rte
## Goto Goal -4.02856149 -0.48488460  6.22994302  0.35268327 -0.50535336
## Shortcut   4.54282597  0.54678235 -7.02522402 -0.39770492  0.56986405
##               Top-Rte     Sur-Rev     Top-Rev     Rte-Sur     Rte-Top
## Goto Goal -0.20549486 -0.06039464  1.56849613  0.14420923 -0.06212386
## Shortcut   0.23172723  0.06810430 -1.76872190 -0.16261820  0.07005426
##               Rev-Sur     Rev-Top     Sur-Top     Top-Sur
## Goto Goal -1.80678437  0.37893737  1.01910310 -1.34277934
## Shortcut   2.03742874 -0.42731048 -1.14919632  1.51419132

Visualization: Pearson Residuals of Chi-square Independence Test (Figure 6c)

library(corrplot)
## corrplot 0.84 loaded
#jpeg("residul.png", width = 12, height = 2.5, units = 'in', res = 300)
title <- "C.Pearson Residuals of Chi-square Independence Test"
corrplot(chi.tst$residuals,is.cor = FALSE,method = "color",title=title,mar=c(0,0,1,0))

#dev.off()

Visualization: Relative Contribution of Each Cell to the Total Chi-square Score (Figure 6d)

contrib <- 100*chi.tst$residuals^2/chi.tst$statistic
round(contrib, 3)
##           Survey Topological  Route Reverse Sur-Rte Top-Rte Sur-Rev
## Goto Goal 11.087       0.161 26.516   0.085   0.174   0.029   0.002
## Shortcut  14.099       0.204 33.717   0.108   0.222   0.037   0.003
##           Top-Rev Rte-Sur Rte-Top Rev-Sur Rev-Top Sur-Top Top-Sur
## Goto Goal   1.681   0.014   0.003   2.230   0.098   0.710   1.232
## Shortcut    2.137   0.018   0.003   2.836   0.125   0.902   1.566
#jpeg("contribu.png", width = 12, height = 2.5, units = 'in', res = 300)
title <- "D.Relative Contribution of Each Cell to the Total Chi-square Score"
corrplot(contrib, is.cor = FALSE,title=title,mar=c(0,0,1,0))

#dev.off()

##Strategy Variation (SV) distribution

SV indicates how likely each subject varies his strategies across 20 trials.

load SV data for both conditions

svgtg <- read.csv('SVGotoGoal.csv')
svst <- read.csv('SVShortcut.csv')
svgtg$Instr <- 'Goto Goal'
svst$Instr <- 'Shortcut'
sv <- rbind(svgtg,svst)
colnames(sv)[1] <- 'SV'

Visualize distributions of SV in two conditions (Figure 8)

library(viridis)
## Loading required package: viridisLite
library(hrbrthemes)
## NOTE: Either Arial Narrow or Roboto Condensed fonts are required to use these themes.
##       Please use hrbrthemes::import_roboto_condensed() to install Roboto Condensed and
##       if Arial Narrow is not on your system, please see https://bit.ly/arialnarrow
ggplot(sv, aes(x=Instr, y=SV, fill=Instr,color=Instr))+
  geom_violin()+
  scale_fill_viridis(discrete = TRUE, alpha=0.7, option="B")+
  scale_color_viridis(discrete = TRUE, alpha=1, option="E")+
  geom_jitter(height = 0, width = 0.1,alpha=0.3)+
  scale_x_discrete(name = "Instructions",labels=c("Goto Goal","Shortcut"))+
  ylim(0.05,.97)+
  ylab("Strategy Variation")+
  theme_ipsum(base_size = 20, axis_title_size = 20,axis_title_just="m")+
  theme(
      legend.position="none"
    )

#ggsave("SV.png",width = 8,height = 5)

t-test for SV

The following independent t-test shows the mean of SV in the Go toGoal conditioon is not significantly different from the mean of SV in the Shortcut condition

t.test(sv$SV~sv$Instr,var.equal=T)
## 
##  Two Sample t-test
## 
## data:  sv$SV by sv$Instr
## t = 0.48563, df = 366, p-value = 0.6275
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.01713648  0.02837601
## sample estimates:
## mean in group Goto Goal  mean in group Shortcut 
##               0.5424584               0.5368386

The following one-sample t-test shows the mean of SV in both conditioons is significantly smaller than 0.965 (which is theoretically largest value of SV, indicating no variation across 20 trials).

t.test(sv$SV,mu=0.965)
## 
##  One Sample t-test
## 
## data:  sv$SV
## t = -74.063, df = 367, p-value < 2.2e-16
## alternative hypothesis: true mean is not equal to 0.965
## 95 percent confidence interval:
##  0.5286998 0.5512691
## sample estimates:
## mean of x 
## 0.5399845

The second set of simulation for cost investigation

####load simulated agents’ strategies

simgtg <- read.csv('SimGotoGoal.csv')
simst <- read.csv('SimShortcut.csv')

data transformation

simgtg$Instr <- 'Goto Goal'
simst$Instr <- 'Shortcut'
sim <- rbind(simgtg,simst)
colnames(sim)[1] <- 'Strategy'
sim_sum <- sim%>%group_by(Instr,Strategy)%>%
  summarise(
    n=n()
  )
sim_sum_w <- reshape2::dcast(sim_sum, Strategy~Instr, value.var="n")
sim_sum_w
##   Strategy Goto Goal Shortcut
## 1        1        35       50
## 2        2        10       10
## 3        3         8        4
## 4        4        17       10
## 5        5         3        2
## 6        9         3        3
## 7       11         4        1

Show Distribution of Strategy Use in the simulated Goto Goal condition (Figure 10a)

ggplot(sim[sim$Instr=="Goto Goal",],aes(x=Strategy))+
  geom_bar(aes(y = (..count..)/sum(..count..)))+
  scale_x_continuous(name="Strategy", breaks =c(1:11),labels=c("Survey","Topological","Route","Reverse","Sur-Rte","Top-Rte","Sur-Rev",
                            "Top-Rev","Rte-Sur","Rte-Top","Rev-Sur"))+
  ylab("Proportion")+
  xlab("Strategy")+
  ggtitle("A.Simulation of Goto Goal")+
  theme_bw(base_size = 20)+
  theme(axis.text.x = element_text(angle = 45, hjust=1),plot.title = element_text(hjust = 0.5))

#ggsave("simgotoGoal.png",width=10,height = 5)

Show Distribution of Strategy Use in the simulated Shortcut condition (Figure 10b)

ggplot(sim[sim$Instr=="Shortcut",],aes(x=Strategy))+
  geom_bar(aes(y = (..count..)/sum(..count..)))+
  scale_x_continuous(name="Strategy", breaks =c(1:11),labels=c("Survey","Topological","Route","Reverse","Sur-Rte","Top-Rte","Sur-Rev",
                            "Top-Rev","Rte-Sur","Rte-Top","Rev-Sur"))+
  ylab("Proportion")+
  xlab("Strategy")+
  ggtitle("B.Simulation of Shortcut")+
  theme_bw(base_size = 20)+
  theme(axis.text.x = element_text(angle = 45, hjust=1),plot.title = element_text(hjust = 0.5))

#ggsave("simshortCut.png",width=10,height = 5)

Show simulated results are similar to human results

For more discussions on these results, see section 3.2 in the paper

dfs_sum
## # A tibble: 28 x 3
## # Groups:   Instr [2]
##    Instr     Strategy     n
##  * <chr>     <fct>    <dbl>
##  1 Goto Goal 1         1510
##  2 Goto Goal 2          540
##  3 Goto Goal 3         1121
##  4 Goto Goal 4          444
##  5 Goto Goal 5           20
##  6 Goto Goal 6           28
##  7 Goto Goal 7           26
##  8 Goto Goal 8           35
##  9 Goto Goal 9          185
## 10 Goto Goal 10          31
## # … with 18 more rows
#Rte or Rev strategies -Goto Goal
prop.test(c(25,1121+444),c(80,4120))
## 
##  2-sample test for equality of proportions with continuity
##  correction
## 
## data:  c(25, 1121 + 444) out of c(80, 4120)
## X-squared = 1.2406, df = 1, p-value = 0.2654
## alternative hypothesis: two.sided
## 95 percent confidence interval:
##  -0.17637102  0.04166229
## sample estimates:
##    prop 1    prop 2 
## 0.3125000 0.3798544
#Rte or Rev strategies -Shortcut
prop.test(c(14,542+336),c(80,4120))
## 
##  2-sample test for equality of proportions with continuity
##  correction
## 
## data:  c(14, 542 + 336) out of c(80, 4120)
## X-squared = 0.47249, df = 1, p-value = 0.4918
## alternative hypothesis: two.sided
## 95 percent confidence interval:
##  -0.12867428  0.05246069
## sample estimates:
##    prop 1    prop 2 
## 0.1750000 0.2131068
#route to survey -Goto Goal
prop.test(c(7,144+185),c(80,4120))
## 
##  2-sample test for equality of proportions with continuity
##  correction
## 
## data:  c(7, 144 + 185) out of c(80, 4120)
## X-squared = 0.0017313, df = 1, p-value = 0.9668
## alternative hypothesis: two.sided
## 95 percent confidence interval:
##  -0.06119545  0.07648671
## sample estimates:
##     prop 1     prop 2 
## 0.08750000 0.07985437
#route to survey -Shortcut
prop.test(c(4,142+155),c(80,3240))
## 
##  2-sample test for equality of proportions with continuity
##  correction
## 
## data:  c(4, 142 + 155) out of c(80, 3240)
## X-squared = 1.1775, df = 1, p-value = 0.2779
## alternative hypothesis: two.sided
## 95 percent confidence interval:
##  -0.09685200  0.01351866
## sample estimates:
##     prop 1     prop 2 
## 0.05000000 0.09166667