# Fitting Hill Functions

Here is a problem from Smith & Minton, Calculus: Early Transcendental Functions 3/e:

• What techniques are being used to estimate the parameters of the Hill function?

We're going to revisit the problem using least-squares modeling.

library(mosaic, quietly = TRUE)
trellis.par.set(theme = col.mosaic())

hemo = data.frame(air = c(1, 2, 3, 4, 5, 6, 7, 8, 9), hemoglobin = c(2,
13, 32, 52, 67, 77, 84, 88, 91))
plotPoints(hemoglobin ~ air, data = hemo)


## Fitting Hill Functions

We can try various Hill functions fitted to the data. Here's one with exponent $$n=2$$:

f2 = fitModel(hemoglobin ~ A * air^2/(theta^2 + air^2), data = hemo,
start = list(A = 100, theta = 4))
plotFun(f2(air) ~ air, air.lim = range(0, 12))
plotPoints(hemoglobin ~ air, data = hemo, add = TRUE)


### QUESTIONS

1. Note the starting values guessed for the parameters. Explain how these parameters are related to the shape of the function.
2. What features of this fitted function with $$n=2$$ are good, what features are bad? Are the fitted parameter functions reasonable?
3. Fit a Hill function with $$n=1$$. Is this better? How about $$n=3$$? How about $$n=5$$?
4. What criteria would you use in choosing the best $$n$$? Give a reasonable criterion in terms of how well the data points fall on the function. Also give a criterion expressed in terms of what you know physically about the possible values of $$A$$.

## Fitting the Exponent

Of course, $$n$$ itself is a parameter and we can include it among the parameters to be found.

fn = fitModel(hemoglobin ~ A * air^n/(theta^n + air^n), data = hemo,
start = list(A = 100, theta = 4, n = 3))
plotFun(fn(air) ~ air, air.lim = range(0, 12))
plotPoints(hemoglobin ~ air, data = hemo, add = TRUE)


## The Residuals

The residuals are the difference between the actual values of the output variable and the model function. You can calculate them by putting the data values for the input (air, in this case) into the model function.

resids = with(hemoglobin - fn(air), data = hemo)


One way to quantify the typical size of a residual is with the “root mean square”.

sqrt(mean(resids^2))

## [1] 0.1231


### QUESTIONS:

1. Calculate the root mean square for exponents $$n=1,2,3,5$$ and compare them to the RMS for the fitted value of $$n$$.

## Confidence Intervals Project

When fitting the function to the data, the parameters are reported by the computer to many digits. This suggests an estimate of high precision, but that's misleading.

Read the data from the graph and plot the data. Then use the data to fit a Hill function, using all three parameters $$A$$, $$n$$, and $$\theta$$.