##Set working directory
setwd("C:/Users/ChanRW/OneDrive - Universiteit Twente/2020_MSCA_IF/2_Bachelor_thesis/2022_Joel_Broncho_X/Data")
##Packages that are required for the analysis
library(tidyverse)
library(broom.mixed)
library(devtools)
library(brms)
library(mascutils)
library(bayr)
library(readxl)
library(ggplot2)
library(effects)
##Import dataset
#dfAcc3<-read.table("Acc_Task3_1.csv", sep = ",", header = T, stringsAsFactors = F)
#dfAcc2<-read.table("Acc_Task1_220124_4.csv", sep = ",", header = T, stringsAsFactors = F)
df1<-read.table("Task1Behav.csv", sep = ",", header = T, stringsAsFactors = F)
df3<-read.table("Task3Behav.csv", sep = ",", header = T, stringsAsFactors = F)
##USELESS Free learning curves (ROUGHT AND NOT ACCURATE)
#dfAcc3 %>%
#filter(RT < 10) %>%
#ggplot(aes(x = Time,
#y = DomHandX)) +
#geom_point() +
#geom_smooth(se = F) +
#facet_wrap(~Subject, scales = "free_y")
#dfAcc1 %>%
#filter(RT < 10) %>%
#ggplot(aes(x = Time,
#y = DomHandX,
#group = Part)) +
#facet_grid(~Trial) +
#geom_smooth(se = F)
#dfAcc1 %>%
#filter(RT < 10) %>%
#ggplot(aes(x = Time,
#y = DomHand_X,
#group = Subject)) +
#facet_grid(~Trial) +
#geom_smooth(se = F)
#df %>%
#filter(RT < 10) %>%
#ggplot(aes(x = repetition,
#y = RT,
#group = subject)) +
#geom_smooth(se = F)
#Proper
df1$Subject <- factor(df1$Subject)
df3$Subject <- factor(df3$Subject)
mycolors=c("#6b5f3c","#ccc627","#54ab8e","#587ed1","#b04366","#de2d26","#d95f0e", "#a1d99b", "#dd1c77", "#a6bddb")
## FREE LEARNING CURVES ##
# Free learning curve 1
# per subject per sequence
df1 %>%
ggplot(aes(x = Trial,
y = MT,
color=Subject)) +
geom_point() +
geom_smooth(se = F) +
facet_wrap(~Subject, scales = "free_y")+
ylab("MT (s)")+
xlab("Time")+
ylim(0,250)+
theme_classic()+
scale_color_manual(values=mycolors)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at 0.98
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at 0.98
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at 0.98
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at 0.98
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at 0.98
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at 0.98
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at 0.98
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at 0.98
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at 0.98
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at 0.98
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804

df3 %>%
ggplot(aes(x = Trial,
y = MT,
color=Subject)) +
geom_point() +
geom_smooth(se = F) +
facet_wrap(~Subject, scales = "free_y")+
ylab("MT (s)")+
xlab("Time")+
ylim(250,1000)+
theme_classic()+
scale_color_manual(values=mycolors)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at 0.99
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 1.0201
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at 0.99
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 1.0201
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at 0.99
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 1.0201
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at 0.99
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 1.0201
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at 0.99
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 1.0201
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at 0.99
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 1.0201
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at 0.99
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 1.0201
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at 0.99
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 1.0201
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at 0.99
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 1.0201
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at 0.99
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 1.0201

# Free learning curve 2
# Individual learning curves over blocks/reps
df1 %>%
ggplot(aes(x = Trial,
y = MT,
group = Subject,
color= Subject)) +
geom_smooth(se = F)+
#scale_x_continuous(limits = c(0,192), expand = c(0, 0))+
theme_classic()+
ylab("MT (s)")+
xlab("Time")+
scale_color_manual(values=mycolors)+
facet_wrap(~Trial)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

#Over Trials / TimeRepX
df1 %>%
ggplot(aes(x = Rep,
y = MT,
group = Subject,
color=Subject)) +
geom_smooth(se = F)+
#scale_x_continuous(limits = c(0,192), expand = c(0, 0))+
theme_classic()+
ylab("MT (s)")+
xlab("Rep")+
scale_color_manual(values=mycolors)+
facet_wrap(~Subject)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804

df3 %>%
ggplot(aes(x = Rep,
y = MT,
group = Subject,
color=Subject)) +
geom_smooth(se = F)+
#scale_x_continuous(limits = c(0,192), expand = c(0, 0))+
theme_classic()+
ylab("MT (s)")+
xlab("Rep")+
scale_color_manual(values=mycolors)+
facet_wrap(~Subject)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 1.0201
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 1.0201
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 1.0201
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 1.0201
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 1.0201
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 1.0201
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 1.0201
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 1.0201
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 1.0201
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 1.0201

#geom_vline(xintercept = c(24,48,72,96,120,144,168),colour="grey”, show.legend=TRUE)+
#geom_text(aes(x=12, label="Trial_1", y=0.1), colour="grey") +
#geom_text(aes(x=36, label="Trial 2", y=0.1), colour="grey") +
#geom_text(aes(x=60, label="Trial 3", y=0.1), colour="grey") +
#geom_text(aes(x=84, label="Trial 4", y=0.1), colour="grey") +
#geom_text(aes(x=108, label="Trial 5", y=0.1), colour="grey")
#geom_vline(xintercept = c(24,48,72,96,120,144,168),colour="grey”, show.legend=TRUE)+
#geom_text(aes(x=12, label="Block 1", y=0.1), colour="grey") +
#geom_text(aes(x=36, label="Block 2", y=0.1), colour="grey") +
#geom_text(aes(x=60, label="Block 3", y=0.1), colour="grey") +
#geom_text(aes(x=84, label="Block 4", y=0.1), colour="grey") +
#geom_text(aes(x=108, label="Block 5", y=0.1), colour="grey") +
#geom_text(aes(x=132, label="Block 6", y=0.1), colour="grey") +
#geom_text(aes(x=156, label="Block 7", y=0.1), colour="grey") +
#geom_text(aes(x=180, label="Block 8", y=0.1), colour="grey")
## NON-LINEAR MULTILEVEL REGRESSION ##
# specify formula, variables and weakly informative priors
F_ary <- formula(MT ~ asym + ampl * exp(-rate * Rep))
F_ary_ef_1 <- list(formula(ampl ~ 1|Subject),
formula(rate ~ 1|Subject),
formula(asym ~ 1|Subject))
F_ary_prior <- c(set_prior("normal(5, 100)", nlpar = "ampl", lb = 0),
set_prior("normal(.5, 3)", nlpar = "rate", lb = 0),
set_prior("normal(3, 20)", nlpar = "asym", lb = 0))
# create model including MCMC sampling
M_1 <-
df1 %>%
brm(bf(F_ary,
flist = F_ary_ef_1,
nl = T),
prior = F_ary_prior,
family = "exgaussian",
data = .,
iter = 10,
warmup = 8,
save_pars=save_pars("Subject"))
## Compiling Stan program...
## Start sampling
##
## SAMPLING FOR MODEL 'cd137cae3425170764c33899873035dd' NOW (CHAIN 1).
## Chain 1: Rejecting initial value:
## Chain 1: Log probability evaluates to log(0), i.e. negative infinity.
## Chain 1: Stan can't start sampling from this initial value.
## Chain 1:
## Chain 1: Gradient evaluation took 0 seconds
## Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
## Chain 1: Adjust your expectations accordingly!
## Chain 1:
## Chain 1:
## Chain 1: WARNING: No variance estimation is
## Chain 1: performed for num_warmup < 20
## Chain 1:
## Chain 1: Iteration: 1 / 10 [ 10%] (Warmup)
## Chain 1: Iteration: 2 / 10 [ 20%] (Warmup)
## Chain 1: Iteration: 3 / 10 [ 30%] (Warmup)
## Chain 1: Iteration: 4 / 10 [ 40%] (Warmup)
## Chain 1: Iteration: 5 / 10 [ 50%] (Warmup)
## Chain 1: Iteration: 6 / 10 [ 60%] (Warmup)
## Chain 1: Iteration: 7 / 10 [ 70%] (Warmup)
## Chain 1: Iteration: 8 / 10 [ 80%] (Warmup)
## Chain 1: Iteration: 9 / 10 [ 90%] (Sampling)
## Chain 1: Iteration: 10 / 10 [100%] (Sampling)
## Chain 1:
## Chain 1: Elapsed Time: 0.002 seconds (Warm-up)
## Chain 1: 0.001 seconds (Sampling)
## Chain 1: 0.003 seconds (Total)
## Chain 1:
##
## SAMPLING FOR MODEL 'cd137cae3425170764c33899873035dd' NOW (CHAIN 2).
## Chain 2:
## Chain 2: Gradient evaluation took 0 seconds
## Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
## Chain 2: Adjust your expectations accordingly!
## Chain 2:
## Chain 2:
## Chain 2: WARNING: No variance estimation is
## Chain 2: performed for num_warmup < 20
## Chain 2:
## Chain 2: Iteration: 1 / 10 [ 10%] (Warmup)
## Chain 2: Iteration: 2 / 10 [ 20%] (Warmup)
## Chain 2: Iteration: 3 / 10 [ 30%] (Warmup)
## Chain 2: Iteration: 4 / 10 [ 40%] (Warmup)
## Chain 2: Iteration: 5 / 10 [ 50%] (Warmup)
## Chain 2: Iteration: 6 / 10 [ 60%] (Warmup)
## Chain 2: Iteration: 7 / 10 [ 70%] (Warmup)
## Chain 2: Iteration: 8 / 10 [ 80%] (Warmup)
## Chain 2: Iteration: 9 / 10 [ 90%] (Sampling)
## Chain 2: Iteration: 10 / 10 [100%] (Sampling)
## Chain 2:
## Chain 2: Elapsed Time: 0.002 seconds (Warm-up)
## Chain 2: 0.001 seconds (Sampling)
## Chain 2: 0.003 seconds (Total)
## Chain 2:
##
## SAMPLING FOR MODEL 'cd137cae3425170764c33899873035dd' NOW (CHAIN 3).
## Chain 3:
## Chain 3: Gradient evaluation took 0 seconds
## Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
## Chain 3: Adjust your expectations accordingly!
## Chain 3:
## Chain 3:
## Chain 3: WARNING: No variance estimation is
## Chain 3: performed for num_warmup < 20
## Chain 3:
## Chain 3: Iteration: 1 / 10 [ 10%] (Warmup)
## Chain 3: Iteration: 2 / 10 [ 20%] (Warmup)
## Chain 3: Iteration: 3 / 10 [ 30%] (Warmup)
## Chain 3: Iteration: 4 / 10 [ 40%] (Warmup)
## Chain 3: Iteration: 5 / 10 [ 50%] (Warmup)
## Chain 3: Iteration: 6 / 10 [ 60%] (Warmup)
## Chain 3: Iteration: 7 / 10 [ 70%] (Warmup)
## Chain 3: Iteration: 8 / 10 [ 80%] (Warmup)
## Chain 3: Iteration: 9 / 10 [ 90%] (Sampling)
## Chain 3: Iteration: 10 / 10 [100%] (Sampling)
## Chain 3:
## Chain 3: Elapsed Time: 0.002 seconds (Warm-up)
## Chain 3: 0 seconds (Sampling)
## Chain 3: 0.002 seconds (Total)
## Chain 3:
##
## SAMPLING FOR MODEL 'cd137cae3425170764c33899873035dd' NOW (CHAIN 4).
## Chain 4:
## Chain 4: Gradient evaluation took 0 seconds
## Chain 4: 1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
## Chain 4: Adjust your expectations accordingly!
## Chain 4:
## Chain 4:
## Chain 4: WARNING: No variance estimation is
## Chain 4: performed for num_warmup < 20
## Chain 4:
## Chain 4: Iteration: 1 / 10 [ 10%] (Warmup)
## Chain 4: Iteration: 2 / 10 [ 20%] (Warmup)
## Chain 4: Iteration: 3 / 10 [ 30%] (Warmup)
## Chain 4: Iteration: 4 / 10 [ 40%] (Warmup)
## Chain 4: Iteration: 5 / 10 [ 50%] (Warmup)
## Chain 4: Iteration: 6 / 10 [ 60%] (Warmup)
## Chain 4: Iteration: 7 / 10 [ 70%] (Warmup)
## Chain 4: Iteration: 8 / 10 [ 80%] (Warmup)
## Chain 4: Iteration: 9 / 10 [ 90%] (Sampling)
## Chain 4: Iteration: 10 / 10 [100%] (Sampling)
## Chain 4:
## Chain 4: Elapsed Time: 0.007 seconds (Warm-up)
## Chain 4: 0.003 seconds (Sampling)
## Chain 4: 0.01 seconds (Total)
## Chain 4:
## Warning: There were 6 divergent transitions after warmup. See
## http://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
## to find out why this is a problem and how to eliminate them.
## Warning: There were 3 chains where the estimated Bayesian Fraction of Missing Information was low. See
## http://mc-stan.org/misc/warnings.html#bfmi-low
## Warning: Examine the pairs() plot to diagnose sampling problems
## Warning: The largest R-hat is 1.67, indicating chains have not mixed.
## Running the chains for more iterations may help. See
## http://mc-stan.org/misc/warnings.html#r-hat
## Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
## Running the chains for more iterations may help. See
## http://mc-stan.org/misc/warnings.html#bulk-ess
## Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
## Running the chains for more iterations may help. See
## http://mc-stan.org/misc/warnings.html#tail-ess
P_1 <- posterior(M_1)
## Warning: Method 'posterior_samples' is deprecated. Please see ?as_draws for
## recommended alternatives.
## Warning: `funs()` was deprecated in dplyr 0.8.0.
## Please use a list of either functions or lambdas:
##
## # Simple named list:
## list(mean = mean, median = median)
##
## # Auto named with `tibble::lst()`:
## tibble::lst(mean, median)
##
## # Using lambdas
## list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
PP_1 <- post_pred(M_1, thin = 10)
## Warning: 'nsamples.brmsfit' is deprecated. Please use 'ndraws' instead.
## Warning: Argument 'nsamples' is deprecated. Please use argument 'ndraws'
## instead.
# save model estimates
save(M_1, P_1, PP_1, df, file = "model_estimates.Rda")
# get parameters for fixed effects, random factor variation and random effects
bayr::fixef(P_1)
Coefficient estimates with 95% credibility limits
| ampl |
1.5372730 |
0.2441283 |
7.532265 |
| rate |
0.9047972 |
0.6752391 |
5.994427 |
| asym |
0.5115005 |
0.2946219 |
89.096451 |
bayr::grpef(P_1)
Coefficient estimates with 95% credibility limits
| ampl |
4.2609141 |
1.5042368 |
13.427043 |
| rate |
0.6306478 |
0.3218369 |
1.849620 |
| asym |
0.7215044 |
0.1628746 |
4.117278 |
P_1 %>% re_scores() %>% bayr::ranef()
Coefficient estimates with 95% credibility limits
| ampl |
1 |
2.8459440 |
-4.0190910 |
6.311818 |
| ampl |
2 |
2.1026237 |
-3.3140584 |
5.332197 |
| ampl |
3 |
8.8466523 |
4.9345281 |
26.299112 |
| ampl |
4 |
0.2218807 |
-7.9569252 |
5.119654 |
| ampl |
5 |
4.0804121 |
-3.8072336 |
20.027441 |
| ampl |
6 |
1.7266856 |
-3.0906295 |
16.998520 |
| ampl |
7 |
-1.4921182 |
-12.0888616 |
9.957731 |
| ampl |
8 |
4.0659946 |
-5.9701183 |
9.218559 |
| ampl |
9 |
-0.9485475 |
-18.1375707 |
15.985171 |
| ampl |
10 |
1.1976497 |
-13.7032115 |
11.133031 |
| rate |
1 |
1.4297614 |
0.5545299 |
6.574320 |
| rate |
2 |
1.0628584 |
0.1473731 |
5.893760 |
| rate |
3 |
0.6909012 |
-0.2318586 |
7.527884 |
| rate |
4 |
0.8788250 |
-0.1372828 |
5.693161 |
| rate |
5 |
0.4432553 |
-0.3974981 |
7.021053 |
| rate |
6 |
1.4667947 |
0.9317835 |
8.534708 |
| rate |
7 |
1.6635068 |
-0.2545396 |
6.771273 |
| rate |
8 |
0.5969694 |
-0.1577749 |
5.854229 |
| rate |
9 |
0.8752235 |
-0.3484960 |
5.531201 |
| rate |
10 |
1.3543611 |
1.0857261 |
6.240982 |
| asym |
1 |
0.8224183 |
-1.7897847 |
89.182016 |
| asym |
2 |
0.3962197 |
-3.5172137 |
88.925652 |
| asym |
3 |
1.6877796 |
-1.5135568 |
89.164884 |
| asym |
4 |
0.8901015 |
-1.7875809 |
89.126578 |
| asym |
5 |
0.9748117 |
-3.9222010 |
89.060216 |
| asym |
6 |
-0.0614516 |
-5.7202461 |
88.998442 |
| asym |
7 |
0.1393303 |
-6.9366189 |
89.225925 |
| asym |
8 |
2.2711239 |
-1.2744745 |
89.202639 |
| asym |
9 |
4.8634926 |
-1.3297056 |
88.945384 |
| asym |
10 |
2.7202911 |
1.0478260 |
88.950185 |
## LEARNING CURVES BASED ON MODEL ESTIMATES ##
df1$Subject<-df1$Subject
# learning curves per Subject
df1 %>%
mutate(M_1 = predict(PP_1)$center) %>%
ggplot(aes(x = Rep,
y = M_1,
color=Subject)) +
facet_wrap(~Subject, scales = "free_y") +
geom_smooth(se = F) +
geom_point(alpha=0.2, size=1)+
ylim(-100,500)+
labs(x="Rep",y="Model estimates")+
theme_classic()+
scale_color_manual(values=mycolors)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.02
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0804

# crossbar plots for each parameter and Subject
P_1 %>%
re_scores() %>%
bayr::ranef() %>%
ggplot(aes(x = re_entity,
y = center,
ymin = lower,
ymax = upper)) +
facet_grid(nonlin~1, scales = "free_y") +
geom_crossbar(width = .2) +
labs(x = "Subject", y = "Model estimates") +
theme_classic()

## NON-LINEAR MULTILEVEL REGRESSION ##
# specify formula, variables and weakly informative priors
F_ary2 <- formula(MT ~ asym + ampl * exp(-rate * Rep))
F_ary_ef_2 <- list(formula(ampl ~ 1|Subject),
formula(rate ~ 1|Subject),
formula(asym ~ 1|Subject))
F_ary_prior2 <- c(set_prior("normal(5, 100)", nlpar = "ampl", lb = 0),
set_prior("normal(.5, 3)", nlpar = "rate", lb = 0),
set_prior("normal(3, 20)", nlpar = "asym", lb = 0))
# create model including MCMC sampling
M_2 <-
df3 %>%
brm(bf(F_ary2,
flist = F_ary_ef_2,
nl = T),
prior = F_ary_prior2,
family = "exgaussian",
data = .,
iter = 10,
warmup = 8,
save_pars=save_pars("Subject"))
## Compiling Stan program...
## Start sampling
##
## SAMPLING FOR MODEL 'e92e15377b9191dba6fe2a238d4e46dd' NOW (CHAIN 1).
## Chain 1:
## Chain 1: Gradient evaluation took 0 seconds
## Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
## Chain 1: Adjust your expectations accordingly!
## Chain 1:
## Chain 1:
## Chain 1: WARNING: No variance estimation is
## Chain 1: performed for num_warmup < 20
## Chain 1:
## Chain 1: Iteration: 1 / 10 [ 10%] (Warmup)
## Chain 1: Iteration: 2 / 10 [ 20%] (Warmup)
## Chain 1: Iteration: 3 / 10 [ 30%] (Warmup)
## Chain 1: Iteration: 4 / 10 [ 40%] (Warmup)
## Chain 1: Iteration: 5 / 10 [ 50%] (Warmup)
## Chain 1: Iteration: 6 / 10 [ 60%] (Warmup)
## Chain 1: Iteration: 7 / 10 [ 70%] (Warmup)
## Chain 1: Iteration: 8 / 10 [ 80%] (Warmup)
## Chain 1: Iteration: 9 / 10 [ 90%] (Sampling)
## Chain 1: Iteration: 10 / 10 [100%] (Sampling)
## Chain 1:
## Chain 1: Elapsed Time: 0.004 seconds (Warm-up)
## Chain 1: 0.001 seconds (Sampling)
## Chain 1: 0.005 seconds (Total)
## Chain 1:
##
## SAMPLING FOR MODEL 'e92e15377b9191dba6fe2a238d4e46dd' NOW (CHAIN 2).
## Chain 2:
## Chain 2: Gradient evaluation took 0 seconds
## Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
## Chain 2: Adjust your expectations accordingly!
## Chain 2:
## Chain 2:
## Chain 2: WARNING: No variance estimation is
## Chain 2: performed for num_warmup < 20
## Chain 2:
## Chain 2: Iteration: 1 / 10 [ 10%] (Warmup)
## Chain 2: Iteration: 2 / 10 [ 20%] (Warmup)
## Chain 2: Iteration: 3 / 10 [ 30%] (Warmup)
## Chain 2: Iteration: 4 / 10 [ 40%] (Warmup)
## Chain 2: Iteration: 5 / 10 [ 50%] (Warmup)
## Chain 2: Iteration: 6 / 10 [ 60%] (Warmup)
## Chain 2: Iteration: 7 / 10 [ 70%] (Warmup)
## Chain 2: Iteration: 8 / 10 [ 80%] (Warmup)
## Chain 2: Iteration: 9 / 10 [ 90%] (Sampling)
## Chain 2: Iteration: 10 / 10 [100%] (Sampling)
## Chain 2:
## Chain 2: Elapsed Time: 0 seconds (Warm-up)
## Chain 2: 0 seconds (Sampling)
## Chain 2: 0 seconds (Total)
## Chain 2:
##
## SAMPLING FOR MODEL 'e92e15377b9191dba6fe2a238d4e46dd' NOW (CHAIN 3).
## Chain 3: Rejecting initial value:
## Chain 3: Log probability evaluates to log(0), i.e. negative infinity.
## Chain 3: Stan can't start sampling from this initial value.
## Chain 3:
## Chain 3: Gradient evaluation took 0 seconds
## Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
## Chain 3: Adjust your expectations accordingly!
## Chain 3:
## Chain 3:
## Chain 3: WARNING: No variance estimation is
## Chain 3: performed for num_warmup < 20
## Chain 3:
## Chain 3: Iteration: 1 / 10 [ 10%] (Warmup)
## Chain 3: Iteration: 2 / 10 [ 20%] (Warmup)
## Chain 3: Iteration: 3 / 10 [ 30%] (Warmup)
## Chain 3: Iteration: 4 / 10 [ 40%] (Warmup)
## Chain 3: Iteration: 5 / 10 [ 50%] (Warmup)
## Chain 3: Iteration: 6 / 10 [ 60%] (Warmup)
## Chain 3: Iteration: 7 / 10 [ 70%] (Warmup)
## Chain 3: Iteration: 8 / 10 [ 80%] (Warmup)
## Chain 3: Iteration: 9 / 10 [ 90%] (Sampling)
## Chain 3: Iteration: 10 / 10 [100%] (Sampling)
## Chain 3:
## Chain 3: Elapsed Time: 0 seconds (Warm-up)
## Chain 3: 0 seconds (Sampling)
## Chain 3: 0 seconds (Total)
## Chain 3:
##
## SAMPLING FOR MODEL 'e92e15377b9191dba6fe2a238d4e46dd' NOW (CHAIN 4).
## Chain 4:
## Chain 4: Gradient evaluation took 0 seconds
## Chain 4: 1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
## Chain 4: Adjust your expectations accordingly!
## Chain 4:
## Chain 4:
## Chain 4: WARNING: No variance estimation is
## Chain 4: performed for num_warmup < 20
## Chain 4:
## Chain 4: Iteration: 1 / 10 [ 10%] (Warmup)
## Chain 4: Iteration: 2 / 10 [ 20%] (Warmup)
## Chain 4: Iteration: 3 / 10 [ 30%] (Warmup)
## Chain 4: Iteration: 4 / 10 [ 40%] (Warmup)
## Chain 4: Iteration: 5 / 10 [ 50%] (Warmup)
## Chain 4: Iteration: 6 / 10 [ 60%] (Warmup)
## Chain 4: Iteration: 7 / 10 [ 70%] (Warmup)
## Chain 4: Iteration: 8 / 10 [ 80%] (Warmup)
## Chain 4: Iteration: 9 / 10 [ 90%] (Sampling)
## Chain 4: Iteration: 10 / 10 [100%] (Sampling)
## Chain 4:
## Chain 4: Elapsed Time: 0.004 seconds (Warm-up)
## Chain 4: 0.001 seconds (Sampling)
## Chain 4: 0.005 seconds (Total)
## Chain 4:
## Warning: There were 6 divergent transitions after warmup. See
## http://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
## to find out why this is a problem and how to eliminate them.
## Warning: There were 2 chains where the estimated Bayesian Fraction of Missing Information was low. See
## http://mc-stan.org/misc/warnings.html#bfmi-low
## Warning: Examine the pairs() plot to diagnose sampling problems
## Warning: The largest R-hat is 1.39, indicating chains have not mixed.
## Running the chains for more iterations may help. See
## http://mc-stan.org/misc/warnings.html#r-hat
## Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
## Running the chains for more iterations may help. See
## http://mc-stan.org/misc/warnings.html#bulk-ess
## Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
## Running the chains for more iterations may help. See
## http://mc-stan.org/misc/warnings.html#tail-ess
P_2 <- posterior(M_2)
## Warning: Method 'posterior_samples' is deprecated. Please see ?as_draws for
## recommended alternatives.
PP_2 <- post_pred(M_2, thin = 10)
## Warning: 'nsamples.brmsfit' is deprecated. Please use 'ndraws' instead.
## Warning: Argument 'nsamples' is deprecated. Please use argument 'ndraws'
## instead.
# save model estimates
save(M_2, P_2, PP_2, df, file = "model_estimates2.Rda")
# get parameters for fixed effects, random factor variation and random effects
bayr::fixef(P_2)
Coefficient estimates with 95% credibility limits
| ampl |
2.217012 |
0.5119803 |
24.779228 |
| rate |
3.956863 |
0.4145142 |
6.454642 |
| asym |
6.109056 |
0.7827957 |
22.210695 |
bayr::grpef(P_2)
Coefficient estimates with 95% credibility limits
| ampl |
1.2876692 |
0.2697084 |
3.184098 |
| rate |
0.5482723 |
0.1011188 |
1.255198 |
| asym |
1.2282076 |
0.0985602 |
13.334264 |
P_2 %>% re_scores() %>% bayr::ranef()
Coefficient estimates with 95% credibility limits
| ampl |
1 |
2.520021 |
0.5933774 |
20.895040 |
| ampl |
2 |
2.743138 |
0.8504929 |
25.153398 |
| ampl |
3 |
3.010682 |
-0.1947308 |
24.804242 |
| ampl |
4 |
2.251460 |
0.4408577 |
21.751716 |
| ampl |
5 |
3.265185 |
-1.4391451 |
23.096544 |
| ampl |
6 |
2.009275 |
-0.3846950 |
25.612125 |
| ampl |
7 |
2.281924 |
0.5345588 |
27.873327 |
| ampl |
8 |
3.061369 |
0.6124279 |
26.926629 |
| ampl |
9 |
2.578767 |
-9.0206021 |
21.354280 |
| ampl |
10 |
3.784110 |
0.8083094 |
25.035000 |
| rate |
1 |
4.182387 |
-0.3153740 |
6.372929 |
| rate |
2 |
3.523668 |
1.2422143 |
6.806751 |
| rate |
3 |
4.313452 |
-0.5138478 |
7.050187 |
| rate |
4 |
4.508422 |
-1.3744200 |
7.515303 |
| rate |
5 |
3.788438 |
-0.0356767 |
6.241064 |
| rate |
6 |
3.625326 |
1.0719685 |
6.453255 |
| rate |
7 |
3.148713 |
-0.1200784 |
5.938351 |
| rate |
8 |
3.250953 |
0.7751837 |
6.206078 |
| rate |
9 |
3.610666 |
0.6568504 |
5.973544 |
| rate |
10 |
4.446138 |
1.0639951 |
7.975844 |
| asym |
1 |
2.917321 |
0.5679055 |
14.149390 |
| asym |
2 |
5.503346 |
0.6218894 |
24.101602 |
| asym |
3 |
4.883594 |
0.2545269 |
21.813136 |
| asym |
4 |
5.839893 |
0.8644056 |
36.366124 |
| asym |
5 |
3.682677 |
0.8159019 |
18.837016 |
| asym |
6 |
6.153524 |
0.3633338 |
16.280428 |
| asym |
7 |
3.008648 |
0.7916115 |
17.441304 |
| asym |
8 |
6.108018 |
0.8848794 |
23.359119 |
| asym |
9 |
6.207769 |
0.2081330 |
23.266166 |
| asym |
10 |
3.494624 |
-5.5384711 |
27.583948 |
## LEARNING CURVES BASED ON MODEL ESTIMATES ##
df3$Subject<-df3$Subject
# learning curves per Subject
df3 %>%
mutate(M_2 = predict(PP_2)$center) %>%
ggplot(aes(x = Rep,
y = M_2,
color=Subject)) +
facet_wrap(~Subject, scales = "free_y") +
geom_smooth(se = F) +
geom_point(alpha=0.2, size=1)+
ylim(-500,1500)+
labs(x="Rep",y="Model estimates")+
theme_classic()+
scale_color_manual(values=mycolors)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 1.0201
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 1.0201
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 1.0201
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 1.0201
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 1.0201
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 1.0201
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 1.0201
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 1.0201
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 1.0201
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -0.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 1.01
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 1.0201

# crossbar plots for each parameter and Subject
P_2 %>%
re_scores() %>%
bayr::ranef() %>%
ggplot(aes(x = re_entity,
y = center,
ymin = lower,
ymax = upper)) +
facet_grid(nonlin~1, scales = "free_y") +
geom_crossbar(width = .2) +
labs(x = "Subject", y = "Model estimates") +
theme_classic()
