如何减少三次方程的最大峰值(拟合)

问题描述 投票:0回答:1

根据效率收集通风量数据。采集了几个样本并将其拟合为三次方程式。它用Excel编写,并获得了第三个回归方程。

Click to see picture

但是,从图片中可以看到,90-95%的通风量高于100%。数据不应高于100%,但是自动回归的最大顶点是凸的,因此它以曲线形式超过100%。

是否有减少最大顶点并使其合适的方法?照原样使用测量数据,但不要超过100%。

也欢迎使用R或其他统计程序。R值可能会低一些。

谢谢。

r excel curve-fitting vertex
1个回答
0
投票

R中有一些想法:

首先,我制作一些与您的数据类似的示例数据,并使用x ^ 3,x ^ 2和x作为预测变量拟合线性模型:

#  make example data
xx = rep(c(30, 50, 70, 100), each = 10)
yy = 1/(1+exp(-(xx-50)/15))  * 4798.20 + rnorm(length(xx), sd = 20)
xx = c(0, xx)
yy = c(0, yy)

# fit third-order linear model
m0 = lm(yy ~ I(xx^3) + I(xx^2) + xx)

x_to_predict = data.frame(xx = seq(0, 100, length.out = length(xx)))
lm_preds = predict(m0, newdata = x_to_predict)

想法1:您可以拟合使用S形曲线(单调)的模型。

# fit quasibinomial model for proportion
# first scale response variable between 0 and 1
m1 = glm(I(yy/max(yy)) ~ xx , family = quasibinomial())

# predict
preds_glm = predict(m1, 
                newdata = x_to_predict, 
                type = "response")

想法2:拟合将形成平滑曲线的广义加法模型。

# fit Generalized Additive Model
library(mgcv)
# you have to tune "k" somewhat -- larger means more "wiggliness"
m2 = gam(yy ~ s(xx, k = 4)) 
gam_preds = predict(m2, 
                    newdata = x_to_predict, 
        type = "response")

这是每个模型的图样:

# plot data and predictions
plot(xx, yy, ylab = "result", xlab = "efficiency")
lines(x_to_predict$xx, 
      preds_glm*max(yy), "l", col = 'red', lwd = 2)
lines(x_to_predict$xx, 
      gam_preds, "l", col = 'blue', lwd = 2)
lines(x_to_predict$xx, lm_preds, 
      "l", col = 'black', lwd = 2, lty = 2)
legend("bottomright", 
       lty = c(0, 1, 1, 2), 
       legend = c("data", "GLM prediction", "GAM prediction", "third-order lm"), 
       pch = c(1, NA_integer_, NA_integer_, NA_integer_), 
       col = c("black", "red", "blue", "black"))

plot of three different models

© www.soinside.com 2019 - 2024. All rights reserved.