• Register
0 votes
2.1k 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.

6 5 3
7,540 points

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
9 7 4
38,600 points

Related questions

0 votes
1 answer 935 views
935 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 1.3K views
1.3K 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 114 views
114 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
1 answer 145 views
145 views
Problem: I have only the fundamental knowledge related to R. I want to simulate the very basic moving average process in R which is as shown below for your reference: x_t = Z_(t-1)-0.4Z_(t-2)+Z_t. Please find below my code in R: z = rnorm(500, 0, 1) x ... was unable to find the exact solution for my above error. I am looking for some help from R expert if possible to fix my above R related error.
asked Aug 12 Raphael Pacheco 4.9k points