【发布时间】:2019-08-19 15:21:10
【问题描述】:
我在 R 和 Excel 中创建了长度与干质量的幂回归方程,但系数不匹配。
我通过这个链接使用了 Hong Ooi 的answer:Power regression in R similar to excel。在该代码中,他们能够使用 R 代码从 Excel 复制幂方程。但是,当我尝试时,我得到了一些非常奇怪的系数。使用随机长度进行测试时,幂趋势线的 Excel 方程要准确得多。
代码如下:
#sample dataset of Lengths and Dry Masses
test <- structure(list(
Length = c(23, 17, 16, 25, 15, 25, 11, 22, 13, 21, 31),
DryMass = c(3.009, 1.6, 1, 4.177, 0.992, 6.166, 0.7, 1.73, 0.613, 3.429, 7.896)),
.Names = c("Length", "DryMass"),
row.names = c(NA, 11L),
class = "data.frame")
#log-log regression
lm(formula = log(Length) ~ log(DryMass), data = test)
Coefficients:
(Intercept) log(DryMass)
2.7048 0.3413
一旦我转换截距 (EXP(2.7048) = 14.9515),这应该给我等式“14.9515*x^0.3413”。我试图用一些随机长度对其进行测试,但预测结果很差。
However, the equation given by Excel is "0.0009*x^2.6291" which, when tested, was very accurate. 我只会使用 Excel 中的公式,但我需要再做 50 个这样的公式,并且希望使用 R 来自动化它。
【问题讨论】:
标签: r excel regression