The simplest way is to use a least-squares non-linear regression ( nls
function). Mathematically, this is an iterative method, which looks for values for the parameters to reduce the residuals below a limit value.
An example usage is as follows:
set.seed(0)
x <- rnorm(100)
y <- jitter(1234/(x + 1), 0.1)
dat <- data.frame(x = x, y = y)
nl <- nls(y ~ a/(x + b), data = dat, start = c(a = 1000, b = 2))
The results can be observed with the summary
function:
> summary(nl)
# Formula: y ~ a/(x + b)
#
# Parameters:
# Estimate Std. Error t value Pr(>|t|)
# a 1132.5404 548.9356 2.063 0.0417 *
# b 1.9850 0.2013 9.863 2.4e-16 ***
# ---
# Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#
# Residual standard error: 4639 on 98 degrees of freedom
#
# Number of iterations to convergence: 13
# Achieved convergence tolerance: 9.861e-06
The estimate is not always "good", but it depends on the data and the function, not on the R.