【问题标题】:How can i fit a power curve from a non-linear regression? [duplicate]如何从非线性回归拟合功率曲线? [复制]
【发布时间】:2019-01-14 12:51:37
【问题描述】:

我正在尝试拟合非线性回归后的曲线。

这是我的数据集:

stem_diameter <- c(15, 15, 16, 17, 19, 23, 23, 24, 24, 25, 25, 26, 27, 28, 29, 30, 30, 32, 32, 33, 34, 34, 35, 36, 36, 37, 38, 40, 41, 41, 42, 42, 46, 48, 48, 49, 51, 54, 55, 60)

total_biomass <- c(0.25, 0.65, 0.40, 0.40, 0.65, 0.60, 0.20, 0.60, 0.50, 0.35, 0.70, 0.65, 0.95, 0.60, 0.80, 0.90, 0.70, 1.15, 1.00, 1.70, 1.95, 1.15, 1.70, 1.25, 1.95, 1.20,
2.70, 2.00, 3.70, 2.35, 1.50, 2.50, 5.05, 4.10, 2.85, 2.15, 3.50, 4.80, 5.30, 2.95)

stem_data.df <- data.frame(stem_diameter, total_biomass)

我尝试过如下拟合线性模型:

model1 <- lm(total_biomass ~ stem_diameter, data = stem_data.df)
summary(model1)
plot(total_biomass ~ stem_diameter)
lines(stem_diameter, predict(model1))

但是我认为非线性模型更适合数据。

然后我继续这样做:

m <- nls(total_biomass ~ a(stem_diameter^b), stem_data.df, start = list(a = -1.8, b = 0.1)) # power formula: y = a*x^b
summary(m)
plot(total_biomass ~ stem_diameter)
lines(stem_diameter, fitted(m), col = "green")

使用 a 和 b 来自上述线性模型的系数,正如我在别处所读到的。然而,曲线上拟合的曲线看起来并不应该是这样,这让我认为公式本身存在问题。数据本身似乎很好,因为我已经能够在 Excel 散点图中绘制一条曲线,该曲线的 R2 值为 0.79,公式为 y = 0.0009x^2.0598。更改 a 和 b 的值对曲线也没有实际影响,因此我不确定问题可能是什么。

谁能解释可能是什么问题?

提前致谢

【问题讨论】:

    标签: r curve-fitting curve nls


    【解决方案1】:

    我建议你研究一下这篇文章:https://stats.stackexchange.com/a/255265/11849

    不管怎样,

    fit1 <- lm(log(total_biomass) ~ log(stem_diameter), data = stem_data.df)
    
    #you were missing a `*` and had bad starting values
    m <- nls(total_biomass ~ a*(stem_diameter^b), stem_data.df, 
             start = list(a = exp(coef(fit1)[1]), b = coef(fit1)[2])) # power formula: y = a*x^b
    summary(m)
    plot(total_biomass ~ stem_diameter)
    curve(predict(m, newdata = data.frame(stem_diameter = x)), add = TRUE)
    

    【讨论】:

    • 我很久以前就基本放弃搜索重复了。随意关闭。
    猜你喜欢
    • 1970-01-01
    • 2016-11-13
    • 2020-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-17
    • 2019-03-15
    • 2021-05-08
    相关资源
    最近更新 更多