'R:approx(sp$y, sp$x, xout = cutoff) : need at least two non-NA values to interpolate

I use the onls model package to calculate the orthogonal regression, use confit(model) to calculate the confidence interval of the equation coefficients, the sample size is 50. But it prompts an error:

Error in approx(sp$y, sp$x, xout = cutoff): need at least two non-NA
values to interpolate.

I checked and there is no same x as the previous answer to this question, so what could be the reason? Or what else can I use to solve the confidence interval?

# Data
x<-c(52.37,52.91,53.15,55.18,55.25,56.95,57.17,57.86,60.93,63.55,65.25,65.73,68.39,70.39,70.65,72.19,73.33,75.98,76.88,79.58,79.83,80.57,82.68,83.75,87.48,98.35,101.86,103.69,104.42,104.69,106.84,107.01,108.61,109.97,111.32,112.89,113.81,115.97,119.46,120.24,120.40,145.92,145.90,153.39,167.93,171.33,172.33,195.90,209.02,226.68,244.34,291.43,328.42,360.37,457.47,576.96,749.65)
y<-c(218500,238600,395300,144900,526900,305100,229000,291600,327800,149200,239200,1500600,150400,222500,470800,347600,356400,375400,325100,151400,395800,367900,597000,391500,479700,349900,445200,521400,505400,573700,529700,317400,379700,829500,514900,706500,877400,500800,633800,529900,738800,917300,853700,734200,587700,991900,1324300,767200,1254300,902900,966300,2615300,1183600,1842500,2455700,4384800,5117400)

# Code
DAT <- data.frame(x, y)
model1 <-onls(y ~ a * x ^ b, data = DAT, start = list(a = 1,b = 1))
confint(model1, level = 0.95)


Solution 1:[1]

Some points are not orthogonal, so fit model1 like in the question, check orthogonality and refit (model2) with the orthogonal points only.

library(onls)
#> Loading required package: minpack.lm

# Data
x<-c(52.37,52.91,53.15,55.18,55.25,56.95,57.17,57.86,60.93,63.55,65.25,65.73,68.39,70.39,70.65,72.19,73.33,75.98,76.88,79.58,79.83,80.57,82.68,83.75,87.48,98.35,101.86,103.69,104.42,104.69,106.84,107.01,108.61,109.97,111.32,112.89,113.81,115.97,119.46,120.24,120.40,145.92,145.90,153.39,167.93,171.33,172.33,195.90,209.02,226.68,244.34,291.43,328.42,360.37,457.47,576.96,749.65)
y<-c(218500,238600,395300,144900,526900,305100,229000,291600,327800,149200,239200,1500600,150400,222500,470800,347600,356400,375400,325100,151400,395800,367900,597000,391500,479700,349900,445200,521400,505400,573700,529700,317400,379700,829500,514900,706500,877400,500800,633800,529900,738800,917300,853700,734200,587700,991900,1324300,767200,1254300,902900,966300,2615300,1183600,1842500,2455700,4384800,5117400)

# Code
DAT <- data.frame(x, y)

# 1st fit: with the full data set DAT
model1 <- onls(y ~ a * x ^ b, data = DAT, start = list(a = 1,b = 1))
#> Obtaining starting parameters from ordinary NLS...
#>   Passed...
#>  Relative error in the sum of squares is at most `ftol'. 
#> Optimizing orthogonal NLS...
#>   Passed... Relative error in the sum of squares is at most `ftol'.
o <- check_o(model1)$Ortho

# 2nd fit: with the orthogonal points only
model2 <- onls(y ~ a * x ^ b, data = DAT[o,], start = list(a = 1,b = 1))
#> Obtaining starting parameters from ordinary NLS...
#>   Passed...
#>  Relative error in the sum of squares is at most `ftol'. 
#> Optimizing orthogonal NLS...
#>   Passed... Relative error in the sum of squares is at most `ftol'.
confint(model2, level = 0.95)
#> Waiting for profiling to be done...
#>          2.5%       97.5%
#> a 2378.957049 4012.371390
#> b    1.079456    1.180696

Created on 2022-04-01 by the reprex package (v2.0.1)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rui Barradas