jwdink / eyetrackingR

This package is designed to make dealing with eye-tracking data easier. It addresses tasks along the pipeline from raw data to analysis and visualization.
http://eyetrackingr.com
Other
82 stars 20 forks source link

make_time_cluster_data not working with lmer: "statistic" undefined line 433 in time_sequence_data.R #61

Closed respatte closed 6 years ago

respatte commented 6 years ago

Hi,

I've tried running the following code but got the following error:

LT.time_cluster_aois <- make_time_cluster_data(LT.time_course_aois, 
                                               predictor_column = "Condition",
                                               aoi = "Tail",
                                               test = "lmer",
                                               threshold = 1.5,
                                               formula = ArcSin ~ TrialId*Condition +
                                                 (1 + TrialId | Participant) +
                                                 (1 | Stimulus))
## |==================================================|100% ~0 s remaining
## Error in pnorm(q = abs(statistic), lower.tail = FALSE) : 
##   object 'statistic' not found

This error seems to link to line 433 of time_sequence_data.R, where statistic appears out of nowhere, as far as I can tell (function analyze_time_bins.time_sequence_data). I would offer to try and fix that but I'm afraid I'm far from being good enough for that.

It's probably not related, but in case it is, I also had a few warnings:

warnings()
## Warning messages:
## 1: In bind_rows_(x, .id) : Unequal factor levels: coercing to character
## 2: In bind_rows_(x, .id) :
##   binding character and factor vector, coercing into character vector

and that second warning repeating up to the 50th printed warning.

brockf commented 6 years ago

statistic is actually returned by the_test() as part of the model object. I wonder if your model isn't running properly, thus not returning a statistic.

respatte commented 6 years ago

Hi Brock,

Thanks for the explanation, I tried running my model in the same way the_test() does, and it came up with an error (it's not really relevant but here it is:)

Error: number of observations (=543) <= number of random effects (=1008) for term
(1 + TrialId | Participant); the random-effects parameters and the residual variance
(or scale parameter) are probably unidentifiable

So I changed the specification of my random effects, and now make_time_cluster_data works fine!

I'm guessing from what I understand of the_test() that it should have returned the errors in that case, wouldn't it be good if the code then raised an error and printed the errors from the model?

Edit: reading further into the code for analyse_time_bins.time_sequence_data, I see that the code should indeed raise an error and show what errors came up while running the model. I'm not really sure why this isn't working though...

If you want to reproduce this and check why the errors weren't printed, you can find my project here. If you open stats/InfantsAnalysis.R, run the first two blocks (LIBRARY IMPORTS and GATHER DATA), then change line 93 to be (1 + TrialId | Participant) + and finally run lines 77-94. I hope this is helpful! :)

jwdink commented 6 years ago

Thank you for contributing! At some point in the near future I'd like to significantly refactor that function, so issues like this will (hopefully) get swept up then.