Error in lm.fit(x,y,offset = offset, singular.ok,…) 0 non-NA cases with boxcox formula

The error message

lm.fit(x,y,offset = offset, singular.ok = singular.ok, …) : 0 (non-NA) cases

is generated by the lm(y ~ x) command when variables x or y (or both) have only NAs.
Here is an example:

n <- 10
x <- rnorm(n,1)
y <- rep(NA,n)
lm(y ~ x)

Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 
  0 (non-NA) cases

In your code I suggest to test (just before your lm commands) if one of your variables has all NAs using:

all(is.na(x))
all(is.na(y))
all(is.na(y^trans))

In my example:

all(is.na(y))
[1] TRUE

Leave a Comment