• Register
search
Log In
0 votes
1.2k views

Problem :

While I am trying to run the 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)))

a <- (ski$gender*urban1)

b <- ski$EPSI.

bc <- boxcox(b ~ a)

(trans <- bc$a[which.max(bc$b)])

model3 <- lm(b ~ a)

model3new <- lm(b^trans ~ a)

ski$EPSI. <- ski$EPSI. + 1

But I am facing following error message:

Error in lm.fit(a,b,offset = offset, singular.ok = singular.ok, ...) : 0 (non-NA) cases Calls: ... eval -> eval -> boxcar -> boxcar.formula -> lm -> lm.fit Execution halted

Please let me know if anyone knows the solution for this error message.

7.5k points
edited by

1 Answer

0 votes

Solution :

The following error message:

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

is usually generated by the lm(b ~ a) command when the variables a or b (or if both) have only NA values.
Following is an example:

n <- 20
a <- rnorm(n,1)
b <- rep(NA,n)
lm(b ~ a)
Error in lm.fit(a, b, offset = offset, singular.ok = singular.ok, ...) : 
  0 (non-NA) cases

In your code I suggest you to test just before your lm commands if one of your variables has all NA values using commands:

all(is.na(a))
all(is.na(b))
all(is.na(b^trans))

In my example:

all(is.na(b))
[1] TRUE
36.1k points
edited by

Related questions

0 votes
1 answer 574 views
574 views
Problem : Suppose I have data.frame a And I am using following code m.fit <- lm(col2 ~ col3 * col4, na.action = na.exclude) Here the col2 has some NA values And col3,col4 have values less than 1. I am getting following error: Error in lm.fit ... because of the NAs. Problem with this warning is interpreted by every google results is pointing towards the NA values. Have I misinterpreted the error ?
asked Nov 22, 2019 peterlaw 6.9k points
1 vote
1 answer 807 views
807 views
Problem : I want to perform a logistic regression but I am facing following error I am unable to find my mistake. summary(glm(prefmerkel~angst+crisismerkel+leadership+trustworthiness+ideology+pid+agegroups+gender+region,data=gles)) Error in glm.fit(x = c(1, 1, 1, 1, 1, 1, 1, ... In Ops.factor(eta, offset) : -' nicht sinnvoll für Faktoren 3: In Ops.factor(y, mu) : -' nicht sinnvoll für Faktoren
asked Nov 24, 2019 alecxe 7.5k points
0 votes
1 answer 59 views
59 views
Problem : I have done a lot of research on this extensively without finding any solution on it. I have tried cleaning my data set as follows: library("myraster") impute.mean <- function(l) replace(l, is.na(l) | is.nan(l) | is.infinite(l) , mean(l, na.rm = TRUE)) losses <- ... TRUE, na.rm=TRUE, nan.rm=TRUE) All my research says it should be NA's or Inf's or NaN's in the data but I don't have any
asked Dec 5, 2019 alecxe 7.5k points
0 votes
2 answers 64 views
64 views
Problem : I am trying to do data manipulation using R. I am trying to import the file which is having headings and also numbers in the multiple columns. I am trying to divide my values in the one column by the other column and then trying to determine the highest values. But ... below error &ldquo;Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) : 'x' must be atomic&rdquo;.
asked Feb 17 mphil 2.3k points
0 votes
2 answers 834 views
834 views
Problem : Below is my code which is giving me the error. plot(x,y) yx.lm <- lm(y ~ x) lines(x, predict(yx.lm), col="red") Why am I facing following error? Error in plot.xy(xy.coords(x, y), type = type, ...) : plot.new has not been called yet
asked Dec 4, 2019 alecxe 7.5k points