set.seed(42) library("lme4") library("eyetrackingR") data("word_recognition") data <- make_eyetrackingr_data(word_recognition, participant_column = "ParticipantName", trial_column = "Trial", time_column = "TimeFromTrialOnset", trackloss_column = "TrackLoss", aoi_columns = c('Animate','Inanimate'), treat_non_aoi_looks_as_missing = TRUE) # subset to response window post word-onset response_window <- subset_by_window(data, window_start_time = 15500, window_end_time = 21000, rezero = FALSE) # remove trials with > 25% of trackloss response_window_clean <- clean_by_trackloss(data = response_window, trial_prop_thresh = .25) # pick threshold t based on alpha = .05 two tailed num_sub = length(unique((response_window_clean$ParticipantName))) threshold_t = qt(p = 1 - .05/2, df = num_sub-1) # create Target condition column response_window_clean$Target <- as.factor( ifelse(test = grepl('(Spoon|Bottle)', response_window_clean$Trial), yes = 'Inanimate', no = 'Animate')) # create time sequence data (within-subject) response_time <- make_time_sequence_data(response_window_clean, time_bin_size = 100, predictor_columns = c("Target"), aois = "Animate", summarize_by = "ParticipantName") # look for initial clusters using lmer (within-subject) df_timeclust <- make_time_cluster_data(response_time, test= "lmer", predictor_column = "Target", treatment_level = "Inanimate", threshold = threshold_t, formula = Prop ~ Target + (1 | ParticipantName)) # run permutations (within-subject) clust_analysis <- analyze_time_clusters(df_timeclust, formula = Prop ~ Target + (1 | ParticipantName), within_subj = T, samples = 100) # create time sequence data (between-subject) response_time_between <- make_time_sequence_data(response_window_clean, time_bin_size = 100, predictor_columns = c("Sex", "Trial"), aois = "Animate", summarize_by = "ParticipantName" ) # look for initial clusters using lmer (between-subject) df_timeclust_between <- make_time_cluster_data(response_time_between, test= "lmer", predictor_column = "Sex", treatment_level = "M", threshold = threshold_t, formula = Prop ~ Sex + (1 | Trial)) # using (1 | ParticipantName) doesn't work: # 'number of levels of each grouping factor must be < number of observations' # run permutations (between-subject) with within_subj set to T and F clust_analysis_between.wsT <- analyze_time_clusters(df_timeclust_between, formula = Prop ~ Sex + (1 | Trial), within_subj = T, samples=100) (summary(clust_analysis_between.wsT)) ## Test Type: lmer ## Predictor: Sex ## Formula: Prop ~ Sex + (1 | Trial) ## Null Distribution ====== ## Mean: -4.4887 ## 2.5%: -4.4887 ## 97.5%: -4.4887 ## Summary of Clusters ====== ## Cluster Direction SumStatistic StartTime EndTime Probability ## 1 1 Negative -4.488748 15500 15700 1 clust_analysis_between.wsF <- analyze_time_clusters(df_timeclust_between, formula = Prop ~ Sex + (1 | Trial), within_subj = F, samples=100) ## Error in analyze_time_bins.time_sequence_data: ## The term 'Sex' was not found in your model. ## This can happen if your predictor is treatment-coded, in which case you should specify the `treatment_level` argument. ## For example, if 'Target' is treatment coded, then it becomes 'TargetInanimate'in the model, and you should set `treatment_level = 'Inanimate'`. ## The terms in the model were: '(Intercept)', 'SexM' # look for initial clusters using lmer (between-subject) df_timeclust_between_lm <- make_time_cluster_data(response_time_between, test= "lm", predictor_column = "Sex", treatment_level = "M", threshold = threshold_t, formula = Prop ~ Sex) # run permutations (between-subject) with within_subj set to T and F clust_analysis_between_lm.wsT <- analyze_time_clusters(df_timeclust_between_lm, formula = Prop ~ Sex, within_subj = T, samples=100) (summary(clust_analysis_between.wsT)) clust_analysis_between_lm.wsF <- analyze_time_clusters(df_timeclust_between_lm, formula = Prop ~ Sex, within_subj = F, samples=100)