Question on "Error in hasTsp(x) : argument "x" is missing, with no default" when using nls

Viewed 128

I'm learning to do nonlinear square fit with R, and I followed this tutorial:

p = function(x) x^3+2*x^2+5
x = seq(-0.99, 1, by = .01)
y = p(x) + runif(200)
df = data.frame(x = x, y = y)
head(df)
      x        y
1 -0.99 6.183018
2 -0.98 6.611669
3 -0.97 6.762615
4 -0.96 6.594278
5 -0.95 5.990637
6 -0.94 6.048369

# Then the author conducted a nonlinear regression fit.
fit = nls(y~a*x^2+b*x, data = df, start(a=0, b=0))

But when I try to run the code, it always says "Error in hasTsp(x) : argument "x" is missing, with no default"

Does anyone know where the problem is?

Thank you so much!

1 Answers

We need the start as a list argument

nls(y~a*x^2+b*x, data = df, start = list(a=0, b=0))

-output

Nonlinear regression model
  model: y ~ a * x^2 + b * x
   data: df
      a       b 
11.1241  0.5711 
 residual sum-of-squares: 2713

Number of iterations to convergence: 1 
Achieved convergence tolerance: 3.246e-10
Related