• Register
0 votes

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

Please log in or register to answer this question.

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:


In my example:

[1] TRUE
9 7 4
38,600 points

Related questions

0 votes
1 answer 1.2K 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.8K 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 180 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 68 views
0 votes
1 answer 467 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, 2020 Raphael Pacheco 4.9k points
0 votes
2 answers 401 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, 2020 mphil 2.3k points
0 votes
2 answers 2.3K 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
0 votes
2 answers 143 views
Problem : I am stuck because of following weired error error in sort.list(y) : 'x' must be atomic for 'sort.list' have you called 'sort' on a list?
asked Nov 15, 2019 peterlaw 6.9k points
1 vote
1 answer 160 views
Problem: I have very fundamental knowledge of logistic regression. I am trying to write code on logistic regression. I have done a lot of research on this issue but because of my limited knowledge I am still unable to fix the below error. Error ... (data) stock.direction <- data$Direction training_model=glm(stock.direction~data$lag2,data=data,family=binomial) Please help me in fixing above error.
asked May 26, 2020 Martin K 6.6k points
0 votes
1 answer 659 views