I'm trying to fit parabola to my data in R. I already created the fit in MATLAB (so I know the parameter values), but when I run this code:
library("nls2")
fo <- y ~ A * (x ^ 2) + B * x + C
sA <- seq(-.000001,0,len=10)
sB <- seq(0,.001,len=10)
sC <- seq(1,20,len=10)
st1 <- expand.grid(A=sA,B=sB,C=sC)
mod1 <- nls2(fo,start=st1,algorithm="brute-force")
z <- nls(fo,start=coef(mod1))
x <- c(50072,50072,52536,52536,53768,53768,53768,54384,54384,54384, 54384,54692,54692,54846,54846,54846,54846,54846,54923,54923, 54923,54923,54923,54923,54961.5,54961.5,54961.5,54961.5,54961.5,54961.5,55000,55000,55000)
y <- c(0.46007,0.47185,0.24377,0.28506,0.16560,0.13587,0.16844, 0.08156,0.06917,0.09357,0.08704,0.02968,0.03293,0.01233,0.01509, 0.01095,0.005,0.00704,0.00861,0.00287,0.00456,0.01043,0.00373,0.00594, 0.00628,0.00089,0.00085,0.00055,0.00142,0.0022,-0.00091,-0.00209,-0.00293)
I get the following: z
A B C
-7.728222e-09 7.177715e-04 -1.610196e+01
> z
Nonlinear regression model
model: y ~ A * (x^2) + B * x + C
data: parent.frame()
A B C
-7.728e-09 7.178e-04 -1.610e+01
residual sum-of-squares: 0.0106
Number of iterations to convergence: 1
Achieved convergence tolerance: 4.457e-07
But confint(z)
gives me the following error message:
Waiting for profiling to be done...
Error in approx(sp$y, sp$x, xout = cutoff) :
need at least two non-NA values to interpolate
What went wrong ? Thanks !