Wersja jednowymiarowa
x<-seq(0,50,1)
y<-((runif(1,10,20)*x)/(runif(1,0,10)+x))+rnorm(51,0,1)
model<-nls(y~a*x/(b+x),start = list(a = 1,b = 3))
summary(model)
##
## Formula: y ~ a * x/(b + x)
##
## Parameters:
## Estimate Std. Error t value Pr(>|t|)
## a 14.4044 0.2562 56.232 < 2e-16 ***
## b 3.8106 0.3899 9.772 4.3e-13 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.8079 on 49 degrees of freedom
##
## Number of iterations to convergence: 5
## Achieved convergence tolerance: 3.92e-06
plot(x,y)
lines(x,predict(model),lty=2,col="red",lwd=3)
Wersja wielowymiarowa
n <- 1000
x1 <- runif(n, min = 0, max = 100)
x2 <- runif(n, min = 0, max = 100)
y<-5*x1/(45+x2)+rnorm(n, sd = 3)
model2<-nls(y~b1*x1/(b2+x2),start = list(b1 = 1,b2 = 2))
summary(model2)
##
## Formula: y ~ b1 * x1/(b2 + x2)
##
## Parameters:
## Estimate Std. Error t value Pr(>|t|)
## b1 4.1538 0.3729 11.138 < 2e-16 ***
## b2 36.2922 4.9543 7.325 4.91e-13 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.028 on 998 degrees of freedom
##
## Number of iterations to convergence: 7
## Achieved convergence tolerance: 2.111e-06