How are these two power law fitting glm models different?

by ohnoplus   Last Updated March 19, 2019 20:19 PM

I have some data that I thought I'd try fitting with a power law (in R).

``````test2 <- structure(list(Depth = c(69, 73, 148, 365, 452, 965, 100, 100,
120, 120, 150, 159, 180), Value = c(155.29, 28.09, 23.98, 28.51,
44.22, 13.52, 19.8, 97.35, 69.1, 99.03, 26.4, 35.08, 37.39)), .Names = c("Depth",
"Value"), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-13L))
``````

I tried fitting two glm to this model. In the first model, I log transformed both the independent variable "Depth" and the dependent variable "Value", and tried to fit these with a linear function.

``````modA <- glm(log10(Value) ~ log10(Depth), data = test2, family = gaussian(link = "identity"))
``````

I also tried fitting the same data by not log transforming the independent variable, and instead fitting a log link function.

``````modB <- glm(Value ~ log10(Depth), family = gaussian(link = "log"), data = test2)
``````

When I examined values predicted by these functions, they seem to generate somewhat different predictions.

``````testPred <- tibble(
Depth = c(seq(from = 30, to = 150, by = 0.1),
seq(from = 101, to = 1000, by = 1)
)
)

testPred$$ModA <- 10^predict(modA, testPred) testPred$$ModB <- predict(modB, testPred, type = "response")

ggplot() + geom_point(data = test2, aes(x = Value, y = Depth), size = 2) + scale_y_reverse() +
geom_line(data = testPred, aes(x = ModA, y = Depth), colour = "blue") +
geom_line(data = testPred, aes(x = ModB, y = Depth), colour = "green")
`````` I don't understand why these approaches would generate different predicted values. Could somebody explain to me why these yield different results? Furthermore, which model, if either is the correct approach?

Tags :