• Register
0 votes
1.1k 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(x, y, offset = offset, singular.ok = singular.ok, ...) : 
NA/NaN/Inf in foreign function call (arg 1)
 

I have also checked the mailing list and I found that the error is because of the NA values present in col2  I also tried using na.action=na.exclude/omit/pass but none of them seem to work. I have tested lm again on the first 10 entries, definitely not 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 ?

6 5 3
6,930 points

1 Answer

0 votes

Solution :

I had encountered the same error when my equivalent of col2 was an integer64 rather than an integer and while using natural and polynomial splines, splines::bs and splines:ns example as follows:

m.fit <- lm(col1 ~ ns(col2))
m.fit <- lm(col1 ~ bs(col2, degree = 3))

Converting it to a standard integer really worked for me:

m.fit <- lm(col1 ~ ns(as.integer(col2)))
m.fit <- lm(col1 ~ bs(as.integer(col2), degree = 3))
9 7 4
38,600 points

Related questions

0 votes
1 answer 2.5K views
2.5K 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) ... -> boxcar -> boxcar.formula -> lm -> lm.fit Execution halted Please let me know if anyone knows the solution for this error message.
asked Nov 27, 2019 alecxe 7.5k points
1 vote
1 answer 1.6K views
1.6K 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 151 views
151 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
1 vote
1 answer 499 views
499 views
Problem : Currently I am learning r. I have the data table "normal" which has the numeric as far as I know normalized values. If I try to execute the below command k <- kmeans(normal,center=3) Then I always face the below error: &ldquo;Error in do_one(nmeth) : NA/NaN/ ... call (arg 1)&rdquo; I am trying to fix it by researching on it but still unable to fix it. Can somebody help me in fixing it?
asked Mar 28 morrisBson 3.2k points
0 votes
1 answer 952 views
952 views
Problem : I am learning to work with neural networks in R. As a learning tutorial I am using the following problem over at Kaggle: https://www.kaggle.com/c/titanic This problem is specifically designed for people who want to learn and please note there is no reward ... Error in neurons[[i]] %*% weights[[i]] : requires numeric/complex matrix/vector arguments Can anyone help in resolving my issue?
asked Nov 27, 2019 alecxe 7.5k points