Error in fitting Natural Spline in R

879 views Asked by At

I'm fitting a natural spline model and I get the errors below. Can you help me understand and solve the error below?

Error in double(nx * ncoef) : vector size cannot be NA

In addition: Warning message: In nx * ncoef : NAs produced by integer overflow

Unfortunately, I cannot upload the dataset and unfortunately, you could not replicate my code. Instead, I'll try to explain my code as much as I can:

Below is the code that I run to fit a natural spline fit:

fit.temp <- lm(y ~ ns(x,knots = seq(1, nrow(data), by = 10)),data = data)

In my dataset, x is a sequence from 1 to the number of rows in data which is 424742.

I know this question is somewhat a vague question, but after spending a lot of energy, I didn't have any luck figuring out what this error is and how to solve it.

Thanks very much,

1

There are 1 answers

1
flodel On BEST ANSWER

Somewhere within the code, it is trying to multiply two integers but the result is greater than the maximum integer that can be stored on your machine (.Machine$integer.max).

Without delving too much into the code, your inputs must be too big for this tool. Either work with a smaller data, or fewer knots by increasing the by argument to seq. Roughly, (nrow(data)^2 / .Machine$integer.max should give you a lower bound on how big by should be.