library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.0     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(here)
## here() starts at /Users/caoanjie/Desktop/projects/meta_stimuli
library(lme4)
## Loading required package: Matrix
## 
## Attaching package: 'Matrix'
## 
## The following objects are masked from 'package:tidyr':
## 
##     expand, pack, unpack
library(nlme)
## 
## Attaching package: 'nlme'
## 
## The following object is masked from 'package:lme4':
## 
##     lmList
## 
## The following object is masked from 'package:dplyr':
## 
##     collapse
source("helper/volatility.R")
source("helper/slope.R")

The goal of this simulation is to test whether the current analytical approach can control for confounds.

4. non-confounding relationship

Now let’s create a dataset that the dishabituation time is arbitrarily high

# Set seed for reproducibility
set.seed(123)

# Generate synthetic data
generate_fake_data <- function(n_subjects = 50) {
  # Create subject IDs
  subjects <- paste0("S", sprintf("%03d", 1:n_subjects))

  # Initialize empty data frame
  data <- data.frame()

  # Loop through each subject
  for (subj in subjects) {
    # Randomly assign number of habituation trials (4 or 6)
    n_trials <- sample(c(4, 6), 1)
    trial_number <- 1:(n_trials + 1)

    # Simulate exponential drop in habituation times with varying slopes
    initial_looking_time <- runif(1, 5000, 10000)
    decay_rate <- runif(1, 0.2, 0.5)  # Randomly vary decay rate
    habituation_times <- initial_looking_time * exp(-decay_rate * (1:n_trials))
    deviant_time <- runif(1, 10000, 15000)  # Arbitrarily high but independent of previous trials

    # Combine looking times
    trial_looking_time <- c(habituation_times, deviant_time)

    # Assign trial types
    trial_type <- c(rep('background', n_trials), 'deviant')

    # Create data frame for subject
    subject_data <- data.frame(
      subject = subj,
      block_number = 1,
      task_type = 'curiosity',
      deviant_position = n_trials + 1,
      trial_number = trial_number,
      trial_type = trial_type,
      trial_looking_time = trial_looking_time,
      stimulus_displayed = paste0('images/stimuli/', sample(1:20, n_trials + 1, replace = TRUE), '_A_a.gif'),
      task_question_type = 'curiosity_background',
      task_question_response = sample(1:5, n_trials + 1, replace = TRUE)
    )

    # Append subject data
    data <- rbind(data, subject_data)
  }

  return(data)
}

# Generate dataset
fake_data_nr <- generate_fake_data(n_subjects = 50)
habituation_data <-  fake_data_nr %>% 
  # fist block
  # before the dishabituation trials
  filter(trial_number < deviant_position) %>% 
  # only keeping the relevant information 
  select(subject, trial_number, trial_looking_time) 

adult_slope_df <- get_individual_slope(habituation_data)



adult_dishab_raw <- fake_data_nr %>% 
  filter(trial_number == deviant_position) 

adult_dishab_d <- adult_dishab_raw %>% 
  select(subject,block_number, trial_looking_time) %>% 
  rename(dishab_raw = trial_looking_time) %>% 
  left_join(
    fake_data_nr  %>% filter(trial_number < deviant_position) %>% group_by(subject, block_number) %>% filter(trial_number == max(trial_number)),
    by = c("subject", "block_number")
  ) %>% 
  # calculating the key 
  mutate(dishab_diff = log(dishab_raw) - log(trial_looking_time)) %>% 
  mutate(dishab_trial_num = trial_number + 1) %>% 
  select(subject, dishab_diff, dishab_trial_num)

4.1. relationships

4.1.1 first trial vs dishab

check the relationship between first trial and dishabituation

adult_dishab_raw %>% 
  select(subject,block_number, trial_looking_time) %>% 
  rename(dishab_raw = trial_looking_time) %>% 
  left_join(
    fake_data_nr  %>% filter(trial_number == 1),
    by = c("subject", "block_number")
  ) %>% 
  ggplot(aes(x = trial_looking_time, y = dishab_raw)) + 
  geom_point() + 
  geom_smooth(method = "lm") +
  labs(
    title = "No relationship", 
    subtitle = "dishab raw ~ first trial"
  )
## `geom_smooth()` using formula = 'y ~ x'

4.1.2 last trial vs dishab

check the relationship between last trial and dishabituation

adult_dishab_raw %>% 
  select(subject,block_number, trial_looking_time) %>% 
  rename(dishab_raw = trial_looking_time) %>% 
  left_join(
    fake_data_nr  %>% group_by(subject) %>% filter(trial_number == (max(trial_number) -1)),
    by = c("subject", "block_number")
  ) %>% 
  ggplot(aes(x = trial_looking_time, y = dishab_raw)) + 
  geom_point() + 
  geom_smooth(method = "lm") + 
   labs(
    title = "No relationship", 
    subtitle = "dishab raw ~ last trial"
  )
## `geom_smooth()` using formula = 'y ~ x'

4.2 slope?!?

yet still there exists a relationship between the slope and the dishabituation difference

adult_dishab_d %>% 
  left_join(adult_slope_df) %>% 
  ggplot(aes(x = decay_rate, y = dishab_diff)) + 
  geom_point() + 
  geom_smooth(method = "lm") + 
  labs(
    title = "No relationship", 
    subtitle = "dishab diff ~ slope"
  )
## Joining with `by = join_by(subject)`
## `geom_smooth()` using formula = 'y ~ x'

4.3 raw data

weird, what does it look like?

fake_data_nr %>% 
  ggplot(aes(x = trial_number, y = trial_looking_time)) + 
  geom_point(position = position_jitter(width = .2)) + 
  facet_wrap(~deviant_position)

4.4. why the relationship?

  1. The last habituation trial value depends inversely on the decay rate (higher decay → smaller last trial values).

  2. The dishabituation difference is computed as a logarithmic ratio involving the last trial time. When t_last is smaller (due to a higher decay rate), the log difference grows larger, creating a spurious correlation.

# Generate synthetic data
generate_fake_data <- function(n_subjects = 50) {
  # Create subject IDs
  subjects <- paste0("S", sprintf("%03d", 1:n_subjects))

  # Initialize empty data frame
  data <- data.frame()

  # Loop through each subject
  for (subj in subjects) {
    # Randomly assign number of habituation trials (4 or 6)
    n_trials <- sample(c(4, 6), 1)
    trial_number <- 1:(n_trials + 1)

    # Simulate exponential drop in habituation times with varying slopes
    initial_looking_time <- runif(1, 5000, 10000)
    decay_rate <- runif(1, 0.2, 0.5)  # Randomly vary decay rate
    habituation_times <- initial_looking_time * exp(-decay_rate * (1:n_trials))

    # Make the deviant trial completely independent by adding a large random value
    deviant_time <- runif(1, 15000, 20000)  # Arbitrarily high but independent of previous trials

    # Combine looking times
    trial_looking_time <- c(habituation_times, deviant_time)

    # Assign trial types
    trial_type <- c(rep('background', n_trials), 'deviant')

    # Create data frame for subject
    subject_data <- data.frame(
      subject = subj,
      block_number = 1,
      task_type = 'curiosity',
      deviant_position = n_trials + 1,
      trial_number = trial_number,
      trial_type = trial_type,
      trial_looking_time = trial_looking_time,
      decay_rate = decay_rate,  # Include decay rate for analysis
      stimulus_displayed = paste0('images/stimuli/', sample(1:20, n_trials + 1, replace = TRUE), '_A_a.gif'),
      task_question_type = 'curiosity_background',
      task_question_response = sample(1:5, n_trials + 1, replace = TRUE)
    )

    # Append subject data
    data <- rbind(data, subject_data)
  }

  return(data)
}

# Generate dataset
fake_data <- generate_fake_data(n_subjects = 50)

# Visualization: Relationship between decay rate and last trial time
last_trial_data <- fake_data %>% 
  group_by(subject) %>% 
  filter(trial_number == max(trial_number) - 1)  # Select last habituation trial

# Plot decay rate vs last trial looking time
ggplot(last_trial_data, aes(x = decay_rate, y = trial_looking_time)) +
  geom_point() +
  geom_smooth(method = 'lm') +
  labs(
    title = 'Decay Rate vs Last Habituation Trial Time',
    x = 'Decay Rate',
    y = 'Last Trial Looking Time'
  )
## `geom_smooth()` using formula = 'y ~ x'

4.5 try normalizing by the first trial???

still doesn’t work. even though the deviant time is independent, the first trial indirectly scales the entire decay trajectory. Here’s the subtle issue:

adult_dishab_d <- adult_dishab_raw %>% 
  select(subject,block_number, trial_looking_time) %>% 
  rename(dishab_raw = trial_looking_time) %>% 
  left_join(
    fake_data_nr  %>% filter(trial_number < deviant_position) %>% group_by(subject, block_number) %>% filter(trial_number == max(trial_number)),
    by = c("subject", "block_number")
  ) %>% 
  left_join(
    fake_data_nr %>% group_by(subject, block_number)  %>% filter(trial_number == 1) %>% rename(first_trial_looking_time = trial_looking_time) %>% select(subject, block_number, first_trial_looking_time)
,
    by = c("subject", "block_number")
  ) %>% 
  # calculating the key 
  mutate(
    dishab_diff = log(dishab_raw) - log(trial_looking_time), 
    dishab_normalized = (dishab_raw / first_trial_looking_time)) %>% 
  mutate(dishab_trial_num = trial_number + 1) %>% 
  select(subject, dishab_diff, dishab_normalized, dishab_trial_num, first_trial_looking_time)

adult_dishab_d %>% 
  left_join(adult_slope_df) %>% 
  ggplot(aes(x = decay_rate, y = dishab_normalized)) + 
  geom_point() + 
  geom_smooth(method = "lm") + 
  labs(
    title = "No relationship", 
    subtitle = "dishab diff ~ slope"
  )
## Joining with `by = join_by(subject)`
## `geom_smooth()` using formula = 'y ~ x'

4.6 try modeling

model_d <- adult_dishab_d %>% 
  left_join(adult_slope_df)
## Joining with `by = join_by(subject)`
lm(
  dishab_diff ~ decay_rate, 
  data = model_d
) %>% summary()
## 
## Call:
## lm(formula = dishab_diff ~ decay_rate, data = model_d)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.73879 -0.27604  0.00625  0.29323  0.70181 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   0.7079     0.1729   4.094 0.000162 ***
## decay_rate   -4.3211     0.4526  -9.547 1.13e-12 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3662 on 48 degrees of freedom
## Multiple R-squared:  0.655,  Adjusted R-squared:  0.6479 
## F-statistic: 91.15 on 1 and 48 DF,  p-value: 1.129e-12
lm(
  dishab_diff ~ decay_rate + first_trial_looking_time, 
  data = model_d
) %>% summary()
## 
## Call:
## lm(formula = dishab_diff ~ decay_rate + first_trial_looking_time, 
##     data = model_d)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.73373 -0.27297  0.06726  0.29824  0.64478 
## 
## Coefficients:
##                           Estimate Std. Error t value Pr(>|t|)    
## (Intercept)              -0.849068   0.914957  -0.928   0.3582    
## decay_rate               -5.909253   1.018758  -5.800 5.39e-07 ***
## first_trial_looking_time  0.000187   0.000108   1.732   0.0899 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3588 on 47 degrees of freedom
## Multiple R-squared:  0.6757, Adjusted R-squared:  0.6619 
## F-statistic: 48.97 on 2 and 47 DF,  p-value: 3.207e-12
lm(
  dishab_diff ~  first_trial_looking_time, 
  data = model_d
) %>% 
  summary()
## 
## Call:
## lm(formula = dishab_diff ~ first_trial_looking_time, data = model_d)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.79337 -0.37262 -0.04103  0.44039  0.92881 
## 
## Coefficients:
##                            Estimate Std. Error t value Pr(>|t|)    
## (Intercept)               4.254e+00  3.254e-01  13.074  < 2e-16 ***
## first_trial_looking_time -3.769e-04  6.092e-05  -6.186  1.3e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4651 on 48 degrees of freedom
## Multiple R-squared:  0.4436, Adjusted R-squared:  0.432 
## F-statistic: 38.27 on 1 and 48 DF,  p-value: 1.301e-07

5. REAL non-confounding!!

now let’s create another non-confounding dataset?!?

# Generate synthetic data
generate_fake_data <- function(n_subjects = 50) {
  # Create subject IDs
  subjects <- paste0("S", sprintf("%03d", 1:n_subjects))

  # Initialize empty data frame
  data <- data.frame()

  # Loop through each subject
  for (subj in subjects) {
    # Randomly assign number of habituation trials (4 or 6)
    n_trials <- sample(c(4, 6), 1)
    trial_number <- 1:(n_trials + 1)

    # Generate habituation times that always go down
    initial_looking_time <- runif(1, 5000, 10000)
    habituation_times <- sort(runif(n_trials, 500, 5000), decreasing = TRUE)

    # Make sure the values never go below zero
    habituation_times <- pmax(habituation_times, 500)

    # Generate deviant trial looking time that is higher than the last habituation time
    deviant_time <-runif(1, 20000, 30000)

    # Combine looking times
    trial_looking_time <- c(habituation_times, deviant_time)

    # Assign trial types
    trial_type <- c(rep('background', n_trials), 'deviant')

    # Create data frame for subject
    subject_data <- data.frame(
      subject = subj,
      block_number = 1,
      task_type = 'curiosity',
      deviant_position = n_trials + 1,
      trial_number = trial_number,
      trial_type = trial_type,
      trial_looking_time = trial_looking_time,
      stimulus_displayed = paste0('images/stimuli/', sample(1:20, n_trials + 1, replace = TRUE), '_A_a.gif'),
      task_question_type = 'curiosity_background',
      task_question_response = sample(1:5, n_trials + 1, replace = TRUE)
    )

    # Append subject data
    data <- rbind(
      data, subject_data)
  }

  return(data)
}

# Generate dataset
fake_data_rnr <- generate_fake_data(n_subjects = 50)
habituation_data <-  fake_data_rnr %>% 
  # fist block
  # before the dishabituation trials
  filter(trial_number < deviant_position) %>% 
  # only keeping the relevant information 
  select(subject, trial_number, trial_looking_time) 

adult_slope_df <- get_individual_slope(habituation_data)



adult_dishab_raw <- fake_data_rnr %>% 
  filter(trial_number == deviant_position) 

adult_dishab_d <- adult_dishab_raw %>% 
  select(subject,block_number, trial_looking_time) %>% 
  rename(dishab_raw = trial_looking_time) %>% 
  left_join(
    fake_data_rnr  %>% filter(trial_number < deviant_position) %>% group_by(subject, block_number) %>% filter(trial_number == max(trial_number)),
    by = c("subject", "block_number")
  ) %>% 
  left_join(
    fake_data_rnr %>% group_by(subject, block_number)  %>% filter(trial_number == 1) %>% rename(first_trial_looking_time = trial_looking_time) %>% select(subject, block_number, first_trial_looking_time)
,
    by = c("subject", "block_number")
  ) %>% 
  # calculating the key 
  mutate(
    dishab_log_diff = log(dishab_raw) - log(trial_looking_time),
    dishab_diff = dishab_raw - trial_looking_time) %>% 
  mutate(dishab_trial_num = trial_number + 1) %>% 
  select(subject, dishab_diff, dishab_log_diff, first_trial_looking_time, dishab_trial_num)

5.1. slope?

check the slope….

adult_dishab_d %>% 
  left_join(adult_slope_df) %>% 
  ggplot(aes(x = decay_rate, y = dishab_diff)) + 
  geom_point() + 
  geom_smooth(method = "lm") + 
  labs(
    title = "No relationship", 
    subtitle = "dishab diff ~ slope"
  )
## Joining with `by = join_by(subject)`
## `geom_smooth()` using formula = 'y ~ x'

adult_dishab_d %>% 
  left_join(adult_slope_df) %>% 
  ggplot(aes(x = decay_rate, y = dishab_log_diff)) + 
  geom_point() + 
  geom_smooth(method = "lm") + 
  labs(
    title = "No relationship", 
    subtitle = "dishab log diff ~ slope"
  )
## Joining with `by = join_by(subject)`
## `geom_smooth()` using formula = 'y ~ x'

5.2 try modeling??

model_d <- adult_dishab_d %>% 
  left_join(adult_slope_df)
## Joining with `by = join_by(subject)`
lm(
  dishab_diff ~ decay_rate, 
  data = model_d
) %>% summary()
## 
## Call:
## lm(formula = dishab_diff ~ decay_rate, data = model_d)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5496.0 -2082.5   151.5  1854.0  4424.7 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    22448       1511   14.86   <2e-16 ***
## decay_rate     -5564       5058   -1.10    0.277    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2588 on 48 degrees of freedom
## Multiple R-squared:  0.02459,    Adjusted R-squared:  0.004271 
## F-statistic:  1.21 on 1 and 48 DF,  p-value: 0.2768
lm(
  dishab_log_diff ~ decay_rate, 
  data = model_d
) %>% summary()
## 
## Call:
## lm(formula = dishab_log_diff ~ decay_rate, data = model_d)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.90860 -0.41262  0.00744  0.35261  0.82718 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   2.1680     0.2552   8.494 3.99e-11 ***
## decay_rate   -3.0501     0.8546  -3.569 0.000826 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4373 on 48 degrees of freedom
## Multiple R-squared:  0.2097, Adjusted R-squared:  0.1932 
## F-statistic: 12.74 on 1 and 48 DF,  p-value: 0.0008257
lm(
  dishab_diff ~ decay_rate + first_trial_looking_time, 
  data = model_d
) %>% summary()
## 
## Call:
## lm(formula = dishab_diff ~ decay_rate + first_trial_looking_time, 
##     data = model_d)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5728.1 -1794.2   205.1  1862.4  4758.6 
## 
## Coefficients:
##                            Estimate Std. Error t value Pr(>|t|)    
## (Intercept)              18422.3281  4767.7428   3.864 0.000341 ***
## decay_rate               -8631.9034  6128.8893  -1.408 0.165595    
## first_trial_looking_time     0.7177     0.8060   0.890 0.377772    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2594 on 47 degrees of freedom
## Multiple R-squared:  0.04077,    Adjusted R-squared:  -4.504e-05 
## F-statistic: 0.9989 on 2 and 47 DF,  p-value: 0.376
lm(
  dishab_diff ~  first_trial_looking_time, 
  data = model_d
) %>% 
  summary()
## 
## Call:
## lm(formula = dishab_diff ~ first_trial_looking_time, data = model_d)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -6383.3 -1824.6   263.6  1580.0  5179.2 
## 
## Coefficients:
##                           Estimate Std. Error t value Pr(>|t|)    
## (Intercept)              2.371e+04  2.966e+03   7.995 2.24e-10 ***
## first_trial_looking_time 7.946e-02  6.733e-01   0.118    0.907    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2620 on 48 degrees of freedom
## Multiple R-squared:  0.0002901,  Adjusted R-squared:  -0.02054 
## F-statistic: 0.01393 on 1 and 48 DF,  p-value: 0.9065

6. Try control by residualized

fake_data_rnr
##     subject block_number task_type deviant_position trial_number trial_type
## 1      S001            1 curiosity                5            1 background
## 2      S001            1 curiosity                5            2 background
## 3      S001            1 curiosity                5            3 background
## 4      S001            1 curiosity                5            4 background
## 5      S001            1 curiosity                5            5    deviant
## 6      S002            1 curiosity                5            1 background
## 7      S002            1 curiosity                5            2 background
## 8      S002            1 curiosity                5            3 background
## 9      S002            1 curiosity                5            4 background
## 10     S002            1 curiosity                5            5    deviant
## 11     S003            1 curiosity                5            1 background
## 12     S003            1 curiosity                5            2 background
## 13     S003            1 curiosity                5            3 background
## 14     S003            1 curiosity                5            4 background
## 15     S003            1 curiosity                5            5    deviant
## 16     S004            1 curiosity                5            1 background
## 17     S004            1 curiosity                5            2 background
## 18     S004            1 curiosity                5            3 background
## 19     S004            1 curiosity                5            4 background
## 20     S004            1 curiosity                5            5    deviant
## 21     S005            1 curiosity                5            1 background
## 22     S005            1 curiosity                5            2 background
## 23     S005            1 curiosity                5            3 background
## 24     S005            1 curiosity                5            4 background
## 25     S005            1 curiosity                5            5    deviant
## 26     S006            1 curiosity                5            1 background
## 27     S006            1 curiosity                5            2 background
## 28     S006            1 curiosity                5            3 background
## 29     S006            1 curiosity                5            4 background
## 30     S006            1 curiosity                5            5    deviant
## 31     S007            1 curiosity                5            1 background
## 32     S007            1 curiosity                5            2 background
## 33     S007            1 curiosity                5            3 background
## 34     S007            1 curiosity                5            4 background
## 35     S007            1 curiosity                5            5    deviant
## 36     S008            1 curiosity                7            1 background
## 37     S008            1 curiosity                7            2 background
## 38     S008            1 curiosity                7            3 background
## 39     S008            1 curiosity                7            4 background
## 40     S008            1 curiosity                7            5 background
## 41     S008            1 curiosity                7            6 background
## 42     S008            1 curiosity                7            7    deviant
## 43     S009            1 curiosity                7            1 background
## 44     S009            1 curiosity                7            2 background
## 45     S009            1 curiosity                7            3 background
## 46     S009            1 curiosity                7            4 background
## 47     S009            1 curiosity                7            5 background
## 48     S009            1 curiosity                7            6 background
## 49     S009            1 curiosity                7            7    deviant
## 50     S010            1 curiosity                5            1 background
## 51     S010            1 curiosity                5            2 background
## 52     S010            1 curiosity                5            3 background
## 53     S010            1 curiosity                5            4 background
## 54     S010            1 curiosity                5            5    deviant
## 55     S011            1 curiosity                7            1 background
## 56     S011            1 curiosity                7            2 background
## 57     S011            1 curiosity                7            3 background
## 58     S011            1 curiosity                7            4 background
## 59     S011            1 curiosity                7            5 background
## 60     S011            1 curiosity                7            6 background
## 61     S011            1 curiosity                7            7    deviant
## 62     S012            1 curiosity                5            1 background
## 63     S012            1 curiosity                5            2 background
## 64     S012            1 curiosity                5            3 background
## 65     S012            1 curiosity                5            4 background
## 66     S012            1 curiosity                5            5    deviant
## 67     S013            1 curiosity                5            1 background
## 68     S013            1 curiosity                5            2 background
## 69     S013            1 curiosity                5            3 background
## 70     S013            1 curiosity                5            4 background
## 71     S013            1 curiosity                5            5    deviant
## 72     S014            1 curiosity                7            1 background
## 73     S014            1 curiosity                7            2 background
## 74     S014            1 curiosity                7            3 background
## 75     S014            1 curiosity                7            4 background
## 76     S014            1 curiosity                7            5 background
## 77     S014            1 curiosity                7            6 background
## 78     S014            1 curiosity                7            7    deviant
## 79     S015            1 curiosity                5            1 background
## 80     S015            1 curiosity                5            2 background
## 81     S015            1 curiosity                5            3 background
## 82     S015            1 curiosity                5            4 background
## 83     S015            1 curiosity                5            5    deviant
## 84     S016            1 curiosity                5            1 background
## 85     S016            1 curiosity                5            2 background
## 86     S016            1 curiosity                5            3 background
## 87     S016            1 curiosity                5            4 background
## 88     S016            1 curiosity                5            5    deviant
## 89     S017            1 curiosity                7            1 background
## 90     S017            1 curiosity                7            2 background
## 91     S017            1 curiosity                7            3 background
## 92     S017            1 curiosity                7            4 background
## 93     S017            1 curiosity                7            5 background
## 94     S017            1 curiosity                7            6 background
## 95     S017            1 curiosity                7            7    deviant
## 96     S018            1 curiosity                5            1 background
## 97     S018            1 curiosity                5            2 background
## 98     S018            1 curiosity                5            3 background
## 99     S018            1 curiosity                5            4 background
## 100    S018            1 curiosity                5            5    deviant
## 101    S019            1 curiosity                5            1 background
## 102    S019            1 curiosity                5            2 background
## 103    S019            1 curiosity                5            3 background
## 104    S019            1 curiosity                5            4 background
## 105    S019            1 curiosity                5            5    deviant
## 106    S020            1 curiosity                5            1 background
## 107    S020            1 curiosity                5            2 background
## 108    S020            1 curiosity                5            3 background
## 109    S020            1 curiosity                5            4 background
## 110    S020            1 curiosity                5            5    deviant
## 111    S021            1 curiosity                5            1 background
## 112    S021            1 curiosity                5            2 background
## 113    S021            1 curiosity                5            3 background
## 114    S021            1 curiosity                5            4 background
## 115    S021            1 curiosity                5            5    deviant
## 116    S022            1 curiosity                7            1 background
## 117    S022            1 curiosity                7            2 background
## 118    S022            1 curiosity                7            3 background
## 119    S022            1 curiosity                7            4 background
## 120    S022            1 curiosity                7            5 background
## 121    S022            1 curiosity                7            6 background
## 122    S022            1 curiosity                7            7    deviant
## 123    S023            1 curiosity                5            1 background
## 124    S023            1 curiosity                5            2 background
## 125    S023            1 curiosity                5            3 background
## 126    S023            1 curiosity                5            4 background
## 127    S023            1 curiosity                5            5    deviant
## 128    S024            1 curiosity                5            1 background
## 129    S024            1 curiosity                5            2 background
## 130    S024            1 curiosity                5            3 background
## 131    S024            1 curiosity                5            4 background
## 132    S024            1 curiosity                5            5    deviant
## 133    S025            1 curiosity                7            1 background
## 134    S025            1 curiosity                7            2 background
## 135    S025            1 curiosity                7            3 background
## 136    S025            1 curiosity                7            4 background
## 137    S025            1 curiosity                7            5 background
## 138    S025            1 curiosity                7            6 background
## 139    S025            1 curiosity                7            7    deviant
## 140    S026            1 curiosity                5            1 background
## 141    S026            1 curiosity                5            2 background
## 142    S026            1 curiosity                5            3 background
## 143    S026            1 curiosity                5            4 background
## 144    S026            1 curiosity                5            5    deviant
## 145    S027            1 curiosity                7            1 background
## 146    S027            1 curiosity                7            2 background
## 147    S027            1 curiosity                7            3 background
## 148    S027            1 curiosity                7            4 background
## 149    S027            1 curiosity                7            5 background
## 150    S027            1 curiosity                7            6 background
## 151    S027            1 curiosity                7            7    deviant
## 152    S028            1 curiosity                7            1 background
## 153    S028            1 curiosity                7            2 background
## 154    S028            1 curiosity                7            3 background
## 155    S028            1 curiosity                7            4 background
## 156    S028            1 curiosity                7            5 background
## 157    S028            1 curiosity                7            6 background
## 158    S028            1 curiosity                7            7    deviant
## 159    S029            1 curiosity                5            1 background
## 160    S029            1 curiosity                5            2 background
## 161    S029            1 curiosity                5            3 background
## 162    S029            1 curiosity                5            4 background
## 163    S029            1 curiosity                5            5    deviant
## 164    S030            1 curiosity                7            1 background
## 165    S030            1 curiosity                7            2 background
## 166    S030            1 curiosity                7            3 background
## 167    S030            1 curiosity                7            4 background
## 168    S030            1 curiosity                7            5 background
## 169    S030            1 curiosity                7            6 background
## 170    S030            1 curiosity                7            7    deviant
## 171    S031            1 curiosity                5            1 background
## 172    S031            1 curiosity                5            2 background
## 173    S031            1 curiosity                5            3 background
## 174    S031            1 curiosity                5            4 background
## 175    S031            1 curiosity                5            5    deviant
## 176    S032            1 curiosity                5            1 background
## 177    S032            1 curiosity                5            2 background
## 178    S032            1 curiosity                5            3 background
## 179    S032            1 curiosity                5            4 background
## 180    S032            1 curiosity                5            5    deviant
## 181    S033            1 curiosity                7            1 background
## 182    S033            1 curiosity                7            2 background
## 183    S033            1 curiosity                7            3 background
## 184    S033            1 curiosity                7            4 background
## 185    S033            1 curiosity                7            5 background
## 186    S033            1 curiosity                7            6 background
## 187    S033            1 curiosity                7            7    deviant
## 188    S034            1 curiosity                5            1 background
## 189    S034            1 curiosity                5            2 background
## 190    S034            1 curiosity                5            3 background
## 191    S034            1 curiosity                5            4 background
## 192    S034            1 curiosity                5            5    deviant
## 193    S035            1 curiosity                5            1 background
## 194    S035            1 curiosity                5            2 background
## 195    S035            1 curiosity                5            3 background
## 196    S035            1 curiosity                5            4 background
## 197    S035            1 curiosity                5            5    deviant
## 198    S036            1 curiosity                7            1 background
## 199    S036            1 curiosity                7            2 background
## 200    S036            1 curiosity                7            3 background
## 201    S036            1 curiosity                7            4 background
## 202    S036            1 curiosity                7            5 background
## 203    S036            1 curiosity                7            6 background
## 204    S036            1 curiosity                7            7    deviant
## 205    S037            1 curiosity                7            1 background
## 206    S037            1 curiosity                7            2 background
## 207    S037            1 curiosity                7            3 background
## 208    S037            1 curiosity                7            4 background
## 209    S037            1 curiosity                7            5 background
## 210    S037            1 curiosity                7            6 background
## 211    S037            1 curiosity                7            7    deviant
## 212    S038            1 curiosity                7            1 background
## 213    S038            1 curiosity                7            2 background
## 214    S038            1 curiosity                7            3 background
## 215    S038            1 curiosity                7            4 background
## 216    S038            1 curiosity                7            5 background
## 217    S038            1 curiosity                7            6 background
## 218    S038            1 curiosity                7            7    deviant
## 219    S039            1 curiosity                7            1 background
## 220    S039            1 curiosity                7            2 background
## 221    S039            1 curiosity                7            3 background
## 222    S039            1 curiosity                7            4 background
## 223    S039            1 curiosity                7            5 background
## 224    S039            1 curiosity                7            6 background
## 225    S039            1 curiosity                7            7    deviant
## 226    S040            1 curiosity                7            1 background
## 227    S040            1 curiosity                7            2 background
## 228    S040            1 curiosity                7            3 background
## 229    S040            1 curiosity                7            4 background
## 230    S040            1 curiosity                7            5 background
## 231    S040            1 curiosity                7            6 background
## 232    S040            1 curiosity                7            7    deviant
## 233    S041            1 curiosity                7            1 background
## 234    S041            1 curiosity                7            2 background
## 235    S041            1 curiosity                7            3 background
## 236    S041            1 curiosity                7            4 background
## 237    S041            1 curiosity                7            5 background
## 238    S041            1 curiosity                7            6 background
## 239    S041            1 curiosity                7            7    deviant
## 240    S042            1 curiosity                7            1 background
## 241    S042            1 curiosity                7            2 background
## 242    S042            1 curiosity                7            3 background
## 243    S042            1 curiosity                7            4 background
## 244    S042            1 curiosity                7            5 background
## 245    S042            1 curiosity                7            6 background
## 246    S042            1 curiosity                7            7    deviant
## 247    S043            1 curiosity                5            1 background
## 248    S043            1 curiosity                5            2 background
## 249    S043            1 curiosity                5            3 background
## 250    S043            1 curiosity                5            4 background
## 251    S043            1 curiosity                5            5    deviant
## 252    S044            1 curiosity                5            1 background
## 253    S044            1 curiosity                5            2 background
## 254    S044            1 curiosity                5            3 background
## 255    S044            1 curiosity                5            4 background
## 256    S044            1 curiosity                5            5    deviant
## 257    S045            1 curiosity                7            1 background
## 258    S045            1 curiosity                7            2 background
## 259    S045            1 curiosity                7            3 background
## 260    S045            1 curiosity                7            4 background
## 261    S045            1 curiosity                7            5 background
## 262    S045            1 curiosity                7            6 background
## 263    S045            1 curiosity                7            7    deviant
## 264    S046            1 curiosity                5            1 background
## 265    S046            1 curiosity                5            2 background
## 266    S046            1 curiosity                5            3 background
## 267    S046            1 curiosity                5            4 background
## 268    S046            1 curiosity                5            5    deviant
## 269    S047            1 curiosity                7            1 background
## 270    S047            1 curiosity                7            2 background
## 271    S047            1 curiosity                7            3 background
## 272    S047            1 curiosity                7            4 background
## 273    S047            1 curiosity                7            5 background
## 274    S047            1 curiosity                7            6 background
## 275    S047            1 curiosity                7            7    deviant
## 276    S048            1 curiosity                5            1 background
## 277    S048            1 curiosity                5            2 background
## 278    S048            1 curiosity                5            3 background
## 279    S048            1 curiosity                5            4 background
## 280    S048            1 curiosity                5            5    deviant
## 281    S049            1 curiosity                5            1 background
## 282    S049            1 curiosity                5            2 background
## 283    S049            1 curiosity                5            3 background
## 284    S049            1 curiosity                5            4 background
## 285    S049            1 curiosity                5            5    deviant
## 286    S050            1 curiosity                5            1 background
## 287    S050            1 curiosity                5            2 background
## 288    S050            1 curiosity                5            3 background
## 289    S050            1 curiosity                5            4 background
## 290    S050            1 curiosity                5            5    deviant
##     trial_looking_time        stimulus_displayed   task_question_type
## 1            4530.5691 images/stimuli/10_A_a.gif curiosity_background
## 2            3711.8192  images/stimuli/7_A_a.gif curiosity_background
## 3            2973.8823 images/stimuli/16_A_a.gif curiosity_background
## 4            1579.9735  images/stimuli/2_A_a.gif curiosity_background
## 5           24826.2379 images/stimuli/10_A_a.gif curiosity_background
## 6            4744.5113  images/stimuli/7_A_a.gif curiosity_background
## 7            2185.4554  images/stimuli/2_A_a.gif curiosity_background
## 8             562.7376 images/stimuli/14_A_a.gif curiosity_background
## 9             536.1869  images/stimuli/4_A_a.gif curiosity_background
## 10          29805.2450 images/stimuli/17_A_a.gif curiosity_background
## 11           4622.7696 images/stimuli/14_A_a.gif curiosity_background
## 12           3795.4479 images/stimuli/17_A_a.gif curiosity_background
## 13           3243.6982 images/stimuli/13_A_a.gif curiosity_background
## 14           1509.6746  images/stimuli/9_A_a.gif curiosity_background
## 15          28027.6102 images/stimuli/15_A_a.gif curiosity_background
## 16           4306.6773  images/stimuli/5_A_a.gif curiosity_background
## 17           3876.6916 images/stimuli/14_A_a.gif curiosity_background
## 18           2506.3544 images/stimuli/17_A_a.gif curiosity_background
## 19            991.7055  images/stimuli/2_A_a.gif curiosity_background
## 20          27955.3862 images/stimuli/19_A_a.gif curiosity_background
## 21           4118.9822  images/stimuli/6_A_a.gif curiosity_background
## 22           3110.9828 images/stimuli/12_A_a.gif curiosity_background
## 23           2066.1504 images/stimuli/19_A_a.gif curiosity_background
## 24            749.3667 images/stimuli/12_A_a.gif curiosity_background
## 25          23402.6573  images/stimuli/3_A_a.gif curiosity_background
## 26           2386.5477  images/stimuli/1_A_a.gif curiosity_background
## 27           1280.8042  images/stimuli/8_A_a.gif curiosity_background
## 28            713.0225  images/stimuli/1_A_a.gif curiosity_background
## 29            619.3817  images/stimuli/8_A_a.gif curiosity_background
## 30          23780.8653 images/stimuli/12_A_a.gif curiosity_background
## 31           3799.9701  images/stimuli/9_A_a.gif curiosity_background
## 32           3504.7307  images/stimuli/5_A_a.gif curiosity_background
## 33           3497.0298  images/stimuli/6_A_a.gif curiosity_background
## 34           1916.3316 images/stimuli/18_A_a.gif curiosity_background
## 35          24638.8671 images/stimuli/17_A_a.gif curiosity_background
## 36           4832.2214 images/stimuli/16_A_a.gif curiosity_background
## 37           4773.7580  images/stimuli/9_A_a.gif curiosity_background
## 38           4352.5087 images/stimuli/15_A_a.gif curiosity_background
## 39           2882.0080 images/stimuli/13_A_a.gif curiosity_background
## 40           2197.9113 images/stimuli/18_A_a.gif curiosity_background
## 41            848.9973 images/stimuli/15_A_a.gif curiosity_background
## 42          25494.3614 images/stimuli/12_A_a.gif curiosity_background
## 43           4222.4763 images/stimuli/11_A_a.gif curiosity_background
## 44           3033.9315 images/stimuli/11_A_a.gif curiosity_background
## 45           2623.7608  images/stimuli/6_A_a.gif curiosity_background
## 46           2554.1397  images/stimuli/4_A_a.gif curiosity_background
## 47           1546.2511 images/stimuli/15_A_a.gif curiosity_background
## 48           1365.5688 images/stimuli/17_A_a.gif curiosity_background
## 49          23140.7971  images/stimuli/8_A_a.gif curiosity_background
## 50           4695.3752  images/stimuli/7_A_a.gif curiosity_background
## 51           4190.1115  images/stimuli/4_A_a.gif curiosity_background
## 52           2898.8737 images/stimuli/10_A_a.gif curiosity_background
## 53           2230.1104 images/stimuli/16_A_a.gif curiosity_background
## 54          25459.8831 images/stimuli/16_A_a.gif curiosity_background
## 55           3831.1758 images/stimuli/10_A_a.gif curiosity_background
## 56           3139.1844  images/stimuli/5_A_a.gif curiosity_background
## 57           2942.1443 images/stimuli/12_A_a.gif curiosity_background
## 58           2749.3094  images/stimuli/4_A_a.gif curiosity_background
## 59           2310.3033  images/stimuli/3_A_a.gif curiosity_background
## 60           1276.5654  images/stimuli/7_A_a.gif curiosity_background
## 61          29363.5857 images/stimuli/11_A_a.gif curiosity_background
## 62           4998.4296 images/stimuli/10_A_a.gif curiosity_background
## 63           4871.4266  images/stimuli/2_A_a.gif curiosity_background
## 64           4098.8199  images/stimuli/3_A_a.gif curiosity_background
## 65           1297.9073 images/stimuli/13_A_a.gif curiosity_background
## 66          22607.4345  images/stimuli/7_A_a.gif curiosity_background
## 67           3579.5955  images/stimuli/9_A_a.gif curiosity_background
## 68           2939.7283  images/stimuli/4_A_a.gif curiosity_background
## 69           2548.3545 images/stimuli/20_A_a.gif curiosity_background
## 70           2368.3597 images/stimuli/15_A_a.gif curiosity_background
## 71          21270.6444 images/stimuli/17_A_a.gif curiosity_background
## 72           4949.0101 images/stimuli/12_A_a.gif curiosity_background
## 73           4731.1150 images/stimuli/13_A_a.gif curiosity_background
## 74           3781.8948 images/stimuli/16_A_a.gif curiosity_background
## 75           1761.1842 images/stimuli/10_A_a.gif curiosity_background
## 76           1475.5320  images/stimuli/5_A_a.gif curiosity_background
## 77            789.3454 images/stimuli/15_A_a.gif curiosity_background
## 78          22102.0848  images/stimuli/6_A_a.gif curiosity_background
## 79           4898.9710 images/stimuli/10_A_a.gif curiosity_background
## 80           2747.1365 images/stimuli/20_A_a.gif curiosity_background
## 81           2743.5725 images/stimuli/15_A_a.gif curiosity_background
## 82           2376.9576  images/stimuli/7_A_a.gif curiosity_background
## 83          23434.7225 images/stimuli/16_A_a.gif curiosity_background
## 84           4142.8000  images/stimuli/4_A_a.gif curiosity_background
## 85           3914.2665 images/stimuli/10_A_a.gif curiosity_background
## 86           3553.7139 images/stimuli/17_A_a.gif curiosity_background
## 87           2607.6880 images/stimuli/10_A_a.gif curiosity_background
## 88          26833.5962  images/stimuli/5_A_a.gif curiosity_background
## 89           4647.2837  images/stimuli/5_A_a.gif curiosity_background
## 90           3796.6527  images/stimuli/2_A_a.gif curiosity_background
## 91           2576.8871  images/stimuli/9_A_a.gif curiosity_background
## 92           2481.9824 images/stimuli/15_A_a.gif curiosity_background
## 93           1807.3336  images/stimuli/6_A_a.gif curiosity_background
## 94           1032.9994  images/stimuli/6_A_a.gif curiosity_background
## 95          26723.1443  images/stimuli/4_A_a.gif curiosity_background
## 96           3534.5672 images/stimuli/14_A_a.gif curiosity_background
## 97           2596.1945 images/stimuli/19_A_a.gif curiosity_background
## 98           2594.5361  images/stimuli/1_A_a.gif curiosity_background
## 99            998.4990  images/stimuli/3_A_a.gif curiosity_background
## 100         28750.2054  images/stimuli/5_A_a.gif curiosity_background
## 101          4947.0524  images/stimuli/8_A_a.gif curiosity_background
## 102          4612.1992  images/stimuli/5_A_a.gif curiosity_background
## 103          1087.7846 images/stimuli/12_A_a.gif curiosity_background
## 104           699.8768 images/stimuli/20_A_a.gif curiosity_background
## 105         23894.7935 images/stimuli/20_A_a.gif curiosity_background
## 106          4201.9657 images/stimuli/15_A_a.gif curiosity_background
## 107          4163.6466 images/stimuli/10_A_a.gif curiosity_background
## 108          2541.5791 images/stimuli/20_A_a.gif curiosity_background
## 109          2164.8411  images/stimuli/9_A_a.gif curiosity_background
## 110         25126.2427  images/stimuli/9_A_a.gif curiosity_background
## 111          4690.1847 images/stimuli/14_A_a.gif curiosity_background
## 112          3856.1737 images/stimuli/13_A_a.gif curiosity_background
## 113          2570.5666 images/stimuli/15_A_a.gif curiosity_background
## 114          2254.4633 images/stimuli/14_A_a.gif curiosity_background
## 115         27836.0850  images/stimuli/7_A_a.gif curiosity_background
## 116          4803.1263 images/stimuli/13_A_a.gif curiosity_background
## 117          4618.0936 images/stimuli/14_A_a.gif curiosity_background
## 118          3625.0321 images/stimuli/13_A_a.gif curiosity_background
## 119          2737.7093 images/stimuli/13_A_a.gif curiosity_background
## 120          1700.0128 images/stimuli/14_A_a.gif curiosity_background
## 121          1595.9635 images/stimuli/18_A_a.gif curiosity_background
## 122         26089.2179 images/stimuli/20_A_a.gif curiosity_background
## 123          4615.4989  images/stimuli/6_A_a.gif curiosity_background
## 124          4133.8395 images/stimuli/17_A_a.gif curiosity_background
## 125          2458.8507  images/stimuli/6_A_a.gif curiosity_background
## 126          1875.2587  images/stimuli/4_A_a.gif curiosity_background
## 127         26298.2939 images/stimuli/10_A_a.gif curiosity_background
## 128          3056.6137  images/stimuli/7_A_a.gif curiosity_background
## 129          2223.5959 images/stimuli/20_A_a.gif curiosity_background
## 130          2148.4756 images/stimuli/18_A_a.gif curiosity_background
## 131          1414.5742  images/stimuli/8_A_a.gif curiosity_background
## 132         25352.6539  images/stimuli/9_A_a.gif curiosity_background
## 133          4580.4239  images/stimuli/8_A_a.gif curiosity_background
## 134          4020.5992  images/stimuli/3_A_a.gif curiosity_background
## 135          2547.8127  images/stimuli/6_A_a.gif curiosity_background
## 136          1350.5299  images/stimuli/8_A_a.gif curiosity_background
## 137           860.5485 images/stimuli/15_A_a.gif curiosity_background
## 138           644.1577 images/stimuli/17_A_a.gif curiosity_background
## 139         27460.9587 images/stimuli/20_A_a.gif curiosity_background
## 140          4949.6794 images/stimuli/10_A_a.gif curiosity_background
## 141          3474.4361 images/stimuli/20_A_a.gif curiosity_background
## 142          1895.1122  images/stimuli/9_A_a.gif curiosity_background
## 143          1117.0890 images/stimuli/15_A_a.gif curiosity_background
## 144         25849.1338 images/stimuli/10_A_a.gif curiosity_background
## 145          4924.8447  images/stimuli/2_A_a.gif curiosity_background
## 146          4409.2343 images/stimuli/10_A_a.gif curiosity_background
## 147          4243.2708 images/stimuli/20_A_a.gif curiosity_background
## 148          3500.8260  images/stimuli/6_A_a.gif curiosity_background
## 149          3392.8706  images/stimuli/5_A_a.gif curiosity_background
## 150          2730.5574 images/stimuli/18_A_a.gif curiosity_background
## 151         20451.4528  images/stimuli/9_A_a.gif curiosity_background
## 152          4527.2881  images/stimuli/4_A_a.gif curiosity_background
## 153          2949.9703 images/stimuli/12_A_a.gif curiosity_background
## 154          2247.9489 images/stimuli/11_A_a.gif curiosity_background
## 155          1747.6451 images/stimuli/11_A_a.gif curiosity_background
## 156          1010.2786 images/stimuli/10_A_a.gif curiosity_background
## 157           638.7218 images/stimuli/19_A_a.gif curiosity_background
## 158         27195.1983  images/stimuli/7_A_a.gif curiosity_background
## 159          4767.3471 images/stimuli/20_A_a.gif curiosity_background
## 160          4061.0859  images/stimuli/1_A_a.gif curiosity_background
## 161          3473.0410 images/stimuli/20_A_a.gif curiosity_background
## 162          2206.4439 images/stimuli/19_A_a.gif curiosity_background
## 163         24327.6510  images/stimuli/7_A_a.gif curiosity_background
## 164          4742.1508  images/stimuli/1_A_a.gif curiosity_background
## 165          3811.0037  images/stimuli/5_A_a.gif curiosity_background
## 166          3044.0510 images/stimuli/12_A_a.gif curiosity_background
## 167          2638.9050 images/stimuli/20_A_a.gif curiosity_background
## 168          2298.8482  images/stimuli/7_A_a.gif curiosity_background
## 169           863.9466  images/stimuli/1_A_a.gif curiosity_background
## 170         21818.4325  images/stimuli/9_A_a.gif curiosity_background
## 171          3651.5829  images/stimuli/9_A_a.gif curiosity_background
## 172          3055.8331 images/stimuli/15_A_a.gif curiosity_background
## 173          2033.9219  images/stimuli/1_A_a.gif curiosity_background
## 174          1608.5705 images/stimuli/11_A_a.gif curiosity_background
## 175         28397.6195  images/stimuli/1_A_a.gif curiosity_background
## 176          4656.4414  images/stimuli/3_A_a.gif curiosity_background
## 177          1704.9003  images/stimuli/7_A_a.gif curiosity_background
## 178          1520.6249 images/stimuli/10_A_a.gif curiosity_background
## 179          1053.5141  images/stimuli/3_A_a.gif curiosity_background
## 180         20564.8416 images/stimuli/20_A_a.gif curiosity_background
## 181          4002.0121 images/stimuli/11_A_a.gif curiosity_background
## 182          3515.6286 images/stimuli/14_A_a.gif curiosity_background
## 183          2799.9935  images/stimuli/5_A_a.gif curiosity_background
## 184          1463.0093 images/stimuli/11_A_a.gif curiosity_background
## 185          1344.6198  images/stimuli/5_A_a.gif curiosity_background
## 186           846.0838  images/stimuli/1_A_a.gif curiosity_background
## 187         26111.4718  images/stimuli/2_A_a.gif curiosity_background
## 188          4095.7081  images/stimuli/4_A_a.gif curiosity_background
## 189          3947.4238  images/stimuli/8_A_a.gif curiosity_background
## 190          2851.7179 images/stimuli/14_A_a.gif curiosity_background
## 191           555.1975  images/stimuli/8_A_a.gif curiosity_background
## 192         22074.5557 images/stimuli/10_A_a.gif curiosity_background
## 193          3713.7098  images/stimuli/2_A_a.gif curiosity_background
## 194          3530.8110  images/stimuli/8_A_a.gif curiosity_background
## 195          1836.6772  images/stimuli/5_A_a.gif curiosity_background
## 196          1760.4738 images/stimuli/20_A_a.gif curiosity_background
## 197         25710.4577  images/stimuli/6_A_a.gif curiosity_background
## 198          4789.3192  images/stimuli/6_A_a.gif curiosity_background
## 199          4549.3566  images/stimuli/2_A_a.gif curiosity_background
## 200          3529.1410 images/stimuli/18_A_a.gif curiosity_background
## 201          2316.4141  images/stimuli/7_A_a.gif curiosity_background
## 202          2199.7398  images/stimuli/3_A_a.gif curiosity_background
## 203          1104.6714  images/stimuli/3_A_a.gif curiosity_background
## 204         28033.4101 images/stimuli/13_A_a.gif curiosity_background
## 205          4761.5687 images/stimuli/16_A_a.gif curiosity_background
## 206          4669.1986 images/stimuli/12_A_a.gif curiosity_background
## 207          3232.4135 images/stimuli/15_A_a.gif curiosity_background
## 208          2401.6378 images/stimuli/20_A_a.gif curiosity_background
## 209          1927.2845  images/stimuli/1_A_a.gif curiosity_background
## 210           948.3849 images/stimuli/12_A_a.gif curiosity_background
## 211         28662.8896 images/stimuli/20_A_a.gif curiosity_background
## 212          4356.8312 images/stimuli/15_A_a.gif curiosity_background
## 213          4157.3725 images/stimuli/17_A_a.gif curiosity_background
## 214          2811.9732 images/stimuli/15_A_a.gif curiosity_background
## 215          1632.2961 images/stimuli/13_A_a.gif curiosity_background
## 216           801.5115 images/stimuli/17_A_a.gif curiosity_background
## 217           617.8707 images/stimuli/17_A_a.gif curiosity_background
## 218         25962.5631  images/stimuli/4_A_a.gif curiosity_background
## 219          4706.5061  images/stimuli/2_A_a.gif curiosity_background
## 220          4299.6171  images/stimuli/5_A_a.gif curiosity_background
## 221          3958.3407  images/stimuli/3_A_a.gif curiosity_background
## 222          2685.4929  images/stimuli/5_A_a.gif curiosity_background
## 223          2410.5801  images/stimuli/4_A_a.gif curiosity_background
## 224          1864.0978 images/stimuli/13_A_a.gif curiosity_background
## 225         22522.7682 images/stimuli/16_A_a.gif curiosity_background
## 226          4151.1245 images/stimuli/16_A_a.gif curiosity_background
## 227          3215.3762 images/stimuli/12_A_a.gif curiosity_background
## 228          1683.3858 images/stimuli/10_A_a.gif curiosity_background
## 229          1122.2931  images/stimuli/8_A_a.gif curiosity_background
## 230           974.2542 images/stimuli/20_A_a.gif curiosity_background
## 231           679.7613 images/stimuli/18_A_a.gif curiosity_background
## 232         21754.0582 images/stimuli/20_A_a.gif curiosity_background
## 233          4834.8821 images/stimuli/10_A_a.gif curiosity_background
## 234          4383.0236  images/stimuli/8_A_a.gif curiosity_background
## 235          3031.6641 images/stimuli/12_A_a.gif curiosity_background
## 236          2449.6220 images/stimuli/14_A_a.gif curiosity_background
## 237          1651.1905 images/stimuli/19_A_a.gif curiosity_background
## 238          1109.4374  images/stimuli/7_A_a.gif curiosity_background
## 239         29154.7694  images/stimuli/9_A_a.gif curiosity_background
## 240          3747.5569 images/stimuli/11_A_a.gif curiosity_background
## 241          3210.1990  images/stimuli/4_A_a.gif curiosity_background
## 242          3123.6029  images/stimuli/4_A_a.gif curiosity_background
## 243          2869.1305  images/stimuli/6_A_a.gif curiosity_background
## 244          2091.9504 images/stimuli/20_A_a.gif curiosity_background
## 245           860.2780 images/stimuli/17_A_a.gif curiosity_background
## 246         21283.9282 images/stimuli/15_A_a.gif curiosity_background
## 247          4077.1385  images/stimuli/5_A_a.gif curiosity_background
## 248          3964.2669 images/stimuli/11_A_a.gif curiosity_background
## 249          2296.2423 images/stimuli/17_A_a.gif curiosity_background
## 250          2281.3821 images/stimuli/11_A_a.gif curiosity_background
## 251         26301.9679  images/stimuli/4_A_a.gif curiosity_background
## 252          4586.1748 images/stimuli/11_A_a.gif curiosity_background
## 253          4032.5027 images/stimuli/19_A_a.gif curiosity_background
## 254          3350.4112  images/stimuli/9_A_a.gif curiosity_background
## 255          2117.4359 images/stimuli/10_A_a.gif curiosity_background
## 256         26151.1629 images/stimuli/16_A_a.gif curiosity_background
## 257          3718.0301 images/stimuli/19_A_a.gif curiosity_background
## 258          1908.7740 images/stimuli/19_A_a.gif curiosity_background
## 259          1651.2523 images/stimuli/18_A_a.gif curiosity_background
## 260          1349.0579  images/stimuli/6_A_a.gif curiosity_background
## 261          1139.8158  images/stimuli/8_A_a.gif curiosity_background
## 262          1124.6638  images/stimuli/7_A_a.gif curiosity_background
## 263         25741.1162 images/stimuli/12_A_a.gif curiosity_background
## 264          4875.9306  images/stimuli/2_A_a.gif curiosity_background
## 265          4009.8162  images/stimuli/1_A_a.gif curiosity_background
## 266          3584.1176 images/stimuli/19_A_a.gif curiosity_background
## 267           592.0395 images/stimuli/15_A_a.gif curiosity_background
## 268         27284.6574 images/stimuli/13_A_a.gif curiosity_background
## 269          4881.5534 images/stimuli/20_A_a.gif curiosity_background
## 270          4879.5191 images/stimuli/17_A_a.gif curiosity_background
## 271          4396.1805 images/stimuli/13_A_a.gif curiosity_background
## 272          3821.5637  images/stimuli/6_A_a.gif curiosity_background
## 273          3106.9271  images/stimuli/2_A_a.gif curiosity_background
## 274          1291.2562 images/stimuli/12_A_a.gif curiosity_background
## 275         26474.8610  images/stimuli/9_A_a.gif curiosity_background
## 276          4796.5560  images/stimuli/2_A_a.gif curiosity_background
## 277          3018.8374 images/stimuli/18_A_a.gif curiosity_background
## 278          1180.5433  images/stimuli/7_A_a.gif curiosity_background
## 279           943.8609  images/stimuli/5_A_a.gif curiosity_background
## 280         26234.4997 images/stimuli/15_A_a.gif curiosity_background
## 281          3780.0614 images/stimuli/16_A_a.gif curiosity_background
## 282          3129.6262 images/stimuli/15_A_a.gif curiosity_background
## 283          2836.2336 images/stimuli/14_A_a.gif curiosity_background
## 284           860.3518 images/stimuli/10_A_a.gif curiosity_background
## 285         26140.6653 images/stimuli/16_A_a.gif curiosity_background
## 286          4697.5108 images/stimuli/13_A_a.gif curiosity_background
## 287          2398.4414  images/stimuli/8_A_a.gif curiosity_background
## 288          1004.9417  images/stimuli/8_A_a.gif curiosity_background
## 289           982.9847 images/stimuli/18_A_a.gif curiosity_background
## 290         25633.1149  images/stimuli/7_A_a.gif curiosity_background
##     task_question_response
## 1                        3
## 2                        2
## 3                        5
## 4                        1
## 5                        1
## 6                        3
## 7                        3
## 8                        4
## 9                        2
## 10                       2
## 11                       4
## 12                       3
## 13                       2
## 14                       2
## 15                       4
## 16                       5
## 17                       3
## 18                       1
## 19                       2
## 20                       5
## 21                       4
## 22                       5
## 23                       2
## 24                       5
## 25                       5
## 26                       2
## 27                       2
## 28                       4
## 29                       2
## 30                       2
## 31                       3
## 32                       4
## 33                       2
## 34                       2
## 35                       5
## 36                       5
## 37                       1
## 38                       5
## 39                       3
## 40                       5
## 41                       2
## 42                       1
## 43                       1
## 44                       3
## 45                       2
## 46                       1
## 47                       4
## 48                       3
## 49                       2
## 50                       3
## 51                       3
## 52                       3
## 53                       5
## 54                       3
## 55                       2
## 56                       1
## 57                       5
## 58                       3
## 59                       3
## 60                       5
## 61                       5
## 62                       5
## 63                       4
## 64                       5
## 65                       2
## 66                       1
## 67                       3
## 68                       2
## 69                       3
## 70                       3
## 71                       5
## 72                       5
## 73                       1
## 74                       2
## 75                       5
## 76                       3
## 77                       4
## 78                       5
## 79                       4
## 80                       4
## 81                       1
## 82                       4
## 83                       3
## 84                       3
## 85                       1
## 86                       4
## 87                       5
## 88                       4
## 89                       3
## 90                       1
## 91                       3
## 92                       5
## 93                       5
## 94                       2
## 95                       5
## 96                       5
## 97                       3
## 98                       5
## 99                       1
## 100                      1
## 101                      5
## 102                      1
## 103                      2
## 104                      3
## 105                      3
## 106                      5
## 107                      1
## 108                      1
## 109                      2
## 110                      5
## 111                      2
## 112                      5
## 113                      4
## 114                      1
## 115                      5
## 116                      4
## 117                      3
## 118                      1
## 119                      5
## 120                      2
## 121                      1
## 122                      4
## 123                      5
## 124                      2
## 125                      4
## 126                      2
## 127                      1
## 128                      5
## 129                      3
## 130                      3
## 131                      2
## 132                      5
## 133                      3
## 134                      2
## 135                      3
## 136                      5
## 137                      3
## 138                      5
## 139                      4
## 140                      2
## 141                      3
## 142                      4
## 143                      2
## 144                      3
## 145                      3
## 146                      3
## 147                      5
## 148                      1
## 149                      3
## 150                      1
## 151                      5
## 152                      5
## 153                      1
## 154                      5
## 155                      3
## 156                      2
## 157                      5
## 158                      3
## 159                      2
## 160                      4
## 161                      5
## 162                      2
## 163                      3
## 164                      2
## 165                      3
## 166                      1
## 167                      4
## 168                      4
## 169                      2
## 170                      3
## 171                      5
## 172                      1
## 173                      1
## 174                      4
## 175                      3
## 176                      4
## 177                      3
## 178                      5
## 179                      4
## 180                      2
## 181                      4
## 182                      3
## 183                      5
## 184                      3
## 185                      5
## 186                      3
## 187                      4
## 188                      4
## 189                      3
## 190                      5
## 191                      2
## 192                      4
## 193                      3
## 194                      4
## 195                      3
## 196                      1
## 197                      4
## 198                      1
## 199                      1
## 200                      4
## 201                      3
## 202                      2
## 203                      4
## 204                      5
## 205                      2
## 206                      3
## 207                      4
## 208                      4
## 209                      4
## 210                      2
## 211                      2
## 212                      2
## 213                      4
## 214                      1
## 215                      3
## 216                      3
## 217                      3
## 218                      2
## 219                      5
## 220                      4
## 221                      2
## 222                      1
## 223                      5
## 224                      5
## 225                      3
## 226                      2
## 227                      5
## 228                      1
## 229                      3
## 230                      3
## 231                      4
## 232                      5
## 233                      2
## 234                      2
## 235                      5
## 236                      1
## 237                      2
## 238                      3
## 239                      4
## 240                      1
## 241                      3
## 242                      2
## 243                      1
## 244                      1
## 245                      2
## 246                      5
## 247                      4
## 248                      2
## 249                      1
## 250                      2
## 251                      1
## 252                      4
## 253                      5
## 254                      4
## 255                      5
## 256                      4
## 257                      4
## 258                      4
## 259                      1
## 260                      2
## 261                      4
## 262                      2
## 263                      2
## 264                      3
## 265                      2
## 266                      3
## 267                      1
## 268                      4
## 269                      1
## 270                      3
## 271                      4
## 272                      3
## 273                      2
## 274                      4
## 275                      3
## 276                      5
## 277                      5
## 278                      5
## 279                      4
## 280                      4
## 281                      5
## 282                      5
## 283                      3
## 284                      2
## 285                      2
## 286                      5
## 287                      2
## 288                      4
## 289                      3
## 290                      5
fake_data_rnr$trial_type_numeric <- as.numeric(as.factor(fake_data_rnr$trial_type))


# Define the nonlinear model
exp_decay <- function(trial_number, trial_type_numeric, a, b) {
  a * exp(b * trial_number * trial_type_numeric)
}

# Fit the model
habituation_model <- nlme(
  trial_looking_time ~ exp_decay(trial_number, trial_type_numeric, a, b),
  data = fake_data_rnr,
  fixed = a + b ~ 1,
  random =  b ~ 1 + trial_number | subject,  # Add random intercept
  start = c(a = mean(fake_data_rnr$trial_looking_time), 
            b = -0.01),          # Adjust starting values
  control = nlmeControl(msMaxIter = 200, pnlsTol = 1e-6)
)

fake_data_rnr$resid = resid(habituation_model)


adult_dishab_raw <- fake_data_rnr %>% 
  filter(trial_number == deviant_position) 

adult_dishab_d <- adult_dishab_raw %>% 
  select(subject,block_number, resid) %>% 
  rename(dishab_raw = resid) %>% 
  left_join(
    fake_data_rnr  %>% filter(trial_number < deviant_position) %>% group_by(subject, block_number) %>% filter(trial_number == max(trial_number)),
    by = c("subject", "block_number")
  ) %>% 
  # calculating the key 
  mutate(
    dishab_diff_resid = dishab_raw - resid) %>% 
  mutate(dishab_trial_num = trial_number + 1) %>% 
  select(subject, dishab_diff_resid, dishab_trial_num)

adult_dishab_d %>% 
  left_join(adult_slope_df) %>% 
  ggplot(aes(x = decay_rate, y = dishab_diff_resid)) + 
  geom_point() + 
  geom_smooth(method = "lm") + 
  labs(
    title = "No relationship", 
    subtitle = "dishab log diff ~ slope"
  )
## Joining with `by = join_by(subject)`
## `geom_smooth()` using formula = 'y ~ x'

6.1. piece-wise combination

change the model by piece wise combination - this works!

# Separate habituation and deviant trials
habituation_data <- fake_data_rnr %>%
  filter(trial_type == "background")  # Habituation trials only

deviant_data <- fake_data_rnr %>%
  filter(trial_type == "deviant")  # Deviant trial only

# Nonlinear mixed-effects model for habituation trials
habituation_model <- nlme(
  trial_looking_time ~ a * exp(b * trial_number),
  data = habituation_data,
  fixed = a + b ~ 1,                    # Fixed effects for decay
  random = b ~ 1 | subject,         # Random intercept and slope
  start = c(a = mean(habituation_data$trial_looking_time), b = -0.1),        # Initial guesses for parameters
  control = nlmeControl(msMaxIter = 200, pnlsTol = 1e-6)  # Controls for stability
)

deviant_model <- lme(
  trial_looking_time ~ 1,  # Deviant trial modeled as intercept-only
  random = ~ 1 | subject,  # Random intercept to account for subject variability
  data = deviant_data
)

habituation_data$resid_hab <- resid(habituation_model)
deviant_data$resid_dev <- resid(deviant_model)

# Merge the residuals for analysis
combined_residuals <- habituation_data %>%
  select(subject, trial_number, resid_hab) %>%
  bind_rows(
    deviant_data %>%
      select(subject, trial_number, resid_dev) %>%
      rename(resid_hab = resid_dev)
  )


random_effects <- ranef(habituation_model)$b
fixed_decay_rate <- fixef(habituation_model)["b"]
individual_decay_rates <- fixed_decay_rate + random_effects




deviant_resid_data <- deviant_data %>%
  mutate(decay_rate = individual_decay_rates)


ggplot(deviant_resid_data, aes(x = decay_rate, y = resid_dev)) +
  geom_point() +
  geom_smooth(method = "lm") +
  labs(title = "Decay Rate vs Deviant Residuals",
       x = "Decay Rate",
       y = "Deviant Residuals")
## `geom_smooth()` using formula = 'y ~ x'

7. do Z score within participant

fake_data_rnr <-  fake_data_rnr %>% group_by(subject) %>%
  mutate(z_score_looking_time = (trial_looking_time - mean(trial_looking_time)) / sd(trial_looking_time)) %>%
  ungroup()


fake_data_rnr
## # A tibble: 290 × 13
##    subject block_number task_type deviant_position trial_number trial_type
##    <chr>          <dbl> <chr>                <dbl>        <int> <chr>     
##  1 S001               1 curiosity                5            1 background
##  2 S001               1 curiosity                5            2 background
##  3 S001               1 curiosity                5            3 background
##  4 S001               1 curiosity                5            4 background
##  5 S001               1 curiosity                5            5 deviant   
##  6 S002               1 curiosity                5            1 background
##  7 S002               1 curiosity                5            2 background
##  8 S002               1 curiosity                5            3 background
##  9 S002               1 curiosity                5            4 background
## 10 S002               1 curiosity                5            5 deviant   
## # ℹ 280 more rows
## # ℹ 7 more variables: trial_looking_time <dbl>, stimulus_displayed <chr>,
## #   task_question_type <chr>, task_question_response <int>,
## #   trial_type_numeric <dbl>, resid <dbl>, z_score_looking_time <dbl>
habituation_data <-  fake_data_rnr %>% 
  # fist block
  # before the dishabituation trials
  filter(trial_number < deviant_position) %>% 
  # only keeping the relevant information 
  select(subject, trial_number, z_score_looking_time) %>% 
  rename(trial_looking_time = z_score_looking_time)

adult_slope_df <- get_individual_slope(habituation_data)



adult_dishab_raw <- fake_data_rnr %>% 
  filter(trial_number == deviant_position) 

adult_dishab_d <- adult_dishab_raw %>% 
  select(subject,block_number, z_score_looking_time, trial_looking_time) %>% 
  rename(dishab_raw = z_score_looking_time) %>% 
  left_join(
    fake_data_rnr  %>% filter(trial_number < deviant_position) %>% group_by(subject, block_number) %>% filter(trial_number == max(trial_number)),
    by = c("subject", "block_number")
  ) %>% 
  # calculating the key 
  mutate(
    dishab_z_score_diff = dishab_raw - z_score_looking_time) %>% 
  mutate(dishab_trial_num = trial_number + 1) %>% 
  select(subject, dishab_z_score_diff, dishab_trial_num)
adult_dishab_d %>% 
  left_join(adult_slope_df) %>% 
  ggplot(aes(x = decay_rate, y = dishab_z_score_diff)) + 
  geom_point() + 
  geom_smooth(method = "lm") + 
  labs(
    title = "No relationship", 
    subtitle = "dishab log diff ~ slope"
  )
## Joining with `by = join_by(subject)`
## `geom_smooth()` using formula = 'y ~ x'

8. Try to see if the piece-wise destroy the constructed relationship?

no – if there’s a real realtionship it’s still there!

# Generate synthetic data
generate_fake_data <- function(n_subjects = 50) {
  # Create subject IDs
  subjects <- paste0("S", sprintf("%03d", 1:n_subjects))

  # Initialize empty data frame
  data <- data.frame()

  # Loop through each subject
  for (subj in subjects) {
    # Randomly assign number of habituation trials (4 or 6)
    n_trials <- sample(c(4, 6), 1)
    trial_number <- 1:(n_trials + 1)

    # Simulate exponential drop in habituation times with varying slopes
    initial_looking_time <- runif(1, 5000, 10000)
    decay_rate <- runif(1, 0.2, 0.5)  # Randomly vary decay rate
    habituation_times <- initial_looking_time * exp(-decay_rate * (1:n_trials))
    deviant_time <- 10000 * decay_rate + rnorm(1, 0, 500)  # Linearly related to the decay slope

    # Combine looking times
    trial_looking_time <- c(habituation_times, deviant_time)

    # Assign trial types
    trial_type <- c(rep('background', n_trials), 'deviant')

    # Create data frame for subject
    subject_data <- data.frame(
      subject = subj,
      block_number = 1,
      task_type = 'curiosity',
      deviant_position = n_trials + 1,
      trial_number = trial_number,
      trial_type = trial_type,
      trial_looking_time = trial_looking_time,
      stimulus_displayed = paste0('images/stimuli/', sample(1:20, n_trials + 1, replace = TRUE), '_A_a.gif'),
      task_question_type = 'curiosity_background',
      task_question_response = sample(1:5, n_trials + 1, replace = TRUE)
    )

    # Append subject data
    data <- rbind(data, subject_data)
  }

  return(data)
}

# Generate dataset
fake_data_slope <- generate_fake_data(n_subjects = 50)
# Separate habituation and deviant trials
habituation_data <- fake_data_slope %>%
  filter(trial_type == "background")  # Habituation trials only

deviant_data <- fake_data_slope %>%
  filter(trial_type == "deviant")  # Deviant trial only

# Nonlinear mixed-effects model for habituation trials
habituation_model <- nlme(
  trial_looking_time ~ a * exp(b * trial_number),
  data = habituation_data,
  fixed = a + b ~ 1,                    # Fixed effects for decay
  random = b ~ 1 | subject,         # Random intercept and slope
  start = c(a = mean(habituation_data$trial_looking_time), b = -0.1),        # Initial guesses for parameters
  control = nlmeControl(msMaxIter = 200, pnlsTol = 1e-6)  # Controls for stability
)

deviant_model <- lme(
  trial_looking_time ~ 1,  # Deviant trial modeled as intercept-only
  random = ~ 1 | subject,  # Random intercept to account for subject variability
  data = deviant_data
)

habituation_data$resid_hab <- resid(habituation_model)
deviant_data$resid_dev <- resid(deviant_model)

# Merge the residuals for analysis
combined_residuals <- habituation_data %>%
  select(subject, trial_number, resid_hab) %>%
  bind_rows(
    deviant_data %>%
      select(subject, trial_number, resid_dev) %>%
      rename(resid_hab = resid_dev)
  )


random_effects <- ranef(habituation_model)$b
fixed_decay_rate <- fixef(habituation_model)["b"]
individual_decay_rates <- fixed_decay_rate + random_effects




deviant_resid_data <- deviant_data %>%
  mutate(decay_rate = individual_decay_rates)


ggplot(deviant_resid_data, aes(x = decay_rate, y = resid_dev)) +
  geom_point() +
  geom_smooth(method = "lm") +
  labs(title = "Decay Rate vs Deviant Residuals",
       x = "Decay Rate",
       y = "Deviant Residuals")
## `geom_smooth()` using formula = 'y ~ x'