Nonlinear Least Squares in S-plus and R

*Blog post
2004
Nonlinear regression
Author

Steve Simon

Published

June 28, 2004

I’ve worked on a brief explanation of how to fit an S-shaped curve using SPSS and someone wanted to know how to do this in R.

Here’s a simple example.

xc <- c(0.8,0.5,0.2,-0.2,-0.5,-0.8)
yn <- c(0.02,0.10,0.29,0.20,0.80,1.00)
nls.mod1 <- nls(yn~1/(1+exp(b*xc-a)),start=list(a=0,b=10))
summary(nls.mod1)

Formula: yn ~ 1/(1 + exp(b * xc - a))

Parameters:
  Estimate Std. Error t value Pr(>|t|)
a   -2.708      1.404  -1.929    0.126
b    7.917      3.717   2.130    0.100

Residual standard error: 0.1498 on 4 degrees of freedom

Number of iterations to convergence: 32 
Achieved convergence tolerance: 6.08e-06

Earlier versions are here and here.

Also see this related file.