I created power regression equations for length vs dry mass in both R and Excel but the coefficients do not match.
I used Hong Ooi's answer from this link: Power regression in R similar to excel. In that code, they were able to replicate the power equation from Excel using the R code. However, when I tried, I got some very weird coefficients. The Excel equation from the power trendline is much more accurate when tested with random lengths.
Code as follows:
#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
This should give me the equation "14.9515*x^0.3413" once I convert the intercept (EXP(2.7048) = 14.9515). I attempted to test it with some random lengths and the predictions are way off.
However, the equation given by Excel is "0.0009*x^2.6291" which, when tested, was very accurate. I would just use the equation from Excel but I need to make 50 more of these and would love to automate it using R.