通过负转换时间定制注视数据

问题描述 投票:0回答:1

在对话中提出问题 (

aoi_C_aoi
) 时,我会使用注视数据(此处,
aoi_C_dur
给出注视固定情况,
Utterance
给出这些注视固定的持续时间)。我正在解决的问题是,如果对问题的响应在 Utterance 完成之前出现,如何
定制注视数据
,在这种情况下,
Trans_new
值(给出问题和答案之间的时间)为负数:

df
  Sequ  Utterance Trans_new     aoi_C_aoi            aoi_C_dur
1   55  where...?      -125 B, *, A, *, B 59, 110, 72, 50, 100
2   77 what's...?      -333          *, A             299, 401

我通过旋转更长的时间并将所有注视数据分成行来解决这个问题:

df %>% 
  
  # pivot longer:
  pivot_longer(matches("aoi"),
               names_to = c("Gaze_by", ".value"),
               names_pattern = "([ABC])_(.+)") %>%
  # rename more explicitly:
  rename(Gaze_to = aoi) %>%
  # trim whitespace:
  mutate(Gaze_to = trimws(Gaze_to)) %>%
  
  # separate individual data points into rows:
  separate_rows(c(Gaze_to, dur), sep = ", ", convert = TRUE)

但是从这里开始,我不知道如何继续。 所需的输出是这样的:

   Sequ Utterance  Trans_new Gaze_by Gaze_to   dur
  <dbl> <chr>          <dbl> <chr>   <chr>   <int>
1    55 where...?       -125 C       B          59
2    55 where...?       -125 C       *         110
3    55 where...?       -125 C       A          72
4    55 where...?       -125 C       *          25     # 150 - 125 = 25
#5    55 where...?       -125 C       B         100    # removed as 100 < abs(-125)
6    77 what's...?      -333 C       *         299
7    77 what's...?      -333 C       A         68      # 401 - 333 = 68

可重复的数据

df <- data.frame(
  Sequ = c(55,77),
  Utterance = c("where...?", "what's...?"),
  Trans_new = c(-125, -333),
  aoi_C_aoi = c("B, *, A, *, B", "*, A"),       
  aoi_C_dur = c("59, 110, 72, 50, 100", "299, 401")
)

任何帮助寻找

tidyverse
解决方案的帮助都将不胜感激。

r dplyr tidyr
1个回答
0
投票

这是我自己的解决方案。主要的“技巧”是计算从下到上的累积持续时间,这样我们就可以看到哪些凝视落入过渡阶段以及它们做了多少:

df %>% 
  
  # pivot longer:
  pivot_longer(matches("aoi"),
               names_to = c("Gaze_by", ".value"),
               names_pattern = "([ABC])_(.+)") %>%
  # rename for clarity:
  rename(Gaze_to = aoi) %>%
  # trim whitespace:
  mutate(Gaze_to = trimws(Gaze_to)) %>%
  
  # separate individual data points into rows:
  separate_rows(c(Gaze_to, dur), sep = ", ", convert = TRUE) %>%
  
  group_by(Sequ, Gaze_by) %>%
  mutate(
    # compute cumulative duration from bottom up:
    cumdur_1 = rev(cumsum(rev(dur))),
    # add transition time to cumulative duration (works for negative and positive transitions!):
    dur_1 = cumdur_1 + Trans_new,
         ) %>%
  
  # remove rows with negative `dur_1` values (where gazes fall within the negative transition time):
  filter(dur_1 >= 0) %>%
  
  # determine adjusted gaze durations:
                   # if `dur_1` value IS `last(dur_1)`, take that value, else take value from `dur`:
  mutate(dur_adj = ifelse(dur_1 == last(dur_1), dur_1, dur)) %>%
  ungroup()
© www.soinside.com 2019 - 2024. All rights reserved.