R:approx(sp$y, sp$x, xout = cutoff) :至少需要两个非 NA 值来进行插值

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

我使用onls模型包计算正交回归,使用confit(model)计算方程系数的置信区间,样本量为50。但是提示错误:

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

我查了下这个问题没有和之前的答案一样的x,请问是什么原因呢?或者我还能用什么来求解置信区间?

# 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)

有些点不正交,所以像问题中那样拟合 model1,检查正交性并仅使用正交点重新拟合 (model2)。

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

reprex package (v2.0.1)

创建于 2022-04-01