log-log plot and power function fitting

192 Views Asked by At

I try to fit a power function using a lm on log-log plot data mentioned here https://statisticsbyjim.com/regression/log-log-plots/ using a mammal dataset . I used the following code according the description but fail reproduce the results.

mammals <- read.csv("mammals.csv", header=TRUE, stringsAsFactors = FALSE)
plot(log10(mammals$AdultBodyMass_g), log10(mammals$BasalMetRate_mLO2hr)) # log-log plot
lmMammals <- lm(log10(BasalMetRate_mLO2hr) ~ log10(AdultBodyMass_g), data=mammals)
summary(lmMammals)
# Metabolic Rate = 0.5758 Mass ^ 0.7063
mammals$MetRate_predict <- 0.57584 * (mammals$AdultBodyMass_g ^ 0.70630)

mammals[1:5, c("BasalMetRate_mLO2hr", "MetRate_predict")]

I do not get why my predicted values are very different from the measured values. What am I doing wrong?

1

There are 1 best solutions below

0
On

There is an error in the blog the correct answer is:

Metabolic Rate = 10^0.5758 * Mass ^ 0.7063 mammals$MetRate_predict <- 10^0.57584 * (mammals$AdultBodyMass_g ^ 0.70630)