# [R] How to compare the fitting of function?

Luigi Marongiu m@rong|u@|u|g| @end|ng |rom gm@||@com
Tue Jul 7 08:57:28 CEST 2020

```Hello,
I have fitted two curves to the data. How can I tell which one is more
fitted? By eye (see plot underneath) I would say that the function
Gompertz is better than the function Holling type III; how can I give
a number to this hunch?
This is an example:
```
# functions
holling = function(a, b, x) {
y = (a * x^2) / (b^2 + x^2)
return(y)
}
gompertz = function(a, b, c, x) {
y = a * exp(-b * exp(-c * x))
return(y)
}
# data
actual <- c(8,  24,  39,  63,  89, 115, 153)
holling <- c(4.478803,  17.404533,  37.384128,  62.492663,  90.683630,
120.118174, 149.347683)
gompertz <- c(11.30771,  22.39017,  38.99516,  61.19318,  88.23403,
118.77225, 151.19849)
# plot
plot(1:length(actual), actual, lty = 1 , type = "l", lwd = 2,
xlab = "Index", ylab = "Values")
points(1:length(actual), holling, lty = 2, type = "l", col = "red")
points(1:length(actual), gompertz, lty = 3, type = "l", col = "blue")
legend("bottomright",
legend = c("Actual values", "Holling III", "Gompertz"),
lty = c(1, 2, 3), lwd = c(2, 1,1), col = c("black", "red", "blue"))
```
Thank you

```