I am trying to run a boxcox transformation with the following code:
urban1 <- subset(ski,urban <= 4,na.rm=TRUE)
ski$gender <- as.numeric((as.character(ski$gender)),na.rm=TRUE)
urban1 <- as.numeric((as.character(urban1)))
x <- (ski$gender*urban1)
y <- ski$EPSI.
bc <- boxcox(y ~ x)
(trans <- bc$x[which.max(bc$y)])
model3 <- lm(y ~ x)
model3new <- lm(y^trans ~ x)
ski$EPSI. <- ski$EPSI. + 1
But I keep getting this error:
Error in lm.fit(x,y,offset = offset, singular.ok = singular.ok, ...) : 0 (non-NA) cases Calls: ... eval -> eval -> boxcar -> boxcar.formula -> lm -> lm.fit Execution halted
Thanks in advance!
The error message
is generated by the
lm(y ~ x)
command when variablesx
ory
(or both) have only NAs.Here is an example:
In your code I suggest to test (just before your
lm
commands) if one of your variables has all NAs using:In my example:
The error can be triggered by NA's in your data or a bad transformation
Notice the
na.action=
argument. Setting this tona.exclude
will allow thelm
function to ignore NA's in your data. Another option isna.omit
which acts in a slightly different manner.The other problem may be a bad transformation of your data- double check your interaction terms and manipulations.