#Load packages 

library(lme4)
## Loading required package: Matrix
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.3     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ tidyr::expand() masks Matrix::expand()
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ✖ tidyr::pack()   masks Matrix::pack()
## ✖ tidyr::unpack() masks Matrix::unpack()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(afex)
## ************
## Welcome to afex. For support visit: http://afex.singmann.science/
## - Functions for ANOVAs: aov_car(), aov_ez(), and aov_4()
## - Methods for calculating p-values with mixed(): 'S', 'KR', 'LRT', and 'PB'
## - 'afex_aov' and 'mixed' objects can be passed to emmeans() for follow-up tests
## - Get and set global package options with: afex_options()
## - Set sum-to-zero contrasts globally: set_sum_contrasts()
## - For example analyses see: browseVignettes("afex")
## ************
## 
## Attaching package: 'afex'
## 
## The following object is masked from 'package:lme4':
## 
##     lmer
getwd()
## [1] "/Users/maggie/Downloads/bookR"
setwd("/Users/maggie/Downloads/bookR")

#Load data, and name that object "Sheet 1-stim_IA_full.csv"

stimIA_data <- read_csv("Sheet 1-stim_IA_full.csv")
## Rows: 12183 Columns: 183
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (143): RECORDING_SESSION_LABEL, TRIAL_LABEL, IA_LABEL, IA_FIRST_RUN_DWEL...
## dbl  (36): TRIAL_INDEX, IA_ID, IA_DWELL_TIME, IA_FIXATION_COUNT, IP_INDEX, A...
## lgl   (4): IA_DYNAMIC, IP_END_EVENT_MATCHED, IP_START_EVENT_MATCHED, Trial_R...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#View the first six rows of the data frame

head(stimIA_data)
## # A tibble: 6 × 183
##   RECORDING_SESSION_LABEL TRIAL_INDEX TRIAL_LABEL IA_ID IA_LABEL IA_DWELL_TIME
##   <chr>                         <dbl> <chr>       <dbl> <chr>            <dbl>
## 1 01LYX                             1 Trial: 1        5 Her                  0
## 2 01LYX                             1 Trial: 1        6 collar               0
## 3 01LYX                             1 Trial: 1        7 is                   0
## 4 01LYX                             1 Trial: 1        8 ___                  0
## 5 01LYX                             1 Trial: 1        9 all                  0
## 6 01LYX                             1 Trial: 1       10 the                  0
## # ℹ 177 more variables: IA_FIRST_RUN_DWELL_TIME <chr>,
## #   IA_SECOND_RUN_DWELL_TIME <chr>, `IA_DWELL_TIME_%` <chr>,
## #   IA_FIRST_FIXATION_DURATION <chr>, IA_FIRST_FIXATION_INDEX <chr>,
## #   IA_FIRST_FIXATION_X <chr>, IA_FIRST_FIXATION_Y <chr>,
## #   IA_FIRST_SACCADE_AMPLITUDE <chr>, IA_FIRST_SACCADE_ANGLE <chr>,
## #   IA_FIRST_SACCADE_INDEX <chr>, `IA_FIXATION_%` <chr>,
## #   IA_FIXATION_COUNT <dbl>, IP_INDEX <dbl>, IP_LABEL <chr>, ACC <dbl>, …
#Select variables
glimpse(stimIA_data)
## Rows: 12,183
## Columns: 183
## $ RECORDING_SESSION_LABEL               <chr> "01LYX", "01LYX", "01LYX", "01LY…
## $ TRIAL_INDEX                           <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
## $ TRIAL_LABEL                           <chr> "Trial: 1", "Trial: 1", "Trial: …
## $ IA_ID                                 <dbl> 5, 6, 7, 8, 9, 10, 11, 41, 42, 4…
## $ IA_LABEL                              <chr> "Her", "collar", "is", "___", "a…
## $ IA_DWELL_TIME                         <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ IA_FIRST_RUN_DWELL_TIME               <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_SECOND_RUN_DWELL_TIME              <chr> ".", ".", ".", ".", ".", ".", ".…
## $ `IA_DWELL_TIME_%`                     <chr> "0.0000", "0.0000", "0.0000", "0…
## $ IA_FIRST_FIXATION_DURATION            <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_FIRST_FIXATION_INDEX               <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_FIRST_FIXATION_X                   <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_FIRST_FIXATION_Y                   <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_FIRST_SACCADE_AMPLITUDE            <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_FIRST_SACCADE_ANGLE                <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_FIRST_SACCADE_INDEX                <chr> ".", ".", ".", ".", ".", ".", ".…
## $ `IA_FIXATION_%`                       <chr> "0.0000", "0.0000", "0.0000", "0…
## $ IA_FIXATION_COUNT                     <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ IP_INDEX                              <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
## $ IP_LABEL                              <chr> "Stimuli", "Stimuli", "Stimuli",…
## $ ACC                                   <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ ChoiceMade                            <chr> "B", "B", "B", "B", "B", "B", "B…
## $ PositionList                          <chr> "[(146, 437), (528, 437), (146, …
## $ RT                                    <dbl> 6146.020, 6146.020, 6146.020, 61…
## $ conditionid                           <dbl> 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,…
## $ cnPassedLength                        <dbl> 316, 316, 316, 316, 316, 316, 31…
## $ currentItemIndex                      <dbl> 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,…
## $ enPassedLength                        <dbl> 372, 372, 372, 372, 372, 372, 37…
## $ enlist                                <chr> "[Her collar, is neat, all the t…
## $ groupid                               <chr> "A", "A", "A", "A", "A", "A", "A…
## $ type                                  <chr> "p", "p", "p", "p", "p", "p", "p…
## $ IA_FIRST_SACCADE_END_TIME             <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_FIRST_SACCADE_START_TIME           <chr> ".", ".", ".", ".", ".", ".", ".…
## $ DATA_FILE                             <chr> "01LYX.edf", "01LYX.edf", "01LYX…
## $ EYE_USED                              <chr> "LEFT", "LEFT", "LEFT", "LEFT", …
## $ GROUPING_VARIABLES                    <chr> "trialid", "trialid", "trialid",…
## $ IA_AREA                               <dbl> 4300, 5600, 2400, 3200, 3200, 32…
## $ IA_AVERAGE_FIX_PUPIL_SIZE             <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_BOTTOM                             <dbl> 225, 225, 225, 225, 225, 225, 22…
## $ IA_DYNAMIC                            <lgl> FALSE, FALSE, FALSE, FALSE, FALS…
## $ IA_END_TIME                           <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_FIRST_FIXATION_PREVIOUS_FIX_IA     <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_FIRST_FIXATION_PREVIOUS_IAREAS     <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_FIRST_FIXATION_RUN_INDEX           <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_FIRST_FIXATION_TIME                <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_FIRST_FIXATION_VISITED_IA_COUNT    <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_FIRST_FIX_PROGRESSIVE              <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_FIRST_RUN_END_TIME                 <chr> ".", ".", ".", ".", ".", ".", ".…
## $ `IA_FIRST_RUN_FIXATION_%`             <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_FIRST_RUN_FIXATION_COUNT           <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_FIRST_RUN_LANDING_POSITION         <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_FIRST_RUN_LAUNCH_SITE              <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_FIRST_RUN_START_TIME               <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_FSA_COUNT_5                        <chr> "0", "0", "0", "0", "0", "0", "0…
## $ IA_FSA_COUNT_6                        <chr> "0", "0", "0", "0", "0", "0", "0…
## $ IA_FSA_COUNT_7                        <chr> "0", "0", "0", "0", "0", "0", "0…
## $ IA_FSA_COUNT_8                        <chr> "0", "0", "0", "0", "0", "0", "0…
## $ IA_FSA_COUNT_9                        <chr> "0", "0", "0", "0", "0", "0", "0…
## $ IA_FSA_COUNT_10                       <chr> "0", "0", "0", "0", "0", "0", "0…
## $ IA_FSA_COUNT_11                       <chr> "0", "0", "0", "0", "0", "0", "0…
## $ IA_FSA_COUNT_41                       <chr> "0", "0", "0", "0", "0", "0", "0…
## $ IA_FSA_COUNT_42                       <chr> "0", "0", "0", "0", "0", "0", "0…
## $ IA_FSA_COUNT_43                       <chr> "0", "0", "0", "0", "0", "0", "0…
## $ IA_FSA_COUNT_44                       <chr> "0", "0", "0", "0", "0", "0", "0…
## $ IA_FSA_COUNT_51                       <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ IA_FSA_COUNT_52                       <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ IA_FSA_COUNT_53                       <chr> "0", "0", "0", "0", "0", "0", "0…
## $ IA_FSA_COUNT_61                       <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_FSA_COUNT_62                       <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_FSA_COUNT_63                       <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_FSA_COUNT_54                       <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_FSA_COUNT_64                       <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_FSA_DURATION_5                     <chr> "0", "0", "0", "0", "0", "0", "0…
## $ IA_FSA_DURATION_6                     <chr> "0", "0", "0", "0", "0", "0", "0…
## $ IA_FSA_DURATION_7                     <chr> "0", "0", "0", "0", "0", "0", "0…
## $ IA_FSA_DURATION_8                     <chr> "0", "0", "0", "0", "0", "0", "0…
## $ IA_FSA_DURATION_9                     <chr> "0", "0", "0", "0", "0", "0", "0…
## $ IA_FSA_DURATION_10                    <chr> "0", "0", "0", "0", "0", "0", "0…
## $ IA_FSA_DURATION_11                    <chr> "0", "0", "0", "0", "0", "0", "0…
## $ IA_FSA_DURATION_41                    <chr> "0", "0", "0", "0", "0", "0", "0…
## $ IA_FSA_DURATION_42                    <chr> "0", "0", "0", "0", "0", "0", "0…
## $ IA_FSA_DURATION_43                    <chr> "0", "0", "0", "0", "0", "0", "0…
## $ IA_FSA_DURATION_44                    <chr> "0", "0", "0", "0", "0", "0", "0…
## $ IA_FSA_DURATION_51                    <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ IA_FSA_DURATION_52                    <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ IA_FSA_DURATION_53                    <chr> "0", "0", "0", "0", "0", "0", "0…
## $ IA_FSA_DURATION_61                    <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_FSA_DURATION_62                    <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_FSA_DURATION_63                    <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_FSA_DURATION_54                    <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_FSA_DURATION_64                    <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_GROUP                              <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_INSTANCES_COUNT                    <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_LAST_FIXATION_DURATION             <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_LAST_FIXATION_RUN                  <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_LAST_FIXATION_TIME                 <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_LAST_FIXATION_X                    <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_LAST_FIXATION_Y                    <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_LAST_RUN_DWELL_TIME                <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_LAST_RUN_END_TIME                  <chr> ".", ".", ".", ".", ".", ".", ".…
## $ `IA_LAST_RUN_FIXATION_%`              <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_LAST_RUN_FIXATION_COUNT            <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_LAST_RUN_LANDING_POSITION          <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_LAST_RUN_LAUNCH_SITE               <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_LAST_RUN_START_TIME                <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_LAST_SACCADE_AMPLITUDE             <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_LAST_SACCADE_ANGLE                 <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_LAST_SACCADE_END_TIME              <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_LAST_SACCADE_INDEX                 <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_LAST_SACCADE_START_TIME            <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_LEFT                               <dbl> 70, 156, 268, 316, 380, 444, 508…
## $ IA_LEGAL                              <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ IA_LEGAL_IMMEDIATE                    <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ IA_MAX_FIX_PUPIL_SIZE                 <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_MIN_FIX_PUPIL_SIZE                 <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_POINTS                             <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_REGRESSION_IN                      <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_REGRESSION_IN_COUNT                <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_REGRESSION_OUT                     <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_REGRESSION_OUT_COUNT               <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_REGRESSION_OUT_FULL                <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_REGRESSION_OUT_FULL_COUNT          <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_REGRESSION_PATH_DURATION           <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_RIGHT                              <dbl> 156, 268, 316, 380, 444, 508, 62…
## $ IA_RUN_COUNT                          <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ IA_SECOND_FIXATION_DURATION           <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_SECOND_FIXATION_RUN                <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_SECOND_FIXATION_TIME               <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_SECOND_FIXATION_X                  <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_SECOND_FIXATION_Y                  <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_SECOND_RUN_END_TIME                <chr> ".", ".", ".", ".", ".", ".", ".…
## $ `IA_SECOND_RUN_FIXATION_%`            <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_SECOND_RUN_FIXATION_COUNT          <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_SECOND_RUN_LANDING_POSITION        <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_SECOND_RUN_LAUNCH_SITE             <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_SECOND_RUN_START_TIME              <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_SELECTIVE_REGRESSION_PATH_DURATION <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_SKIP                               <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
## $ IA_SPILLOVER                          <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_START_TIME                         <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_THIRD_FIXATION_DURATION            <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_THIRD_FIXATION_RUN                 <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_THIRD_FIXATION_TIME                <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_THIRD_FIXATION_X                   <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_THIRD_FIXATION_Y                   <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_THIRD_RUN_DWELL_TIME               <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_THIRD_RUN_END_TIME                 <chr> ".", ".", ".", ".", ".", ".", ".…
## $ `IA_THIRD_RUN_FIXATION_%`             <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_THIRD_RUN_FIXATION_COUNT           <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_THIRD_RUN_LANDING_POSITION         <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_THIRD_RUN_LAUNCH_SITE              <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_THIRD_RUN_START_TIME               <chr> ".", ".", ".", ".", ".", ".", ".…
## $ IA_TOP                                <dbl> 175, 175, 175, 175, 175, 175, 17…
## $ IA_TYPE                               <chr> "RECTANGLE", "RECTANGLE", "RECTA…
## $ INTEREST_AREA_FIXATION_SEQUENCE       <chr> "[0, 51, 0, 52, 0, 53]", "[0, 51…
## $ IP_END_EVENT_MATCHED                  <lgl> TRUE, TRUE, TRUE, TRUE, TRUE, TR…
## $ IP_END_TIME                           <dbl> 655766, 655766, 655766, 655766, …
## $ IP_START_EVENT_MATCHED                <lgl> TRUE, TRUE, TRUE, TRUE, TRUE, TR…
## $ IP_START_TIME                         <dbl> 652825, 652825, 652825, 652825, …
## $ REPORTING_METHOD                      <chr> "Fixations", "Fixations", "Fixat…
## $ TIME_SCALE                            <chr> "Trial Relative", "Trial Relativ…
## $ TRIAL_DWELL_TIME                      <dbl> 2615, 2615, 2615, 2615, 2615, 26…
## $ TRIAL_FIXATION_COUNT                  <dbl> 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,…
## $ TRIAL_IA_COUNT                        <dbl> 14, 14, 14, 14, 14, 14, 14, 14, …
## $ TRIAL_START_TIME                      <dbl> 652739, 652739, 652739, 652739, …
## $ TRIAL_TOTAL_VISITED_IA_COUNT          <dbl> 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,…
## $ RandomPostitonIndex                   <chr> "[3, 0, 2, 1]", "[3, 0, 2, 1]", …
## $ Session_Name_                         <chr> "01LYX", "01LYX", "01LYX", "01LY…
## $ Trial_Index_                          <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
## $ Trial_Recycled_                       <lgl> FALSE, FALSE, FALSE, FALSE, FALS…
## $ audiofile                             <chr> "p2.wav", "p2.wav", "p2.wav", "p…
## $ choicea                               <chr> "tidy", "tidy", "tidy", "tidy", …
## $ choiceb                               <chr> "clean", "clean", "clean", "clea…
## $ choicec                               <chr> "white", "white", "white", "whit…
## $ choiced                               <chr> "broken", "broken", "broken", "b…
## $ currentWait                           <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ discript                              <chr> "单语", "单语", "单语", "单语", …
## $ fontSize                              <dbl> 20, 20, 20, 20, 20, 20, 20, 20, …
## $ listLength                            <dbl> 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,…
## $ questionstring                        <chr> "Her collar is ___ all the time.…
## $ timelist                              <chr> "[1033, 882, 960]", "[1033, 882,…
## $ trialid                               <chr> "p2", "p2", "p2", "p2", "p2", "p…
## $ wordsPass                             <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
variables <-  c("RECORDING_SESSION_LABEL", "trialid","IA_ID",
                "IA_DWELL_TIME_%","IA_FIXATION_%","RT",
                "ACC","IA_DWELL_TIME","IA_FIRST_FIXATION_DURATION",
                "IA_FIRST_FIXATION_INDEX","currentItemIndex","discript",
                "conditionid","groupid")

stim4 <- stimIA_data %>% 
  select(any_of(variables) )
         
# change column names

df <- stim4 %>% rename(subj = "RECORDING_SESSION_LABEL", 
                       trial = "trialid", ia = "IA_ID",
                       dtrate = "IA_DWELL_TIME_%",
                       fixrate = "IA_FIXATION_%", rt = "RT",
                       acc = "ACC", dt = "IA_DWELL_TIME", 
                       ffd = "IA_FIRST_FIXATION_DURATION",
                       ff = "IA_FIRST_FIXATION_INDEX",
                       item = "currentItemIndex",
                       lang = "discript", cond = "conditionid",
                       gr = "groupid")

glimpse(df)
## Rows: 12,183
## Columns: 14
## $ subj    <chr> "01LYX", "01LYX", "01LYX", "01LYX", "01LYX", "01LYX", "01LYX",…
## $ trial   <chr> "p2", "p2", "p2", "p2", "p2", "p2", "p2", "p2", "p2", "p2", "p…
## $ ia      <dbl> 5, 6, 7, 8, 9, 10, 11, 41, 42, 43, 44, 51, 52, 53, 5, 6, 7, 8,…
## $ dtrate  <chr> "0.0000", "0.0000", "0.0000", "0.0000", "0.0000", "0.0000", "0…
## $ fixrate <chr> "0.0000", "0.0000", "0.0000", "0.0000", "0.0000", "0.0000", "0…
## $ rt      <dbl> 6146.020, 6146.020, 6146.020, 6146.020, 6146.020, 6146.020, 61…
## $ acc     <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ dt      <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 604, 256, 175, 0, 0, 0, 0, 0,…
## $ ffd     <chr> ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "338", …
## $ ff      <chr> ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "2", "5…
## $ item    <dbl> 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,…
## $ lang    <chr> "单语", "单语", "单语", "单语", "单语", "单语", "单语", "单语"…
## $ cond    <dbl> 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 4,…
## $ gr      <chr> "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A…
#cross tabulate
table(df$subj,df$lang)
##            
##             单语 双语
##   01LYX      137  256
##   02PQJ      250  143
##   03LSY      137  256
##   04CMY      250  143
##   05MXJ      137  256
##   06HC       250  143
##   07GXJ      137  256
##   08ZYQ      250  143
##   09MZW      137  256
##   10WLH      250  143
##   11LDP      137  256
##   12SCC      250  143
##   13WSR      137  256
##   15ZMZ      137  256
##   16QY       250  143
##   17DSL      137  256
##   18BXY      250  143
##   19WLL      137  256
##   20ZZY      250  143
##   21WYQ      137  256
##   22SYC      250  143
##   23SYH      137  256
##   24MBH      250  143
##   25HYX      137  256
##   26CJ       250  143
##   27YSH      137  256
##   28HYX      250  143
##   29HRE      137  256
##   30YAL      250  143
##   31SWY      137  256
##   ZWL 14.00  250  143
table(df$subj,df$cond)  
##            
##               1   2   3   4
##   01LYX      67  70 129 127
##   02PQJ     126 124  70  73
##   03LSY      70  67 127 129
##   04CMY     124 126  73  70
##   05MXJ      67  70 129 127
##   06HC      126 124  70  73
##   07GXJ      70  67 127 129
##   08ZYQ     124 126  73  70
##   09MZW      67  70 129 127
##   10WLH     126 124  70  73
##   11LDP      70  67 127 129
##   12SCC     124 126  73  70
##   13WSR      67  70 129 127
##   15ZMZ      70  67 127 129
##   16QY      124 126  73  70
##   17DSL      67  70 129 127
##   18BXY     126 124  70  73
##   19WLL      70  67 127 129
##   20ZZY     124 126  73  70
##   21WYQ      67  70 129 127
##   22SYC     126 124  70  73
##   23SYH      70  67 127 129
##   24MBH     124 126  73  70
##   25HYX      67  70 129 127
##   26CJ      126 124  70  73
##   27YSH      70  67 127 129
##   28HYX     124 126  73  70
##   29HRE      67  70 129 127
##   30YAL     126 124  70  73
##   31SWY      70  67 127 129
##   ZWL 14.00 126 124  70  73
table(df$ia,df$lang)
##     
##      单语 双语
##   5    62   62
##   6    62   62
##   7    62   62
##   8    62   62
##   9    62   62
##   10   62   62
##   11   62   62
##   41   62   62
##   42   62   62
##   43   62   62
##   44   62   62
##   51 1116 1116
##   52 1116 1116
##   53 1084 1086
##   54  279  279
##   61  510  606
##   62  510  606
##   63  510  606
##   64  135  144
table(df$ia,df$cond)
##     
##        1   2   3   4
##   5   31  31  31  31
##   6   31  31  31  31
##   7   31  31  31  31
##   8   31  31  31  31
##   9   31  31  31  31
##   10  31  31  31  31
##   11  31  31  31  31
##   41  31  31  31  31
##   42  31  31  31  31
##   43  31  31  31  31
##   44  31  31  31  31
##   51 558 558 558 558
##   52 558 558 558 558
##   53 542 542 542 544
##   54 140 139 139 140
##   61 255 255 303 303
##   62 255 255 303 303
##   63 255 255 303 303
##   64  68  67  72  72
#EDA

library(skimr)
summary(df)
##      subj              trial                 ia           dtrate         
##  Length:12183       Length:12183       Min.   : 5.00   Length:12183      
##  Class :character   Class :character   1st Qu.:51.00   Class :character  
##  Mode  :character   Mode  :character   Median :53.00   Mode  :character  
##                                        Mean   :51.59                     
##                                        3rd Qu.:61.00                     
##                                        Max.   :64.00                     
##    fixrate                rt             acc               dt        
##  Length:12183       Min.   : 1082   Min.   :0.0000   Min.   :   0.0  
##  Class :character   1st Qu.: 2863   1st Qu.:1.0000   1st Qu.:   0.0  
##  Mode  :character   Median : 3884   Median :1.0000   Median : 396.0  
##                     Mean   : 4568   Mean   :0.8749   Mean   : 479.6  
##                     3rd Qu.: 5461   3rd Qu.:1.0000   3rd Qu.: 801.0  
##                     Max.   :23218   Max.   :1.0000   Max.   :2723.0  
##      ffd                 ff                 item           lang          
##  Length:12183       Length:12183       Min.   :1.000   Length:12183      
##  Class :character   Class :character   1st Qu.:2.000   Class :character  
##  Mode  :character   Mode  :character   Median :2.000   Mode  :character  
##                                        Mean   :2.265                     
##                                        3rd Qu.:3.000                     
##                                        Max.   :3.000                     
##       cond            gr           
##  Min.   :1.000   Length:12183      
##  1st Qu.:2.000   Class :character  
##  Median :3.000   Mode  :character  
##  Mean   :2.525                     
##  3rd Qu.:4.000                     
##  Max.   :4.000
skim(df)
Data summary
Name df
Number of rows 12183
Number of columns 14
_______________________
Column type frequency:
character 8
numeric 6
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
subj 0 1 4 9 0 31 0
trial 0 1 1 2 0 72 0
dtrate 0 1 1 6 0 3873 0
fixrate 0 1 1 6 0 95 0
ffd 0 1 1 4 0 527 0
ff 0 1 1 2 0 22 0
lang 0 1 2 2 0 2 0
gr 0 1 1 1 0 4 0

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
ia 0 1 51.59 13.16 5.00 51.00 53.00 61.00 64.0 ▁▁▁▆▇
rt 0 1 4567.98 2546.85 1081.93 2862.82 3884.38 5460.82 23217.7 ▇▂▁▁▁
acc 0 1 0.87 0.33 0.00 1.00 1.00 1.00 1.0 ▁▁▁▁▇
dt 0 1 479.60 483.74 0.00 0.00 396.00 801.00 2723.0 ▇▃▂▁▁
item 0 1 2.26 0.46 1.00 2.00 2.00 3.00 3.0 ▁▁▇▁▃
cond 0 1 2.52 1.12 1.00 2.00 3.00 4.00 4.0 ▇▇▁▇▇
df %>% skim(dt)
Data summary
Name Piped data
Number of rows 12183
Number of columns 14
_______________________
Column type frequency:
numeric 1
________________________
Group variables None

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
dt 0 1 479.6 483.74 0 0 396 801 2723 ▇▃▂▁▁
stim4%>%
  skim() %>%
  dplyr::filter(n_missing > 0)
## # A tibble: 0 × 17
## # ℹ 17 variables: skim_type <chr>, skim_variable <chr>, n_missing <int>,
## #   complete_rate <dbl>, character.min <int>, character.max <int>,
## #   character.empty <int>, character.n_unique <int>,
## #   character.whitespace <int>, numeric.mean <dbl>, numeric.sd <dbl>,
## #   numeric.p0 <dbl>, numeric.p25 <dbl>, numeric.p50 <dbl>, numeric.p75 <dbl>,
## #   numeric.p100 <dbl>, numeric.hist <chr>
library(DataExplorer)
library(ggplot2)
create_report(stim4)
## 
## 
## processing file: report.rmd
## 
  |                                           
  |                                     |   0%
  |                                           
  |.                                    |   2%                                 
  |                                           
  |..                                   |   5% [global_options]                
  |                                           
  |...                                  |   7%                                 
  |                                           
  |....                                 |  10% [introduce]                     
  |                                           
  |....                                 |  12%                                 
  |                                           
  |.....                                |  14% [plot_intro]                    
  |                                           
  |......                               |  17%                                 
  |                                           
  |.......                              |  19% [data_structure]                
  |                                           
  |........                             |  21%                                 
  |                                           
  |.........                            |  24% [missing_profile]               
  |                                           
  |..........                           |  26%                                 
  |                                           
  |...........                          |  29% [univariate_distribution_header]
  |                                           
  |...........                          |  31%                                 
  |                                           
  |............                         |  33% [plot_histogram]                
  |                                           
  |.............                        |  36%                                 
  |                                           
  |..............                       |  38% [plot_density]                  
  |                                           
  |...............                      |  40%                                 
  |                                           
  |................                     |  43% [plot_frequency_bar]            
  |                                           
  |.................                    |  45%                                 
  |                                           
  |..................                   |  48% [plot_response_bar]             
  |                                           
  |..................                   |  50%                                 
  |                                           
  |...................                  |  52% [plot_with_bar]                 
  |                                           
  |....................                 |  55%                                 
  |                                           
  |.....................                |  57% [plot_normal_qq]                
  |                                           
  |......................               |  60%                                 
  |                                           
  |.......................              |  62% [plot_response_qq]              
  |                                           
  |........................             |  64%                                 
  |                                           
  |.........................            |  67% [plot_by_qq]                    
  |                                           
  |..........................           |  69%                                 
  |                                           
  |..........................           |  71% [correlation_analysis]          
  |                                           
  |...........................          |  74%                                 
  |                                           
  |............................         |  76% [principal_component_analysis]  
  |                                           
  |.............................        |  79%                                 
  |                                           
  |..............................       |  81% [bivariate_distribution_header] 
  |                                           
  |...............................      |  83%                                 
  |                                           
  |................................     |  86% [plot_response_boxplot]         
  |                                           
  |.................................    |  88%                                 
  |                                           
  |.................................    |  90% [plot_by_boxplot]               
  |                                           
  |..................................   |  93%                                 
  |                                           
  |...................................  |  95% [plot_response_scatterplot]     
  |                                           
  |.................................... |  98%                                 
  |                                           
  |.....................................| 100% [plot_by_scatterplot]           
## output file: /Users/maggie/Downloads/bookR/report.knit.md
## /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/pandoc +RTS -K512m -RTS /Users/maggie/Downloads/bookR/report.knit.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output /Users/maggie/Downloads/bookR/report.html --lua-filter /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/rmarkdown/rmarkdown/lua/latex-div.lua --embed-resources --standalone --variable bs3=TRUE --section-divs --table-of-contents --toc-depth 6 --template /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/rmarkdown/rmd/h/default.html --no-highlight --variable highlightjs=1 --variable theme=yeti --mathjax --variable 'mathjax-url=https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' --include-in-header /var/folders/b2/49rr6ps17r128kg5_hklt5br0000gn/T//Rtmp2NIiT9/rmarkdown-str221c7830fe27.html
## 
## Output created: report.html
# delete outliers by subj
df1 <- df %>% 
  group_by(subj) %>% 
  filter(dt>150&abs(scale(dt))<=3)
## Warning: Using one column matrices in `filter()` was deprecated in dplyr 1.1.0.
## ℹ Please use one dimensional logical vectors instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
df1 %>% 
  group_by(ia,lang) %>% 
  summarise(mdt=mean(dt),
            dt_SD=sd(dt))
## `summarise()` has grouped output by 'ia'. You can override using the `.groups`
## argument.
## # A tibble: 29 × 4
## # Groups:   ia [19]
##       ia lang    mdt dt_SD
##    <dbl> <chr> <dbl> <dbl>
##  1     5 双语   200   NA  
##  2     6 单语   397. 198. 
##  3     6 双语   368. 156. 
##  4     7 单语   356. 223. 
##  5     7 双语   252.  62.0
##  6     8 单语   426   18.3
##  7     8 双语   774  264. 
##  8     9 单语   611  251. 
##  9     9 双语   526  547. 
## 10    10 单语   191   55.2
## # ℹ 19 more rows
# do we need to log transform?
qqnorm(df1$dt) 

qqnorm(log(df1$dt))

# no need to log
# if yes 
df1$dt = log(df1$dt)

#geom_boxplot
ggplot(df1,aes(ia,dt,fill=lang))+
  geom_boxplot(notch = TRUE)+
  facet_wrap(~lang)

#mixed model
library(lme4)
summary(mix.m0 <- lmer(dt~ia*lang*cond+
                         (1+lang*cond|subj)+
                         (ia|gr),
                       data=df1),cor=F)
## boundary (singular) fit: see help('isSingular')
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: dt ~ ia * lang * cond + (1 + lang * cond | subj) + (ia | gr)
##    Data: df1
## 
## REML criterion at convergence: 11485.5
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -5.8193 -0.6799  0.0619  0.7386  2.5698 
## 
## Random effects:
##  Groups   Name          Variance  Std.Dev. Corr             
##  subj     (Intercept)   0.0228225 0.15107                   
##           lang双语      0.1013764 0.31840  -0.23            
##           cond          0.0013640 0.03693  -0.66 -0.32      
##           lang双语:cond 0.0015374 0.03921   0.61 -0.90  0.03
##  gr       (Intercept)   0.3279733 0.57269                   
##           ia            0.0001204 0.01097  -1.00            
##  Residual               0.2544902 0.50447                   
## Number of obs: 7666, groups:  subj, 31; gr, 4
## 
## Fixed effects:
##                    Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)       5.340e+00  6.023e-01  5.897e+01   8.866 1.92e-12 ***
## ia                2.537e-02  1.155e-02  5.983e+01   2.196  0.03196 *  
## lang双语          2.001e+00  7.362e-01  6.307e+03   2.718  0.00659 ** 
## cond              6.339e-01  4.671e-01  7.574e+03   1.357  0.17483    
## ia:lang双语      -4.478e-02  1.386e-02  6.559e+03  -3.232  0.00124 ** 
## ia:cond          -1.229e-02  8.962e-03  7.577e+03  -1.371  0.17032    
## lang双语:cond    -5.728e-01  4.886e-01  7.600e+03  -1.172  0.24108    
## ia:lang双语:cond  1.128e-02  9.346e-03  7.598e+03   1.207  0.22745    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
summary(mix.m1 <- lmer(dt~ia*lang*cond+
                         (1+lang+cond|subj)+
                         (ia|gr),
                       data=df1),cor=F)
## boundary (singular) fit: see help('isSingular')
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: dt ~ ia * lang * cond + (1 + lang + cond | subj) + (ia | gr)
##    Data: df1
## 
## REML criterion at convergence: 11488.1
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -5.8218 -0.6803  0.0614  0.7382  2.5490 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev. Corr       
##  subj     (Intercept) 0.0176521 0.13286             
##           lang双语    0.0596471 0.24423   0.14      
##           cond        0.0020657 0.04545  -0.41 -0.78
##  gr       (Intercept) 0.6117129 0.78212             
##           ia          0.0002244 0.01498  -1.00      
##  Residual             0.2544881 0.50447             
## Number of obs: 7666, groups:  subj, 31; gr, 4
## 
## Fixed effects:
##                    Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)       5.330e+00  6.590e-01  9.957e+00   8.087  1.1e-05 ***
## ia                2.559e-02  1.264e-02  1.010e+01   2.025 0.070058 .  
## lang双语          2.077e+00  7.346e-01  7.162e+03   2.828 0.004696 ** 
## cond              6.398e-01  4.673e-01  7.602e+03   1.369 0.171016    
## ia:lang双语      -4.640e-02  1.384e-02  7.124e+03  -3.352 0.000806 ***
## ia:cond          -1.242e-02  8.966e-03  7.599e+03  -1.385 0.166110    
## lang双语:cond    -5.995e-01  4.885e-01  7.603e+03  -1.227 0.219762    
## ia:lang双语:cond  1.185e-02  9.346e-03  7.601e+03   1.267 0.205022    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
#mix.m1和0无显著差别,继续简化
summary(mix.m2 <- lmer(dt~ia*lang*cond+
                         (1+lang|subj)+
                         (ia|gr),
                       data=df1),cor=F)
## boundary (singular) fit: see help('isSingular')
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: dt ~ ia * lang * cond + (1 + lang | subj) + (ia | gr)
##    Data: df1
## 
## REML criterion at convergence: 11492.9
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -5.7443 -0.6880  0.0549  0.7416  2.5719 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev. Corr 
##  subj     (Intercept) 1.761e-02 0.132689      
##           lang双语    3.643e-02 0.190869 -0.41
##  gr       (Intercept) 2.220e-01 0.471155      
##           ia          8.502e-05 0.009221 -1.00
##  Residual             2.549e-01 0.504879      
## Number of obs: 7666, groups:  subj, 31; gr, 4
## 
## Fixed effects:
##                    Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)       5.314e+00  5.793e-01  1.491e+02   9.174 3.47e-16 ***
## ia                2.590e-02  1.115e-02  1.435e+02   2.323 0.021575 *  
## lang双语          2.288e+00  7.318e-01  7.627e+03   3.126 0.001780 ** 
## cond              6.630e-01  4.673e-01  7.604e+03   1.419 0.155997    
## ia:lang双语      -5.064e-02  1.380e-02  7.605e+03  -3.671 0.000244 ***
## ia:cond          -1.287e-02  8.966e-03  7.604e+03  -1.435 0.151272    
## lang双语:cond    -6.742e-01  4.885e-01  7.606e+03  -1.380 0.167527    
## ia:lang双语:cond  1.334e-02  9.344e-03  7.606e+03   1.427 0.153481    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
anova(mix.m1,mix.m2)
## refitting model(s) with ML (instead of REML)
## Warning in optwrap(optimizer, devfun, x@theta, lower = x@lower, calc.derivs =
## TRUE, : convergence code 1 from bobyqa: bobyqa -- maximum number of function
## evaluations exceeded
## Data: df1
## Models:
## mix.m2: dt ~ ia * lang * cond + (1 + lang | subj) + (ia | gr)
## mix.m1: dt ~ ia * lang * cond + (1 + lang + cond | subj) + (ia | gr)
##        npar   AIC   BIC  logLik deviance  Chisq Df Pr(>Chisq)
## mix.m2   15 11463 11567 -5716.4    11433                     
## mix.m1   18 11465 11590 -5714.3    11429 4.1491  3     0.2458
#mix.m1和2无显著差别,仍然存在singular,继续简化
summary(mix.m3 <- lmer(dt~ia*lang*cond+
                         (1+lang|subj)+
                         (ia|gr),
                       data=df1),cor=F)
## boundary (singular) fit: see help('isSingular')
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: dt ~ ia * lang * cond + (1 + lang | subj) + (ia | gr)
##    Data: df1
## 
## REML criterion at convergence: 11492.9
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -5.7443 -0.6880  0.0549  0.7416  2.5719 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev. Corr 
##  subj     (Intercept) 1.761e-02 0.132689      
##           lang双语    3.643e-02 0.190869 -0.41
##  gr       (Intercept) 2.220e-01 0.471155      
##           ia          8.502e-05 0.009221 -1.00
##  Residual             2.549e-01 0.504879      
## Number of obs: 7666, groups:  subj, 31; gr, 4
## 
## Fixed effects:
##                    Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)       5.314e+00  5.793e-01  1.491e+02   9.174 3.47e-16 ***
## ia                2.590e-02  1.115e-02  1.435e+02   2.323 0.021575 *  
## lang双语          2.288e+00  7.318e-01  7.627e+03   3.126 0.001780 ** 
## cond              6.630e-01  4.673e-01  7.604e+03   1.419 0.155997    
## ia:lang双语      -5.064e-02  1.380e-02  7.605e+03  -3.671 0.000244 ***
## ia:cond          -1.287e-02  8.966e-03  7.604e+03  -1.435 0.151272    
## lang双语:cond    -6.742e-01  4.885e-01  7.606e+03  -1.380 0.167527    
## ia:lang双语:cond  1.334e-02  9.344e-03  7.606e+03   1.427 0.153481    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
summary(mix.m4 <- lmer(dt~ia*lang*cond+
                         (1|subj)+
                         (1|gr),
                       data=df1),cor=F)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: dt ~ ia * lang * cond + (1 | subj) + (1 | gr)
##    Data: df1
## 
## REML criterion at convergence: 11730.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -5.3664 -0.6752  0.0611  0.7332  2.5817 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subj     (Intercept) 0.014797 0.12164 
##  gr       (Intercept) 0.002111 0.04594 
##  Residual             0.265487 0.51525 
## Number of obs: 7666, groups:  subj, 31; gr, 4
## 
## Fixed effects:
##                    Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)       5.197e+00  5.306e-01  7.422e+03   9.795  < 2e-16 ***
## ia                2.817e-02  1.017e-02  7.631e+03   2.769  0.00564 ** 
## lang双语          2.904e+00  7.412e-01  7.631e+03   3.918 9.00e-05 ***
## cond              7.485e-01  4.749e-01  7.630e+03   1.576  0.11504    
## ia:lang双语      -6.281e-02  1.398e-02  7.631e+03  -4.491 7.18e-06 ***
## ia:cond          -1.452e-02  9.112e-03  7.630e+03  -1.593  0.11120    
## lang双语:cond    -7.945e-01  4.971e-01  7.630e+03  -1.598  0.11006    
## ia:lang双语:cond  1.566e-02  9.510e-03  7.630e+03   1.647  0.09963 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(mix.m5 <- lmer(dt~ia*lang+cond+
                         (1|subj)+
                         (1|gr),
                       data=df1),cor=F)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: dt ~ ia * lang + cond + (1 | subj) + (1 | gr)
##    Data: df1
## 
## REML criterion at convergence: 11710.9
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -5.3229 -0.6769  0.0590  0.7305  2.5891 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subj     (Intercept) 0.014745 0.12143 
##  gr       (Intercept) 0.002108 0.04591 
##  Residual             0.265513 0.51528 
## Number of obs: 7666, groups:  subj, 31; gr, 4
## 
## Fixed effects:
##               Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)  6.001e+00  1.343e-01  7.998e+02  44.680  < 2e-16 ***
## ia           1.234e-02  2.502e-03  7.642e+03   4.933 8.29e-07 ***
## lang双语     1.921e+00  1.524e-01  7.638e+03  12.600  < 2e-16 ***
## cond         5.229e-03  1.178e-02  7.631e+03   0.444    0.657    
## ia:lang双语 -4.299e-02  2.855e-03  7.639e+03 -15.056  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#M4 没有报错,但和M3有显著差异

anova(mix.m4,mix.m5)
## refitting model(s) with ML (instead of REML)
## Data: df1
## Models:
## mix.m5: dt ~ ia * lang + cond + (1 | subj) + (1 | gr)
## mix.m4: dt ~ ia * lang * cond + (1 | subj) + (1 | gr)
##        npar   AIC   BIC  logLik deviance  Chisq Df Pr(>Chisq)
## mix.m5    8 11686 11742 -5835.1    11670                     
## mix.m4   11 11688 11765 -5833.3    11666 3.6611  3     0.3005
# m4和m5没有显著差异

#model diagnosis
qqnorm(residuals(mix.m4))
qqline(residuals(mix.m4))

qqnorm(residuals(mix.m5))
qqline(residuals(mix.m5))

hist(residuals(mix.m4))

hist(residuals(mix.m5))

#fixed and interaction effect obtained
afex::mixed(mix.m5 <- lmer(dt~ia*lang+cond+
                             (1|subj) + (1|gr),
                             data=df1),
                             REML=FALSE,
                             method="LRT",
                            data=df1)
## Contrasts set to contr.sum for the following variables: lang, subj, gr
## Formula (the first argument) converted to formula.
## Numerical variables NOT centered on 0: ia, cond
## If in interactions, interpretation of lower order (e.g., main) effects difficult.
## Mixed Model Anova Table (Type 3 tests, LRT-method)
## 
## Model: dt ~ ia * lang + cond + (1 | subj) + (1 | gr)
## Data: df1
## Df full model: 8
##    Effect df      Chisq p.value
## 1      ia  1  40.54 ***   <.001
## 2    lang  1 157.39 ***   <.001
## 3    cond  1       0.20    .657
## 4 ia:lang  1 223.69 ***   <.001
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '+' 0.1 ' ' 1
emmeans::emmeans(mix.m5,specs = pairwise~ia*lang)
## Note: D.f. calculations have been disabled because the number of observations exceeds 3000.
## To enable adjustments, add the argument 'pbkrtest.limit = 7666' (or larger)
## [or, globally, 'set emm_options(pbkrtest.limit = 7666)' or larger];
## but be warned that this may result in large computation time and memory use.
## Note: D.f. calculations have been disabled because the number of observations exceeds 3000.
## To enable adjustments, add the argument 'lmerTest.limit = 7666' (or larger)
## [or, globally, 'set emm_options(lmerTest.limit = 7666)' or larger];
## but be warned that this may result in large computation time and memory use.
## $emmeans
##    ia lang emmean     SE  df asymp.LCL asymp.UCL
##  52.9 单语   6.67 0.0354 Inf      6.60      6.74
##  52.9 双语   6.31 0.0344 Inf      6.25      6.38
## 
## Degrees-of-freedom method: asymptotic 
## Confidence level used: 0.95 
## 
## $contrasts
##      contrast                                    estimate     SE  df z.ratio
##  ia52.888859900861 单语 - ia52.888859900861 双语    0.353 0.0265 Inf  13.318
##  p.value
##   <.0001
## 
## Degrees-of-freedom method: asymptotic
#load se and lp data ?

se_data <- read_csv("SE data.csv")
## Rows: 31 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): subj
## dbl (2): lp, se
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# join two data frames by ID (subject ID variable)
sedf <- inner_join (df, se_data, by = "subj")
glimpse(sedf)
## Rows: 11,790
## Columns: 16
## $ subj    <chr> "01LYX", "01LYX", "01LYX", "01LYX", "01LYX", "01LYX", "01LYX",…
## $ trial   <chr> "p2", "p2", "p2", "p2", "p2", "p2", "p2", "p2", "p2", "p2", "p…
## $ ia      <dbl> 5, 6, 7, 8, 9, 10, 11, 41, 42, 43, 44, 51, 52, 53, 5, 6, 7, 8,…
## $ dtrate  <chr> "0.0000", "0.0000", "0.0000", "0.0000", "0.0000", "0.0000", "0…
## $ fixrate <chr> "0.0000", "0.0000", "0.0000", "0.0000", "0.0000", "0.0000", "0…
## $ rt      <dbl> 6146.020, 6146.020, 6146.020, 6146.020, 6146.020, 6146.020, 61…
## $ acc     <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ dt      <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 604, 256, 175, 0, 0, 0, 0, 0,…
## $ ffd     <chr> ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "338", …
## $ ff      <chr> ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "2", "5…
## $ item    <dbl> 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,…
## $ lang    <chr> "单语", "单语", "单语", "单语", "单语", "单语", "单语", "单语"…
## $ cond    <dbl> 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 4,…
## $ gr      <chr> "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A…
## $ lp      <dbl> 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30…
## $ se      <dbl> 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,…
### Fit a mixed-effects model
summary(mix.m6 <- lmer(dt~lp*ia*lang+
                         (1|subj)+
                         (1|gr),
                       data=sedf),cor=F)
## boundary (singular) fit: see help('isSingular')
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: dt ~ lp * ia * lang + (1 | subj) + (1 | gr)
##    Data: sedf
## 
## REML criterion at convergence: 178890.1
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.4212 -0.8936 -0.1519  0.6537  4.8322 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subj     (Intercept)   4930    70.21  
##  gr       (Intercept)      0     0.00  
##  Residual             226671   476.10  
## Number of obs: 11790, groups:  subj, 30; gr, 4
## 
## Fixed effects:
##                  Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)      -40.6125   167.7670   557.1284  -0.242 0.808810    
## lp                12.4578     4.7484   553.0652   2.624 0.008941 ** 
## ia                13.3773     2.9417 11770.2281   4.547 5.48e-06 ***
## lang双语         383.5383   208.7169 11781.9589   1.838 0.066146 .  
## lp:ia             -0.3061     0.0830 11770.6987  -3.688 0.000227 ***
## lp:lang双语      -12.8527     5.9170 11781.9051  -2.172 0.029862 *  
## ia:lang双语      -14.2484     3.9953 11733.3344  -3.566 0.000364 ***
## lp:ia:lang双语     0.3916     0.1132 11729.8536   3.459 0.000544 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
#model diagnosis
qqnorm(residuals(mix.m6))
qqline(residuals(mix.m6))

hist(residuals(mix.m6))

#fixed and interaction effect obtained
afex::mixed(mix.m6 <- lmer(dt~lp*ia*lang+
                             (1|subj)+
                             (1|gr),
                           data=sedf),
            REML=FALSE,
            method="LRT",
            data=sedf)
## boundary (singular) fit: see help('isSingular')
## Contrasts set to contr.sum for the following variables: lang, subj, gr
## Formula (the first argument) converted to formula.
## Numerical variables NOT centered on 0: lp, ia
## If in interactions, interpretation of lower order (e.g., main) effects difficult.
## Warning: Some predictor variables are on very different scales: consider
## rescaling
## boundary (singular) fit: see help('isSingular')
## Warning: Some predictor variables are on very different scales: consider
## rescaling
## Warning: Some predictor variables are on very different scales: consider
## rescaling
## boundary (singular) fit: see help('isSingular')
## Warning: Some predictor variables are on very different scales: consider
## rescaling

## Warning: Some predictor variables are on very different scales: consider
## rescaling
## boundary (singular) fit: see help('isSingular')
## Warning: Some predictor variables are on very different scales: consider
## rescaling

## Warning: Some predictor variables are on very different scales: consider
## rescaling
## boundary (singular) fit: see help('isSingular')
## Warning: Some predictor variables are on very different scales: consider
## rescaling

## Warning: Some predictor variables are on very different scales: consider
## rescaling
## boundary (singular) fit: see help('isSingular')
## Warning: Some predictor variables are on very different scales: consider
## rescaling

## Warning: Some predictor variables are on very different scales: consider
## rescaling
## boundary (singular) fit: see help('isSingular')
## Warning: Some predictor variables are on very different scales: consider
## rescaling

## Warning: Some predictor variables are on very different scales: consider
## rescaling
## boundary (singular) fit: see help('isSingular')
## Warning: Some predictor variables are on very different scales: consider
## rescaling
## boundary (singular) fit: see help('isSingular')
## Warning: lme4 reported (at least) the following warnings for 'full':
##   * boundary (singular) fit: see help('isSingular')
## Warning: lme4 reported (at least) the following warnings for 'lp':
##   * boundary (singular) fit: see help('isSingular')
## Warning: lme4 reported (at least) the following warnings for 'ia':
##   * boundary (singular) fit: see help('isSingular')
## Warning: lme4 reported (at least) the following warnings for 'lang':
##   * boundary (singular) fit: see help('isSingular')
## Warning: lme4 reported (at least) the following warnings for 'lp:ia':
##   * boundary (singular) fit: see help('isSingular')
## Warning: lme4 reported (at least) the following warnings for 'lp:lang':
##   * boundary (singular) fit: see help('isSingular')
## Warning: lme4 reported (at least) the following warnings for 'ia:lang':
##   * boundary (singular) fit: see help('isSingular')
## Warning: lme4 reported (at least) the following warnings for 'lp:ia:lang':
##   * boundary (singular) fit: see help('isSingular')
## Mixed Model Anova Table (Type 3 tests, LRT-method)
## 
## Model: dt ~ lp * ia * lang + (1 | subj) + (1 | gr)
## Data: sedf
## Df full model: 11
##       Effect df     Chisq p.value
## 1         lp  1    2.85 +    .092
## 2         ia  1  10.20 **    .001
## 3       lang  1    3.37 +    .066
## 4      lp:ia  1    3.96 *    .047
## 5    lp:lang  1    4.72 *    .030
## 6    ia:lang  1 12.71 ***   <.001
## 7 lp:ia:lang  1 11.97 ***   <.001
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '+' 0.1 ' ' 1
# Fit the mixed-effects model with rescaled predictors
mix.m7 <- mixed(lmer(dt ~ lp * ia * lang + (1 | subj) + (1 | gr), data = sedf),
                REML = FALSE,
                method = "LRT",
                data = sedf)
## boundary (singular) fit: see help('isSingular')
## Contrasts set to contr.sum for the following variables: lang, subj, gr
## Formula (the first argument) converted to formula.
## Numerical variables NOT centered on 0: lp, ia
## If in interactions, interpretation of lower order (e.g., main) effects difficult.
## Warning: Some predictor variables are on very different scales: consider
## rescaling
## boundary (singular) fit: see help('isSingular')
## Warning: Some predictor variables are on very different scales: consider
## rescaling
## Warning: Some predictor variables are on very different scales: consider
## rescaling
## boundary (singular) fit: see help('isSingular')
## Warning: Some predictor variables are on very different scales: consider
## rescaling

## Warning: Some predictor variables are on very different scales: consider
## rescaling
## boundary (singular) fit: see help('isSingular')
## Warning: Some predictor variables are on very different scales: consider
## rescaling

## Warning: Some predictor variables are on very different scales: consider
## rescaling
## boundary (singular) fit: see help('isSingular')
## Warning: Some predictor variables are on very different scales: consider
## rescaling

## Warning: Some predictor variables are on very different scales: consider
## rescaling
## boundary (singular) fit: see help('isSingular')
## Warning: Some predictor variables are on very different scales: consider
## rescaling

## Warning: Some predictor variables are on very different scales: consider
## rescaling
## boundary (singular) fit: see help('isSingular')
## Warning: Some predictor variables are on very different scales: consider
## rescaling

## Warning: Some predictor variables are on very different scales: consider
## rescaling
## boundary (singular) fit: see help('isSingular')
## Warning: Some predictor variables are on very different scales: consider
## rescaling
## boundary (singular) fit: see help('isSingular')
# Print the model summary
summary(mix.m7)
## Linear mixed model fit by maximum likelihood . t-tests use Satterthwaite's
##   method [lmerModLmerTest]
## Formula: dt ~ lp * ia * lang + (1 | subj) + (1 | gr)
##    Data: data
## 
##      AIC      BIC   logLik deviance df.resid 
## 178925.7 179006.8 -89451.8 178903.7    11779 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.4199 -0.8944 -0.1519  0.6543  4.8311 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subj     (Intercept)   4557    67.5   
##  gr       (Intercept)      0     0.0   
##  Residual             226556   476.0   
## Number of obs: 11790, groups:  subj, 30; gr, 4
## 
## Fixed effects:
##               Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)  1.512e+02  1.257e+02  2.239e+02   1.203 0.230209    
## lp           6.030e+00  3.563e+00  2.235e+02   1.693 0.091943 .  
## ia           6.252e+00  1.957e+00  1.177e+04   3.195 0.001404 ** 
## lang1       -1.917e+02  1.043e+02  1.179e+04  -1.837 0.066199 .  
## lp:ia       -1.103e-01  5.543e-02  1.177e+04  -1.989 0.046677 *  
## lp:lang1     6.426e+00  2.957e+00  1.179e+04   2.173 0.029804 *  
## ia:lang1     7.121e+00  1.997e+00  1.174e+04   3.566 0.000363 ***
## lp:ia:lang1 -1.958e-01  5.658e-02  1.173e+04  -3.461 0.000541 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) lp     ia     lang1  lp:ia  lp:ln1 i:lng1
## lp          -0.985                                          
## ia          -0.796  0.784                                   
## lang1        0.039 -0.038 -0.072                            
## lp:ia        0.785 -0.796 -0.985  0.068                     
## lp:lang1    -0.038  0.036  0.068 -0.985 -0.065              
## ia:lang1    -0.058  0.056  0.106 -0.967 -0.101  0.952       
## lp:ia:lang1  0.056 -0.053 -0.101  0.953  0.097 -0.967 -0.985
## fit warnings:
## Some predictor variables are on very different scales: consider rescaling
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
# Assuming 'sedf' is your data frame

# Rescale the predictor variables
sedf$lp <- scale(sedf$lp)
sedf$ia <- scale(sedf$ia)

# Transform the "lang" variable into a numerical format using dummy coding
sedf$lang_binary <- as.numeric(sedf$lang == "双语")

# Create a new variable 'lang_centered' with values -1 and 1
sedf$lang_centered <- ifelse(sedf$lang == "双语", 1, -1)

# Fit the mixed-effects model with the transformed "lang" variable
mix.m8 <- mixed(lmer(dt ~ lp * ia * lang_centered + 
                       (1 | subj) + 
                       (1 | gr), 
                     data = sedf),
                REML = FALSE,
                method = "LRT",
                data = sedf)
## boundary (singular) fit: see help('isSingular')
## Contrasts set to contr.sum for the following variables: subj, gr
## Formula (the first argument) converted to formula.
## Numerical variables NOT centered on 0: lang_centered
## If in interactions, interpretation of lower order (e.g., main) effects difficult.
## boundary (singular) fit: see help('isSingular')
## boundary (singular) fit: see help('isSingular')
## boundary (singular) fit: see help('isSingular')
## boundary (singular) fit: see help('isSingular')
## boundary (singular) fit: see help('isSingular')
## boundary (singular) fit: see help('isSingular')
## boundary (singular) fit: see help('isSingular')
## boundary (singular) fit: see help('isSingular')
summary(mix.m8)
## Linear mixed model fit by maximum likelihood . t-tests use Satterthwaite's
##   method [lmerModLmerTest]
## Formula: dt ~ lp * ia * lang_centered + (1 | subj) + (1 | gr)
##    Data: data
## 
##      AIC      BIC   logLik deviance df.resid 
## 178925.7 179006.8 -89451.8 178903.7    11779 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.4199 -0.8944 -0.1519  0.6543  4.8311 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subj     (Intercept)   4557    67.5   
##  gr       (Intercept)      0     0.0   
##  Residual             226556   476.0   
## Number of obs: 11790, groups:  subj, 30; gr, 4
## 
## Fixed effects:
##                      Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept)           485.583     13.085    29.961  37.109  < 2e-16 ***
## lp                      2.079     13.110    30.179   0.159 0.875079    
## ia                     31.879      4.393 11761.238   7.257 4.20e-13 ***
## lang_centered         -48.068      4.572 11482.318 -10.515  < 2e-16 ***
## lp:ia                  -8.829      4.438 11767.280  -1.989 0.046677 *  
## lp:lang_centered       22.352      4.615 11583.918   4.844 1.29e-06 ***
## ia:lang_centered       -4.217      4.502 11700.094  -0.937 0.349035    
## lp:ia:lang_centered    15.679      4.531 11734.233   3.461 0.000541 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) lp     ia     lng_cn lp:ia  lp:ln_ i:lng_
## lp          -0.002                                          
## ia           0.002 -0.004                                   
## lang_centrd -0.013  0.018 -0.030                            
## lp:ia       -0.004  0.010 -0.009  0.041                     
## lp:lng_cntr  0.018 -0.051  0.041 -0.009 -0.119              
## i:lng_cntrd -0.010  0.014 -0.025  0.065  0.034 -0.007       
## lp::lng_cnt  0.014 -0.041  0.034 -0.007 -0.097  0.079 -0.006
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
# Check for missing values in 'dt' and other predictor variables
any(is.na(sedf$dt))
## [1] FALSE
any(is.na(sedf$lp))
## [1] FALSE
any(is.na(sedf$ia))
## [1] FALSE
any(is.na(sedf$lang_centered))
## [1] FALSE
# Divide participants into high and low SE groups (using lp_mean as an example)
mean_se <- mean(sedf$lp)
high_se <- subset(sedf, lp > mean_se)
low_se <- subset(sedf, lp <= mean_se)


mix.hm0 <- mixed(lmer(dt ~ lp * ia * lang_centered + 
                       (1 | subj) + 
                       (1 | gr), 
                     data = high_se),
                REML = FALSE,
                method = "LRT",
                data = high_se)
## Contrasts set to contr.sum for the following variables: subj, gr
## Formula (the first argument) converted to formula.
## Numerical variables NOT centered on 0: lp, lang_centered
## If in interactions, interpretation of lower order (e.g., main) effects difficult.
summary(mix.hm0)
## Linear mixed model fit by maximum likelihood . t-tests use Satterthwaite's
##   method [lmerModLmerTest]
## Formula: dt ~ lp * ia * lang_centered + (1 | subj) + (1 | gr)
##    Data: data
## 
##      AIC      BIC   logLik deviance df.resid 
## 101729.7 101804.6 -50853.8 101707.7     6670 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.2150 -0.9706 -0.1410  0.6817  4.0775 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subj     (Intercept)   1411.3  37.57  
##  gr       (Intercept)    698.3  26.43  
##  Residual             238457.6 488.32  
## Number of obs: 6681, groups:  subj, 17; gr, 4
## 
## Fixed effects:
##                     Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)          514.099     24.727   10.793  20.791 4.72e-10 ***
## lp                   -21.394     24.625   16.006  -0.869 0.397795    
## ia                    27.842     10.853 6664.556   2.565 0.010329 *  
## lang_centered         -2.390     11.228 5933.136  -0.213 0.831412    
## lp:ia                  2.654     12.404 6664.837   0.214 0.830562    
## lp:lang_centered     -44.926     12.820 5618.657  -3.504 0.000461 ***
## ia:lang_centered      31.795     11.084 6398.928   2.868 0.004138 ** 
## lp:ia:lang_centered  -36.471     12.658 6252.772  -2.881 0.003974 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) lp     ia     lng_cn lp:ia  lp:ln_ i:lng_
## lp          -0.720                                          
## ia           0.000 -0.001                                   
## lang_centrd  0.003  0.012  0.031                            
## lp:ia       -0.001  0.002 -0.834 -0.012                     
## lp:lng_cntr  0.002 -0.025 -0.011 -0.832 -0.016              
## i:lng_cntrd  0.002  0.009  0.025  0.055 -0.010 -0.044       
## lp::lng_cnt  0.002 -0.020 -0.009 -0.044 -0.013  0.054 -0.833
mix.hm1 <- mixed(lmer(dt ~ lp * ia * lang_centered + 
                        (1 | subj) + 
                        (1 | gr), 
                      data = high_se),
                 REML = FALSE,
                 method = "LRT",
                 data = low_se)
## Contrasts set to contr.sum for the following variables: subj, gr
## Formula (the first argument) converted to formula.
## Numerical variables NOT centered on 0: lp, lang_centered
## If in interactions, interpretation of lower order (e.g., main) effects difficult.
## boundary (singular) fit: see help('isSingular')
## boundary (singular) fit: see help('isSingular')
## boundary (singular) fit: see help('isSingular')
## boundary (singular) fit: see help('isSingular')
## boundary (singular) fit: see help('isSingular')
## boundary (singular) fit: see help('isSingular')
## boundary (singular) fit: see help('isSingular')
## boundary (singular) fit: see help('isSingular')
summary(mix.hm1)
## Linear mixed model fit by maximum likelihood . t-tests use Satterthwaite's
##   method [lmerModLmerTest]
## Formula: dt ~ lp * ia * lang_centered + (1 | subj) + (1 | gr)
##    Data: data
## 
##      AIC      BIC   logLik deviance df.resid 
##  77061.8  77133.7 -38519.9  77039.8     5098 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.9240 -0.8083 -0.1876  0.6175  5.0022 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.
##  subj     (Intercept) 7.473e+03  86.4451
##  gr       (Intercept) 4.225e-05   0.0065
##  Residual             2.058e+05 453.5975
## Number of obs: 5109, groups:  subj, 13; gr, 4
## 
## Fixed effects:
##                      Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept)          440.3742    45.2384   13.0225   9.735 2.42e-07 ***
## lp                   -42.7150    39.6743   13.1237  -1.077    0.301    
## ia                     0.5582    11.6383 5096.5695   0.048    0.962    
## lang_centered         28.2369    12.1301 5086.1765   2.328    0.020 *  
## lp:ia                -44.8545    10.3759 5098.1570  -4.323 1.57e-05 ***
## lp:lang_centered     100.6451    10.7793 5104.4138   9.337  < 2e-16 ***
## ia:lang_centered      50.9720    11.9244 5105.6596   4.275 1.95e-05 ***
## lp:ia:lang_centered   73.1394    10.5437 5108.9755   6.937 4.51e-12 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) lp     ia     lng_cn lp:ia  lp:ln_ i:lng_
## lp           0.836                                          
## ia           0.004  0.008                                   
## lang_centrd -0.016 -0.027 -0.050                            
## lp:ia        0.008  0.016  0.835 -0.082                     
## lp:lng_cntr -0.027 -0.051 -0.082  0.835 -0.155              
## i:lng_cntrd -0.013 -0.022 -0.041  0.073 -0.067  0.069       
## lp::lng_cnt -0.022 -0.041 -0.067  0.070 -0.127  0.096  0.835
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')