. Advertisement .
..3..
. Advertisement .
..4..
For the problem “error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, …) : 0 (non-na) cases.” I tried to fix it, but It doesn’t work and returns the result I want. Here is my program:
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
and
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
has occurred. I’ve checked the entire command line but still can’t find the mistake.
The cause: Because variables
x
ory
or bothx
andy
have only NAs, thelm(y x)
command appears as an error.Solution:
Before your
lm
commands, for example:I recommend testing if one of the variables contains all NAs:
For instance:
This error can be caused by NA in your data , or bad transformation.
Pay attention to the
na.action=
argument. This will enable thelm
function not to consider NA’s in your data by setting it tona.exclude
.na.omit
is another option that acts in a slightly different way.Another problem could be a bad data transformation. Double-check your interactions terms and manipulations.