PupillometryR
PupillometryR copied to clipboard
Error in regress_data when a trial is completely NA
If regress_data is used on a dataset in which a trial is completely NA an error is given:
Error in
mutate(): ℹ In argument:pupil1newkk = .predict_right(L_P, R_P). ℹ In group 1:Subject = "Subject_1",TrialN = 1,Event = "Circle". Caused by error inlm.fit(): ! 0 (non-NA) cases
I beleive this was already reported in #19 but i don't believe was solved.
Suggested Fix:
Modify the internal .predict_right function used within mutate to include a check for cases where both columns are entirely NA. If this condition is met, the function should return a vector of NA with the same length as the input.
.predict_right <- function(x, y) {
if (all(is.na(x)) & all(is.na(y))) {
return(rep(NA, length(x))) # Return a vector of NA if both columns are entirely NA
}
pupilz <- predict(lm(x ~ y, na.action = na.exclude))
return(pupilz)
}