The simplest way is to use nonlinear regression by least squares (function nls
). Mathematically, this is an iterative method, which looks for values for the parameters to reduce the residues below a limit value.
An example of use is the following:
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))
Results can be observed with the function summary
:
> 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
Not always the estimate gets so "good", but it depends on the data and the function, not the R.
The answer below has solved your problem?
– Sergio
To clarify: AP edited the initial question, which was about how to do the non-linear adjustment on R. @Diogo, it is not interesting for you to edit a question by changing its direction, especially if it has already been answered. If you have a new question (about programming, because only mathematics is not within the scope of the site), create a new post.
– Molx
ipsulum gets a divided by the sum of x but b
– user37612